Scripting: Update constant replacement in JSON files 08/20308/1
authorJavon Prince <javon.prince@samsung.com>
Fri, 25 Apr 2014 14:01:54 +0000 (15:01 +0100)
committerDavid Steele <david.steele@partner.samsung.com>
Thu, 1 May 2014 15:01:35 +0000 (16:01 +0100)
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 <javon.prince@samsung.com>
dali-toolkit/internal/builder/builder-impl.cpp
dali-toolkit/internal/builder/builder-impl.h
dali-toolkit/public-api/builder/builder.cpp
dali-toolkit/public-api/builder/builder.h

index a301570..06aa91e 100644 (file)
@@ -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);
index 7747b49..6b538a1 100644 (file)
@@ -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 );
index 4a3fdfc..06a1c90 100644 (file)
@@ -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 );
index abc5a26..209f3c2 100644 (file)
@@ -137,6 +137,44 @@ typedef std::map<std::string, Property::Value> 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");