#include "python.h"
namespace python {
template <class T>
mapref<T>::mapref (MapBase<T>& map, const std::string& k)
: s(map), the_item()
{
key = String(k);
if(map.hasKey(key)) the_item = map.getItem(key);
};
template <class T>
mapref<T>::mapref (MapBase<T>& map, const Object& k)
: s(map), key(k), the_item()
{
if(map.hasKey(key)) the_item = map.getItem(key);
};
template <class T>
mapref<T>::~mapref<T>() {}
// MapBase<T> stuff
// lvalue
template <class T>
mapref<T>& mapref<T>::operator=(const mapref<T>& other) {
if(this == &other) return *this;
the_item = other.the_item;
s.setItem(key, other.the_item);
return *this;
};
template <class T>
mapref<T>& mapref<T>::operator= (const T& ob) {
the_item = ob;
s.setItem (key, ob);
return *this;
}
// rvalue
template <class T>
mapref<T>::operator T() const {
return the_item;
}
// forward everything else to the_item
template <class T>
PyObject* mapref<T>::ptr () const {
return the_item.ptr();
}
template <class T>
int mapref<T>::reference_count () const { // the mapref count
return the_item.reference_count();
}
template <class T>
Type mapref<T>::type () const {
return the_item.type();
}
template <class T>
String mapref<T>::str () const {
return the_item.str();
}
template <class T>
String mapref<T>::repr () const {
return the_item.repr();
}
template <class T>
bool mapref<T>::has_attr (const std::string& attr_name) const {
return the_item.has_attr(attr_name);
}
template <class T>
Object mapref<T>::get_attr (const std::string& attr_name) const {
return the_item.get_attr(attr_name);
}
template <class T>
Object mapref<T>::get_item (const Object& k) const {
return the_item.get_item(k);
}
template <class T>
long mapref<T>::hash_value () const {
return the_item.hash_value();
}
template <class T>
bool mapref<T>::is_callable () const {
return the_item.is_callable();
}
template <class T>
bool mapref<T>::is_list () const {
return the_item.is_list();
}
template <class T>
bool mapref<T>::is_mapping () const {
return the_item.is_mapping();
}
template <class T>
bool mapref<T>::is_numeric () const {
return the_item.is_numeric();
}
template <class T>
bool mapref<T>::is_sequence () const {
return the_item.is_sequence();
}
template <class T>
bool mapref<T>::is_true () const {
return the_item.is_true();
}
template <class T>
bool mapref<T>::is_type (const Type& t) const {
return the_item.is_type (t);
}
template <class T>
bool mapref<T>::is_tuple() const {
return the_item.is_tuple();
}
template <class T>
bool mapref<T>::is_string() const {
return the_item.is_string();
}
// Commands
template <class T>
void mapref<T>::set_attr (const std::string& attr_name, const Object& value) {
the_item.set_attr(attr_name, value);
}
template <class T>
void mapref<T>::del_attr (const std::string& attr_name) {
the_item.del_attr(attr_name);
}
template <class T>
void mapref<T>::del_item (const Object& k) {
the_item.del_item(k);
}
}
syntax highlighted by Code2HTML, v. 0.9.1