Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# monitors.cpp

    00001 /*
    00002     PyEO
    00003
    00004     Copyright (C) 2003 Maarten Keijzer
    00005
    00006     This program is free software; you can redistribute it and/or modify
    00007     it under the terms of the GNU General Public License as published by
    00008     the Free Software Foundation; either version 2 of the License, or
    00009     (at your option) any later version.
    00010
    00011     This program is distributed in the hope that it will be useful,
    00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014     GNU General Public License for more details.
    00015
    00016     You should have received a copy of the GNU General Public License
    00017     along with this program; if not, write to the Free Software
    00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00019 */
    00020
    00021 #include <utils/eoParam.h>
    00022 #include <utils/eoMonitor.h>
    00023 #include "PyEO.h"
    00024
    00025 using namespace boost::python;
    00026
    00027 class MonitorWrapper : public eoMonitor
    00028 {
    00029     public:
    00030         PyObject* self;
    00031         list objects;
    00032
    00033         MonitorWrapper(PyObject* p) :self(p) {}
    00034
    00035         eoMonitor& operator()()
    00036         {
    00037             call_method<void>(self, "__call__");
    00038             return *this;
    00039         }
    00040
    00041         std::string getString(int i)
    00042         {
    00043             if (static_cast<unsigned>(i) >= vec.size())
    00044             {
    00045                 throw index_error("Index out of bounds");
    00046             }
    00047
    00048             return vec[i]->getValue();
    00049         }
    00050
    00051         unsigned size() { return vec.size(); }
    00052 };
    00053
    00054 void monitors()
    00055 {
    00063     class_<eoMonitor, MonitorWrapper, boost::noncopyable>("eoMonitor", init<>())
    00064         .def("lastCall", &eoMonitor::lastCall)
    00065         .def("add", &eoMonitor::add)
    00066         .def("__call__", &MonitorWrapper::operator(), return_internal_reference<1>() )
    00067         .def("__getitem__", &MonitorWrapper::getString,
    00068                 "Returns the string value of the indexed Parameter")
    00069         .def("__len__", &MonitorWrapper::size)
    00070         ;
    00071 }
    00072