![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <WNS/Python.hpp> 00029 #include <WNS/pyconfig/Object.hpp> 00030 #include <sstream> 00031 #include <stddef.h> 00032 00033 using namespace wns::pyconfig; 00034 00035 Object::Object() : 00036 obj_(NULL) 00037 { 00038 } 00039 00040 Object::Object(PyObject* obj) : 00041 obj_(obj) 00042 { 00043 } 00044 00045 std::string 00046 Object::toString() const 00047 { 00048 PyObject* s = PyObject_Str(obj_); 00049 std::string result(PyString_AS_STRING(s)); 00050 // Don't care if null 00051 Py_XDECREF(s); 00052 return result; 00053 } 00054 00055 void 00056 Object::decref() const 00057 { 00058 Py_DECREF(obj_); 00059 } 00060 00061 void 00062 Object::incref() const 00063 { 00064 Py_INCREF(obj_); 00065 } 00066 00067 bool 00068 Object::isNone() const 00069 { 00070 return obj_ == Py_None; 00071 } 00072 00073 bool 00074 Object::isNull() const 00075 { 00076 return obj_ == NULL; 00077 } 00078 00079 bool 00080 Object::isConvertibleToString() const 00081 { 00082 PyObject* s = PyObject_Str(obj_); 00083 bool result = s != NULL; 00084 // Don't care if null 00085 Py_XDECREF(s); 00086 return result; 00087 } 00088 00089 Object 00090 Object::getItem(int n) const 00091 { 00092 return Object(PySequence_GetItem(obj_, n)); 00093 } 00094 00095 bool 00096 Object::isSequence() const 00097 { 00098 return PySequence_Check(obj_) == 1; 00099 } 00100 00101 int 00102 Object::isTrue() const 00103 { 00104 return PyObject_IsTrue(obj_); 00105 } 00106 00107 bool 00108 Object::operator==(const Object& other) 00109 { 00110 return obj_ == other.obj_; 00111 } 00112 00113 bool 00114 Object::operator!=(const Object& other) 00115 { 00116 return obj_ != other.obj_; 00117 }
1.5.5