14 #include "../clib/stlutil.h" 34 const BObject& bkeyobj = elem.first;
44 for (
unsigned i = 0; i < size; ++i )
48 if ( keyimp != NULL && valimp != NULL )
80 m_IterVal( pIterVal ),
95 const BObject& okey = ( *itr ).first;
111 const BObject& okey = ( *itr ).first;
133 for (
const auto& elem : contents_ )
135 const BObject& bkeyobj = elem.first;
144 return contents_.size();
152 auto itr = contents_.find( key );
153 if ( itr != contents_.end() )
156 oref->setimp( target );
162 contents_[key] = ref;
171 auto itr = contents_.find( key );
172 if ( itr != contents_.end() )
174 return ( *itr ).second;
188 auto itr = contents_.find( obj );
189 if ( itr != contents_.end() )
201 return BObjectRef(
new BError(
"Dictionary keys must be integer, real, or string" ) );
213 auto itr = contents_.find( obj );
214 if ( itr != contents_.end() )
217 oref->setimp( new_target );
228 return new BError(
"Dictionary keys must be integer, real, or string" );
235 contents_[key] = val;
258 return new BLong( static_cast<int>( contents_.size() ) );
260 return new BError(
"dictionary.size() doesn't take parameters." );
267 return new BError(
"Dictionary keys must be integer, real, or string" );
268 int nremove =
static_cast<int>( contents_.erase( *keyobj ) );
269 return new BLong( nremove );
273 return new BError(
"dictionary.erase(key) requires a parameter." );
282 return new BError(
"Dictionary keys must be integer, real, or string" );
285 return new BLong( static_cast<int>( contents_.size() ) );
289 return new BError(
"dictionary.insert(key,value) requires two parameters." );
297 return new BError(
"Dictionary keys must be integer, real, or string" );
298 int count =
static_cast<int>( contents_.count( *keyobj ) );
299 return new BLong( count );
303 return new BError(
"dictionary.exists(key) requires a parameter." );
310 for (
const auto& content : contents_ )
312 const BObject& bkeyobj = content.first;
319 return new BError(
"dictionary.keys() doesn't take parameters." );
329 if ( objmethod != NULL )
356 os << packtype() << contents_.size() <<
":";
357 for (
const auto& content : contents_ )
359 const BObject& bkeyobj = content.first;
363 bvalref->impref().packonto( os );
372 if ( !( is >> size >> colon ) )
374 return new BError(
"Unable to unpack dictionary elemcount" );
379 "Unable to unpack dictionary elemcount. Length given must be positive integer!" );
383 return new BError(
"Unable to unpack dictionary elemcount. Bad format. Colon not found!" );
391 os << typetag() <<
"{ ";
394 for (
const auto& content : contents_ )
396 const BObject& bkeyobj = content.first;
404 FormatForStringRep( os, bkeyobj, bvalref );
416 << bvalref->impref().getFormattedStringRep();
423 if ( contents_.count( key ) == 0 )
BObjectImp * copy(void) const
virtual BObject * step() POL_OVERRIDE
bool isa(BObjectType type) const
size_t sizeEstimate() const
virtual char packtype() const
virtual BObjectImp * copy() const =0
#define OSTRINGSTREAM_STR(x)
virtual BObjectImp * array_assign(BObjectImp *idx, BObjectImp *target, bool copy) POL_OVERRIDE
friend class BDictionaryIterator
virtual const char * typetag() const
virtual BObjectImp * call_method_id(const int id, Executor &ex, bool forcebuiltin=false) POL_OVERRIDE
ObjMethod * getKnownObjMethod(const char *token)
virtual BObjectImp * copy() const POL_OVERRIDE
BObject * getParamObj(unsigned param)
virtual ContIterator * createIterator(BObject *pIterVal) POL_OVERRIDE
virtual size_t sizeEstimate() const POL_OVERRIDE
void setimp(BObjectImp *imp)
virtual std::string getStringRep() const POL_OVERRIDE
virtual const char * typeOf() const POL_OVERRIDE
virtual BObjectRef OperSubscript(const BObject &obj) POL_OVERRIDE
size_t sizeEstimate() const
static BObjectImp * unpack(std::istream &is)
std::map< BObject, BObjectRef > Contents
static UninitObject * create()
virtual std::string getFormattedStringRep() const
static BObjectImp * unpack(const char *pstr)
void addMember(const char *name, BObjectRef val)
virtual BObjectImp * call_method_id(const int id, Executor &ex, bool forcebuiltin=false)
unsigned int count() const
virtual BObjectImp * call_method(const char *methodname, Executor &ex) POL_OVERRIDE
virtual BObjectRef operDotPlus(const char *name) POL_OVERRIDE
virtual void packonto(std::ostream &os) const
virtual u8 typeOfInt() const POL_OVERRIDE
virtual BObjectRef get_member(const char *membername) POL_OVERRIDE
const Contents & contents() const
virtual void FormatForStringRep(std::ostream &os, const BObject &bkeyobj, const BObjectRef &bvalref) const
virtual void packonto(std::ostream &os) const POL_OVERRIDE
virtual BObjectRef set_member(const char *membername, BObjectImp *value, bool copy) POL_OVERRIDE
BDictionaryIterator(BDictionary *pDict, BObject *pIterVal)