/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
// load constant map (allows the user to override the constants in the json after loading)
LoadConstants( *parser.GetRoot(), mReplacementMap );
-
+ // load configuration map
+ LoadConfiguration( *parser.GetRoot(), mConfigurationMap );
// merge includes
if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) )
{
}
}
- if( !mParser.Parse( data ) )
+ if( mParser.Parse( data ) )
+ {
+ // Drop the styles and get them to be rebuilt against the new parse tree as required.
+ mStyles.Clear();
+ }
+ else
{
DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
mParser.GetErrorLineNumber(),
}
}
- DUMP_PARSE_TREE(parser); // This macro only writes out if DEBUG is enabled and the "DUMP_TREE" constant is defined in the stylesheet.
- DUMP_TEST_MAPPINGS(parser);
+ DUMP_PARSE_TREE(mParser); // This macro only writes out if DEBUG is enabled and the "DUMP_TREE" constant is defined in the stylesheet.
+ DUMP_TEST_MAPPINGS(mParser);
DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
}
mReplacementMap[key] = value;
}
+const Property::Map& Builder::GetConfigurations() const
+{
+ return mConfigurationMap;
+}
+
const Property::Map& Builder::GetConstants() const
{
return mReplacementMap;
}
}
-FrameBufferImage Builder::GetFrameBufferImage( const std::string &name )
-{
- Replacement constant( mReplacementMap );
- return GetFrameBufferImage(name, constant);
-}
-
-FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant )
-{
- DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
-
- FrameBufferImage ret;
-
- ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) );
- if( iter != mFrameBufferImageLut.end() )
- {
- ret = iter->second;
- }
- else
- {
- if( OptionalChild images = IsChild( *mParser.GetRoot(), "frameBufferImages") )
- {
- if( OptionalChild image = IsChild( *images, name ) )
- {
- Dali::Property::Value property(Property::MAP);
- if( DeterminePropertyFromNode( *image, Property::MAP, property, constant ) )
- {
- Property::Map* map = property.GetMap();
-
- if( map )
- {
- (*map)[ KEYNAME_TYPE ] = Property::Value(std::string("FrameBufferImage") );
- ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( property ) );
- mFrameBufferImageLut[ name ] = ret;
- }
- }
- }
- }
- }
-
- return ret;
-}
-
Path Builder::GetPath( const std::string& name )
{
DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
{
}
+void Builder::LoadConfiguration( const TreeNode& root, Property::Map& intoMap )
+{
+ Replacement replacer(intoMap);
+
+ if( OptionalChild constants = IsChild(root, "config") )
+ {
+ for(TreeNode::ConstIterator iter = (*constants).CBegin();
+ iter != (*constants).CEnd(); ++iter)
+ {
+ Dali::Property::Value property;
+ if( (*iter).second.GetName() )
+ {
+ DeterminePropertyFromNode( (*iter).second, property, replacer );
+
+ // If config is string, find constant and replace it to original value.
+ if( (*iter).second.GetType() == TreeNode::STRING )
+ {
+ std::string stringConfigValue;
+ if( property.Get( stringConfigValue ) )
+ {
+ std::size_t pos = 0;
+
+ while( pos < stringConfigValue.size() )
+ {
+ // If we can't find "{","}" pair in stringConfigValue, will out loop.
+ std::size_t leftPos = stringConfigValue.find( "{", pos );
+ if( leftPos != std::string::npos )
+ {
+ std::size_t rightPos = stringConfigValue.find( "}", pos+1 );
+
+ if( rightPos != std::string::npos )
+ {
+ // If we find "{","}" pair but can't find matched constant
+ // try to find other "{","}" pair after current left position.
+ pos = leftPos+1;
+
+ for( uint32_t i = 0; i < mReplacementMap.Count() ; i++ )
+ {
+ Property::Key constant = mReplacementMap.GetKeyAt(i);
+
+ // Compare string which is between "{" and "}" with constant string
+ // If they are same, change string in stringConfigValue to mapped constant value.
+ if ( 0 == stringConfigValue.compare( leftPos+1, rightPos-leftPos-1, constant.stringKey ) )
+ {
+ std::string replaceString;
+ mReplacementMap.GetValue(i).Get( replaceString );
+
+ stringConfigValue.replace( leftPos, rightPos-leftPos+1, replaceString );
+ pos = leftPos + replaceString.size();
+ break;
+ }
+ }
+ }
+ else
+ {
+ // If we cannot find constant in const value, will out loop.
+ pos = stringConfigValue.size();
+ }
+ }
+ else
+ {
+ // If we cannot find constant in const value, will out loop.
+ pos = stringConfigValue.size();
+ }
+ }
+ property = Property::Value( stringConfigValue );
+ }
+ }
+ intoMap[ (*iter).second.GetName() ] = property;
+ }
+ }
+ }
+}
+
void Builder::LoadConstants( const TreeNode& root, Property::Map& intoMap )
{
Replacement replacer(intoMap);
}
}
- if( OptionalString s = constant.IsString( IsChild(node, "targetFrameBuffer") ) )
- {
- FrameBufferImage fb = GetFrameBufferImage( *s, constant );
- if(fb)
- {
- task.SetTargetFrameBuffer( fb );
- }
- else
- {
- DALI_SCRIPT_WARNING("Cannot find target frame buffer '%s'\n", (*s).c_str() );
- }
- }
-
if( OptionalString s = constant.IsString( IsChild(node, "screenToFrameBufferFunction") ) )
{
if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
}
else
{
- style->visuals.Add(visual.first, *property.GetMap());
+ Property::Map* map = property.GetMap();
+ if( map )
+ {
+ style->visuals.Add( visual.first, *map );
+ }
}
}
}