| 496 | }; |
| 497 | |
| 498 | void bindCompoundData() |
| 499 | { |
| 500 | RunTimeTypedClass<CompoundDataBase>(); |
| 501 | |
| 502 | RunTimeTypedClass<CompoundData>( |
| 503 | "This class behaves like the native python dict, except that it only accepts objects derived from Data class.\n" |
| 504 | "The copy constructor accepts another instance of this class or a python dict containing Data objects\n" |
| 505 | "it has the most important dict methods: has_key, items, keys, values, get, pop, etc.\n" |
| 506 | ) |
| 507 | .def( init<>() ) |
| 508 | .def( "__init__", make_constructor( &CompoundDataFunctions::dataMapConstructor ), "Copy constructor: accepts a python dict containing Data objects." ) |
| 509 | .def( "__getitem__", &CompoundDataFunctions::getItem, "indexing operator.\nAccepts only string keys." ) |
| 510 | .def( "__setitem__", &CompoundDataFunctions::setItem, "index assignment operator.\nWorks exactly like on python dicts but only accepts Data objects as the new value." ) |
| 511 | .def( "__delitem__", &CompoundDataFunctions::delItem, "index deletion operator.\nWorks exactly like on python dicts." ) |
| 512 | .def( "__len__", &CompoundDataFunctions::len, "Length operator." ) |
| 513 | .def( "__contains__", &CompoundDataFunctions::has_key, "In operator.\nWorks exactly like on python dicts." ) |
| 514 | .def( "size", &CompoundDataFunctions::len, "m.size()\nReturns the number of elements on m. Same result as the len operator." ) |
| 515 | .def( "__cmp__", &CompoundDataFunctions::invalidOperator, "Raises an exception. CompoundData does not support comparison operators." ) |
| 516 | .def( "__repr__", &CompoundDataFunctions::repr ) |
| 517 | // python map methods. |
| 518 | .def( "clear", &CompoundDataFunctions::clear, "m.clear()\nRemoves all items from m." ) |
| 519 | .def( "has_key", &CompoundDataFunctions::has_key, "m.has_key(k)\nReturns True if m has key k; otherwise, returns False." ) |
| 520 | .def( "items", &CompoundDataFunctions::items, "m.items()\nReturns a list of (key, value) pairs." ) |
| 521 | .def( "keys", &CompoundDataFunctions::keys, "m.keys()\nReturns a list of key values." ) |
| 522 | .def( "update", &CompoundDataFunctions::update, "m.update(b)\nAdds all objects from b to m. b can be a CompoundData or a python dict." ) |
| 523 | .def( "values", &CompoundDataFunctions::values, "m.values()\nReturns a list of all values in m." ) |
| 524 | .def( "get", &CompoundDataFunctions::get, "m.get(k [, v])\nReturns m[k] if found; otherwise, returns v.", |
| 525 | ( |
| 526 | boost::python::arg( "self" ), |
| 527 | boost::python::arg( "key" ), |
| 528 | boost::python::arg( "defaultValue" ) = object() |
| 529 | ) |
| 530 | ) |
| 531 | .def( "setdefault", &CompoundDataFunctions::setdefault, "m.setdefault(k [, v])\nReturns m[k] if found; otherwise, returns v and sets m[k] = v." ) |
| 532 | .def( "setdefault", &CompoundDataFunctions::setdefault2 ) |
| 533 | .def( "pop", &CompoundDataFunctions::pop, "m.pop(k [,default])\nReturns m[k] if found and removes it from m; otherwise, returns default if supplied or raises KeyError if not." ) |
| 534 | .def( "pop", &CompoundDataFunctions::pop2 ) |
| 535 | .def( "popitem", &CompoundDataFunctions::popitem, "m.popitem()\nRemvoes a random (key,value) pair from m and returns it as a tuple." ) |
| 536 | .def( "hasBase", &CompoundData::hasBase ).staticmethod( "hasBase" ) |
| 537 | ; |
| 538 | |
| 539 | CompoundDataFromPythonDict(); |
| 540 | |
| 541 | } |
| 542 | |
| 543 | } // namespace IECorePython |
no test coverage detected