9 #include <boost/format.hpp>    26 static bool IncludeNode( gp::Node* node, 
const std::string& search_path, gp::IncludedFiles* included,
    27                          gp::Messages* messages )
    29   gp::Node include_root;
    30   bool status = 
gp::Parse( node->position, node->value, search_path, included, messages, &include_root );
    31   if ( !status ) 
return false;
    32   node->value = include_root.value; 
    33   node->children.reserve( node->children.size() + include_root.children.size() );
    39 static bool UnitsNode( gp::Node* node, 
const std::string& search_path, gp::IncludedFiles* included,
    40                        gp::Messages* messages )
    43   bool status = 
gp::ParseUnits( node->position, node->value, search_path, included, messages, &units_root );
    44   if ( !status ) 
return false;
    45   node->value = units_root.value; 
    46   node->children.reserve( node->children.size() + units_root.children.size() );
    53   if ( node->children.size() == 1 ) {
    58     for ( 
unsigned int i = 0; i < ( node->children.size() - 1 ); ++i ) {
    59       client += delim + node->children[i].value;
    63         new gp::PropertyName( client, node->children[node->children.size() - 1].value, node->position ) );
    71   switch ( node->type ) {
    73   case gp::Node::kReal: {
    79     if ( node->children.size() == 1 ) {
    82       double unit_value     = 0;
    83       if ( units->Find( unit_name, unit_value ) ) {
    89         throw gp::PositionalPropertyValueException::CouldNotFindUnit( node->children[0].position, unit_name );
    92       value.
reset( 
new gp::PropertyValue( node->value ) );
    97   case gp::Node::kString: {
    99     value.
reset( 
new gp::PropertyValue( 
'"' + node->value + 
'"' ) );
   103   case gp::Node::kBool: {
   104     value.
reset( 
new gp::PropertyValue( node->value ) );
   108   case gp::Node::kVector: {
   110     result.
reserve( node->children.size() );
   112                     [&]( 
const gp::Node& child ) { return GetPropertyValue( &child, catalog, units )->ToString(); } );
   117   case gp::Node::kMap: {
   119     for ( 
const auto& child : node->children ) {
   120       auto kvalue = GetPropertyValue( &child.children[0], catalog, units );
   121       auto vvalue = GetPropertyValue( &child.children[1], catalog, units );
   122       result.
emplace( kvalue->ToString(), vvalue->ToString() );
   128   case gp::Node::kProperty: {
   129     auto property        = GetPropertyName( node );
   132       value.
reset( 
new gp::PropertyValue( exists->property_value() ) );
   134       throw gp::PositionalPropertyValueException::CouldNotFindProperty( node->position, 
property->ToString() );
   138   case gp::Node::kPropertyRef: {
   139     auto property = GetPropertyName( node );
   161   case gp::Node::kEqual: {
   165   case gp::Node::kPlusEqual: {
   169   case gp::Node::kMinusEqual: {
   180 static bool AssignNode( 
const gp::Node* node, gp::Messages* messages, gp::Catalog* catalog, gp::Units* units,
   186   auto property = GetPropertyName( &node->children[0] );
   188     value = GetPropertyValue( &node->children[2], catalog, units );
   189   } 
catch ( 
const gp::PositionalPropertyValueException& ex ) {
   190     messages->AddError( ex.position(), ex.what() );
   194   bool reassign        = 
false;
   202       if ( node->children[1].type == gp::Node::kEqual ) {
   204         if ( exists->HasDefinedPosition() ) {
   205           message += 
" Previously defined at " + exists->DefinedPosition().ToString() + 
".";
   210       } 
else if ( node->children[1].type == gp::Node::kPlusEqual ) {
   212       } 
else if ( node->children[1].type == gp::Node::kMinusEqual ) {
   215     } 
catch ( 
const gp::PropertyValueException& ex ) {
   217       if ( exists->HasDefinedPosition() ) {
   218         message += 
" Previously defined at " + exists->DefinedPosition().ToString() + 
".";
   220       messages->AddError( node->position, message );
   226   if ( !exists || reassign ) {
   230   if ( result && is_print ) { 
   232                                SignString( node->children[1].type ) % value->ToString() );
   233     messages->AddInfo( node->position, message );
   238 static bool UnitNode( 
const gp::Node* node, gp::Messages* messages, gp::Units* units, 
bool is_print )
   245   gp::Units::Container::mapped_type exists;
   246   if ( units->Find( name, exists ) ) {
   248     if ( exists.second.Exists() ) {
   249       message += 
" at " + exists.second.ToString();
   251     messages->AddError( node->children[1].position, message );
   255   bool result = units->Add( name, right / left, node->children[1].position );
   256   if ( result && is_print ) {
   258     messages->AddInfo( node->position, message );
   263 static bool ConditionNode( gp::Node* node, gp::Catalog* catalog, gp::Node** next )
   266   auto property_name = GetPropertyName( &node->children[0] );
   268   bool is_defined = ( 
nullptr != catalog->Find( property_name->client(), property_name->property() ) );
   270   if ( ( is_defined && ( node->children[1].type == gp::Node::kIfdef ) ) ||
   271        ( !is_defined && ( node->children[1].type == gp::Node::kIfndef ) ) ) {
   272     *next = &node->children[1];
   273   } 
else if ( node->children.size() > 2 ) {
   274     *next = &node->children[2];
   281 static bool Analyze( gp::Node* node, 
const std::string& search_path, gp::IncludedFiles* included,
   282                      gp::Messages* messages, gp::Catalog* catalog, gp::Units* units, gp::PragmaOptions* pragma )
   286   bool local_result   = 
true;
   287   bool skip_childs    = 
true;
   288   gp::Node* next_root = node;
   290   switch ( node->type ) {
   292   case gp::Node::kRoot: {
   297   case gp::Node::kInclude: {
   298     local_result = IncludeNode( node, search_path, included, messages );
   303   case gp::Node::kUnits: {
   304     local_result = UnitsNode( node, search_path, included, messages );
   309   case gp::Node::kAssign: {
   310     local_result = AssignNode( node, messages, catalog, units, pragma->is_print() );
   314   case gp::Node::kUnit: {
   315     local_result = UnitNode( node, messages, units, pragma->is_print() );
   319   case gp::Node::kCondition: {
   320     local_result = ConditionNode( node, catalog, &next_root );
   325   case gp::Node::kPrintOptions: {
   326     pragma->setIsPrintOptions( 
true );
   330   case gp::Node::kPrintOn: {
   331     pragma->setIsPrint( 
true );
   335   case gp::Node::kPrintOff: {
   336     pragma->setIsPrint( 
false );
   340   case gp::Node::kPrintTree: {
   341     pragma->setIsPrintTree( 
true );
   345   case gp::Node::kDumpFile: {
   348       pragma->setDumpFile( file );
   350       pragma->setDumpFile( node->value );
   359   if ( result ) result = local_result;
   361   if ( !skip_childs && next_root ) {
   362     for ( 
auto& child : next_root->children ) {
   363       local_result         = Analyze( &child, search_path, included, messages, catalog, units, pragma );
   364       if ( result ) result = local_result;
   372   bool unreference_result = 
true;
   373   for ( 
auto& client : catalog ) {
   374     for ( 
auto& current : client.second ) {
   375       if ( current.IsReference() ) {
   376         gp::PropertyValue& value              = current.property_value();
   378         gp::Property* 
property                = catalog.Find( names[0], names[1] );
   380           messages->AddError( value.position(), 
"Could not unreference " + current.ValueAsString() );
   381           unreference_result = 
false;
   383           value = 
property->property_value();
   388   return unreference_result;
   397   bool result = 
Parse( filename, search_path, &included, messages, root );
   398   if ( !result ) 
return false;
   400   bool result1 = Analyze( root, search_path, &included, messages, catalog, units, pragma );
   402   return result1 && result2;
 
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)". 
GAUDI_API StatusCode resolveEnv(const std::string &var, std::string &res, int recusions=124)
bool ParseUnits(const Position &from, const std::string &filename, const std::string &search_path, IncludedFiles *included, Messages *messages, Node *root)
Gaudi::Details::PropertyBase * property(const std::string &name) const 
bool ReadOptions(const std::string &filename, const std::string &search_path, Messages *messages, Catalog *catalog, Units *units, PragmaOptions *pragma, Node *root)
Parse and analyze filename, save all messages and properties. 
Gaudi::Details::PropertyBase Property
backward compatibility hack for old Property base class 
bool Parse(const std::string &filename, const std::string &search_path, IncludedFiles *included, Messages *messages, Node *root)
T back_inserter(T...args)
bool Unreference(gp::Catalog &catalog, gp::Messages *messages)
TO * reference(FROM *from)