Property::Value& Property::Value::GetValue(const std::string& key) const { DALI_ASSERT_DEBUG(Property::MAP == GetType() && "Property type invalid"); Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container); if(container) { for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) { if(iter->first == key) { return iter->second; } } } DALI_LOG_WARNING("Cannot find property map key %s", key.c_str()); DALI_ASSERT_ALWAYS(!"Cannot find property map key"); // should never return this static Property::Value null; return null; }
void Property::Value::SetItem(const int index, const Property::Value &value) { switch( GetType() ) { case Property::MAP: { Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue)); if( container && index < static_cast<int>(container->size()) ) { int i = 0; for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) { if(i++ == index) { iter->second = value; break; } } } } break; case Property::ARRAY: { Property::Array *container = AnyCast<Property::Array>(&(mImpl->mValue)); if( container && index < static_cast<int>(container->size()) ) { (*container)[index] = value; } } break; case Property::NONE: case Property::BOOLEAN: case Property::FLOAT: case Property::INTEGER: case Property::UNSIGNED_INTEGER: case Property::VECTOR2: case Property::VECTOR3: case Property::VECTOR4: case Property::MATRIX3: case Property::MATRIX: case Property::RECTANGLE: case Property::ROTATION: case Property::STRING: case Property::TYPE_COUNT: { DALI_ASSERT_ALWAYS(!"Cannot SetItem on property Type; not a container"); break; } } }
const std::string& Property::Value::GetKey(const int index) const { switch( GetType() ) { case Property::MAP: { int i = 0; Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); if(container) { if(0 <= index && index < static_cast<int>(container->size())) { for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) { if(i++ == index) { return iter->first; } } } } } break; case Property::NONE: case Property::ARRAY: case Property::BOOLEAN: case Property::FLOAT: case Property::UNSIGNED_INTEGER: case Property::INTEGER: case Property::VECTOR2: case Property::VECTOR3: case Property::VECTOR4: case Property::MATRIX: case Property::MATRIX3: case Property::RECTANGLE: case Property::ROTATION: case Property::STRING: case Property::TYPE_COUNT: { break; } } // should never return this static std::string null; return null; }
void Property::Value::SetValue(const std::string& key, const Property::Value &value) { DALI_ASSERT_DEBUG(Property::MAP == GetType() && "Property type invalid"); Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue)); if(container) { for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) { if(iter->first == key) { iter->second = value; return; } } // if we get here its a new key container->push_back(Property::StringValuePair(key, value)); } }
bool Property::Value::HasKey(const std::string& key) const { bool has = false; if( Property::MAP == GetType() ) { Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); if(container) { for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) { if(iter->first == key) { has = true; } } } } return has; }
Property::Value& Property::Value::GetItem(const int index) const { switch( GetType() ) { case Property::MAP: { int i = 0; Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); if(container) { DALI_ASSERT_ALWAYS(index < static_cast<int>(container->size()) && "Property array index invalid"); DALI_ASSERT_ALWAYS(index >= 0 && "Property array index invalid"); for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) { if(i++ == index) { return iter->second; } } } } break; case Property::ARRAY: { int i = 0; Property::Array *container = AnyCast<Property::Array>(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); if(container) { DALI_ASSERT_ALWAYS(index < static_cast<int>(container->size()) && "Property array index invalid"); DALI_ASSERT_ALWAYS(index >= 0 && "Property array index invalid"); for(Property::Array::iterator iter = container->begin(); iter != container->end(); ++iter) { if(i++ == index) { return *iter; } } } } break; case Property::NONE: case Property::BOOLEAN: case Property::FLOAT: case Property::INTEGER: case Property::UNSIGNED_INTEGER: case Property::VECTOR2: case Property::VECTOR3: case Property::VECTOR4: case Property::MATRIX3: case Property::MATRIX: case Property::RECTANGLE: case Property::ROTATION: case Property::STRING: case Property::TYPE_COUNT: { DALI_ASSERT_ALWAYS(!"Cannot GetItem on property Type; not a container"); break; } } // switch GetType() DALI_ASSERT_ALWAYS(!"Property value index not valid"); // should never return this static Property::Value null; return null; }