From: Javon Prince Date: Fri, 25 Apr 2014 14:01:54 +0000 (+0100) Subject: Scripting: Update constant replacement in JSON files X-Git-Tag: dali-2014-wk20-release~28 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=78304b72e0cd621ae2f51f93f746db341acde47e Scripting: Update constant replacement in JSON files Get entire map of key/value constants Get a single constant (by key) Add/Set a single constant( key,value ) [Issue#] (N/A) [Problem] [Cause] [Solution] Change-Id: I0a1912b43fc364f82f664c69b4348b834026d1da Signed-off-by: Javon Prince --- diff --git a/dali-toolkit/internal/builder/builder-impl.cpp b/dali-toolkit/internal/builder/builder-impl.cpp index a301570..06aa91e 100644 --- a/dali-toolkit/internal/builder/builder-impl.cpp +++ b/dali-toolkit/internal/builder/builder-impl.cpp @@ -820,6 +820,30 @@ void Builder::AddConstants( const PropertyValueMap& map ) } } +void Builder::AddConstant( const std::string& key, const Property::Value& value ) +{ + mReplacementMap[key] = value; +} + +const PropertyValueMap& Builder::GetConstants() const +{ + return mReplacementMap; +} + +const Property::Value& Builder::GetConstant( const std::string& key ) const +{ + PropertyValueMap::const_iterator iter = mReplacementMap.find( key ); + if( iter != mReplacementMap.end() ) + { + return (*iter).second; + } + else + { + static Property::Value invalid; + return invalid; + } +} + void Builder::LoadConstants() { Replacement replacer(mReplacementMap); diff --git a/dali-toolkit/internal/builder/builder-impl.h b/dali-toolkit/internal/builder/builder-impl.h index 7747b49..6b538a1 100644 --- a/dali-toolkit/internal/builder/builder-impl.h +++ b/dali-toolkit/internal/builder/builder-impl.h @@ -84,6 +84,21 @@ public: void AddConstants( const PropertyValueMap& map ); /** + * @copydoc Toolkit::Builder::AddConstant + */ + void AddConstant( const std::string& key, const Property::Value& value ); + + /** + * @copydoc Toolkit::Builder::GetConstants + */ + const PropertyValueMap& GetConstants() const; + + /** + * @copydoc Toolkit::Builder::GetConstant + */ + const Property::Value& GetConstant( const std::string& key ) const; + + /** * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName ); */ Animation CreateAnimation( const std::string& animationName ); diff --git a/dali-toolkit/public-api/builder/builder.cpp b/dali-toolkit/public-api/builder/builder.cpp index 4a3fdfc..06a1c90 100644 --- a/dali-toolkit/public-api/builder/builder.cpp +++ b/dali-toolkit/public-api/builder/builder.cpp @@ -58,6 +58,21 @@ void Builder::AddConstants( const PropertyValueMap& map ) GetImpl(*this).AddConstants( map ); } +void Builder::AddConstant( const std::string& key, const Property::Value& value ) +{ + GetImpl(*this).AddConstant( key, value ); +} + +const PropertyValueMap& Builder::GetConstants() const +{ + return GetImpl(*this).GetConstants(); +} + +const Property::Value& Builder::GetConstant( const std::string& key ) const +{ + return GetImpl(*this).GetConstant( key ); +} + Animation Builder::CreateAnimation( const std::string& animationName ) { return GetImpl(*this).CreateAnimation( animationName ); diff --git a/dali-toolkit/public-api/builder/builder.h b/dali-toolkit/public-api/builder/builder.h index abc5a26..209f3c2 100644 --- a/dali-toolkit/public-api/builder/builder.h +++ b/dali-toolkit/public-api/builder/builder.h @@ -137,6 +137,44 @@ typedef std::map PropertyValueMap; void AddConstants( const PropertyValueMap& map ); /** + * @brief Adds or modifies a user defined constant to all future style template or animation expansions + * + * e.g. + * @code builder.AddConstant( "IMAGE_DIRECTORY", "/usr/share/images" ); + * + * @pre The Builder has been initialized. + * @param key The constant name to add or update + * @param value The new value for the constant. + */ + void AddConstant( const std::string& key, const Property::Value& value ); + + /** + * @brief Gets all currently defined constants. + * + * e.g. + * @code PropertyValueMap map = builder.GetConstants(); // get copy of current constants + * map["IMAGE_DIRECTORY"] = "/usr/share/images"; // make modification + * builder.AddConstants( map ); // write back changes + * + * @pre The Builder has been initialized. + * @return A reference to the currently defined constants. + */ + const PropertyValueMap& GetConstants() const; + + /** + * @brief Gets a currently defined constant, or returns Property::INVALID + * + * e.g. + * @code PropertyValueMap map = builder.GetConstants(); // get copy of current constants + * map["IMAGE_DIRECTORY"] = "/usr/share/images"; // make modification + * builder.AddConstants( map ); // write back changes + * + * @pre The Builder has been initialized. + * @param key The constant name to search for. + */ + const Property::Value& GetConstant( const std::string& key ) const; + + /** * Creates an animation from the set of known animations * e.g. * Animation a = builder.CreateAnimation( "wobble");