Exemplo n.º 1
0
void Dictionary_Entry_Value_Print( Dictionary_Entry_Value* self, Stream* stream ) {
	Dictionary_Index index;
	
	if( !self ) {
		return;
	}
	
	switch( self->type ) {
		case Dictionary_Entry_Value_Type_String:
			Journal_Printf( stream, "\"%s\"", self->as.typeString );
			return;
		case Dictionary_Entry_Value_Type_Double:
			Journal_Printf( stream, "%g", self->as.typeDouble );
			return;
		case Dictionary_Entry_Value_Type_UnsignedInt:
			Journal_Printf( stream, "%u", self->as.typeUnsignedInt );
			return;
		case Dictionary_Entry_Value_Type_Int:
			Journal_Printf( stream, "%d", self->as.typeInt );
			return;
		case Dictionary_Entry_Value_Type_UnsignedLong:
			Journal_Printf( stream, "%ld", self->as.typeUnsignedLong );
			return;
		case Dictionary_Entry_Value_Type_Bool:
			Journal_Printf( stream, "%s", Dictionary_Entry_Value_AsString( self ) );
			return;
		case Dictionary_Entry_Value_Type_List:
			if (self->as.typeList->first) {
				Dictionary_Entry_Value* cur = self->as.typeList->first;
				Dictionary_Entry_Value_Print( cur, stream );
				cur = cur->next;
				
				while (cur) {
					Journal_Printf( stream, ", " );
					Dictionary_Entry_Value_Print( cur, stream );
					cur = cur->next;
				}
			}
			return;
		case Dictionary_Entry_Value_Type_Struct:
			Stream_Indent( stream );
			for( index = 0; index < self->as.typeStruct->count; index++ ) {
				Journal_Printf( stream, "\n");
				Journal_Printf( stream, "%s: ", self->as.typeStruct->entryPtr[index]->key );
				Dictionary_Entry_Value_Print( self->as.typeStruct->entryPtr[index]->value, stream );
			}
			Stream_UnIndent( stream );
			return;
		default: {
			Stream* errorStream = Journal_Register( Error_Type, "Dictionary_Entry_Value" );
			Journal_Firewall( False, errorStream, "In func %s: self->type '%d' is invalid.\n", __func__, self->type );
		}
	}
}
Exemplo n.º 2
0
Dictionary_Entry_Value* _Stg_ComponentFactory_PluginGetNumericalValue( void* cf, void *codelet, Dictionary_Entry_Key key, Dictionary_Entry_Value* defaultVal ) {
   Stg_ComponentFactory*    self           = (Stg_ComponentFactory*)cf;
   Dictionary_Entry_Value* returnVal;
   Bool                    usedDefault       = False;
   Stream*                 stream            = self->infoStream;
   Stream*         errorStream       = Journal_Register( Error_Type, self->type );

   Journal_Firewall( self != NULL, errorStream, "In func %s: Stg_Component is NULL.\n", __func__ );

   returnVal = _Stg_ComponentFactory_PluginGetDictionaryValue( self, codelet, key, defaultVal );

   /* Check to see whether the type is a string -
    * if it is then assume that this is a dictionary key linking to the root dictionary */
   if ( returnVal ) {
      Dictionary_Entry_Key rootDictKey = Dictionary_Entry_Value_AsString( returnVal );
      Dictionary*          rootDict    = self->rootDict;

      /* Check if the number really is a string or not */
      if ( Stg_StringIsNumeric( rootDictKey ) )
         return returnVal;
      
      Journal_PrintfL( stream, 2, "Key '%s' points to key '%s' in the root dictionary: ", key, rootDictKey );

      Journal_Firewall( rootDict != NULL, errorStream, "Root Dictionary NULL in component factory.\n" );

      /* Get Value from dictionary */
      returnVal = Dictionary_Get( rootDict, rootDictKey );
      if ( !returnVal && defaultVal ) {
         returnVal = Dictionary_GetDefault( rootDict, rootDictKey, defaultVal );
         usedDefault = True;
      }

      /* Print Stuff */
      if ( usedDefault ) {
         Journal_PrintfL( stream, 2, "Using default value = " );
         if ( Stream_IsPrintableLevel( stream, 2 ) ) 
            Dictionary_Entry_Value_Print( returnVal, stream );
         Journal_PrintfL( stream, 2, "\n" );
         return returnVal;
      }
      else if ( returnVal ) {
         Journal_PrintfL( stream, 2, "Found - Value = " );
         if ( Stream_IsPrintableLevel( stream, 2 ) ) 
            Dictionary_Entry_Value_Print( returnVal, stream );
         Journal_PrintfL( stream, 2, "\n" );
      }
      else 
         Journal_PrintfL( stream, 2, "Not found.\n" );
   }

   return returnVal;
}
Exemplo n.º 3
0
Dictionary_Entry_Value* _Dictionary_GetDouble_WithScopeDefault(
   Dictionary*             dictionary,
   Dictionary_Entry_Key    key,
   Dictionary_Entry_Value* defaultVal )
{
   Dictionary_Entry_Value *returnVal=NULL;
   Bool                    usedDefault = False;
   Stream*                 stream = Journal_Register( Info_Type, "Dictionary" );

   returnVal = Dictionary_GetDefault( dictionary, key, defaultVal );

   if( returnVal && returnVal->type == Dictionary_Entry_Value_Type_String ) { 
      Dictionary_Entry_Key rootDictKey = Dictionary_Entry_Value_AsString( returnVal ); 
      Dictionary*          rootDict    = dictionary; 

      /* Check if the number really is a string or not */ 
      if( Stg_StringIsNumeric( rootDictKey ) ) 
         return returnVal; 

      Journal_PrintfL(
         stream,
         2,
         "Key '%s' points to key '%s' in the root dictionary: ",
         key,
         rootDictKey ); 

      /* Get Value from dictionary */ 
      returnVal = Dictionary_Get( rootDict, rootDictKey ); 
      if( !returnVal && defaultVal ) { 
         returnVal = Dictionary_GetDefault( rootDict, rootDictKey, defaultVal ); 
         usedDefault = True; 
      } 

      /* Print Stuff */ 
      if( usedDefault ) { 
         Journal_PrintfL( stream, 2, "Using default value = " ); 
         if( Stream_IsPrintableLevel( stream, 2 ) )  
            Dictionary_Entry_Value_Print( returnVal, stream ); 
            Journal_PrintfL( stream, 2, "\n" ); 
         return returnVal; 
      } 
      else if( returnVal ) { 
         Journal_PrintfL( stream, 2, "Found - Value = " ); 
         if( Stream_IsPrintableLevel( stream, 2 ) )  
            Dictionary_Entry_Value_Print( returnVal, stream ); 
         Journal_PrintfL( stream, 2, "\n" ); 
      } 
      else  
         Journal_PrintfL( stream, 2, "Not found.\n" ); 
   } 
   return returnVal;
}
Exemplo n.º 4
0
Dictionary_Entry_Value* _Stg_ComponentFactory_GetDictionaryValue( void* cf, Name componentName, Dictionary_Entry_Key key, Dictionary_Entry_Value* defaultVal ) {
   Stg_ComponentFactory*       self              = (Stg_ComponentFactory*) cf;
   Dictionary*             componentDict     = NULL;
   Dictionary*             thisComponentDict = NULL;
   Dictionary_Entry_Value* returnVal;
   Bool                    usedDefault       = False;
   Stream*                 errorStream       = Journal_Register( Error_Type, Stg_Component_Type );
   Stream*                 stream            = self->infoStream;

   Journal_Firewall( self != NULL, errorStream, "In func %s: Stg_ComponentFactory is NULL.\n", __func__ );

   Journal_PrintfL( stream, 2, "Getting parameter '%s': ", key );

   /* Get this Stg_Component's Dictionary */
   componentDict = self->componentDict;
   Journal_Firewall( componentDict != NULL, errorStream, 
         "In func %s: Stg_Component Factory's dictionary is NULL.\n", __func__ );
   thisComponentDict = Dictionary_GetDictionary( componentDict, componentName );
   if( thisComponentDict == NULL )
      return defaultVal;

   /* Get Value from dictionary */
   returnVal = Dictionary_Get( thisComponentDict, key );
   if ( !returnVal && defaultVal ) {
      returnVal = Dictionary_GetDefault( thisComponentDict, key, defaultVal );
      usedDefault = True;
   }

   /* Print Stuff */
   if ( usedDefault ) {
      Journal_PrintfL( stream, 2, "Using default value = " );
      if ( Stream_IsPrintableLevel( stream, 2 ) ) 
         Dictionary_Entry_Value_Print( returnVal, stream );
      Journal_PrintfL( stream, 2, "\n" );

      return returnVal;
   }
   else if ( returnVal ) {
      Journal_PrintfL( stream, 2, "Found - Value = " );
      if ( Stream_IsPrintableLevel( stream, 2 ) ) 
         Dictionary_Entry_Value_Print( returnVal, stream );
      Journal_PrintfL( stream, 2, "\n" );
   }
   else 
      Journal_PrintfL( stream, 2, "Not found.\n" );

   return returnVal;
}
Exemplo n.º 5
0
Dictionary_Entry_Value* _Stg_ComponentFactory_PluginGetDictionaryValue( void* cf, void *codelet, Dictionary_Entry_Key key, Dictionary_Entry_Value* defaultVal ) {
   Stg_ComponentFactory*       self              = (Stg_ComponentFactory*) cf;
   Stg_Component*             plugin          = (Stg_Component*)codelet;
   Dictionary*                thisPluginDict = NULL;
   Dictionary*                pluginDict     = (Dictionary*)Dictionary_Get( self->rootDict, "plugins" );
   Name                      pluginType;
   Index      pluginIndex;
   Dictionary_Entry_Value* returnVal;
   Bool                    usedDefault       = False;
   Stream*                 errorStream       = Journal_Register( Error_Type, Stg_Component_Type );
   Stream*                 stream            = self->infoStream;

   Journal_Firewall( self != NULL, errorStream, "In func %s: Stg_ComponentFactory is NULL.\n", __func__ );

   Journal_PrintfL( stream, 2, "Getting parameter '%s': ", key );

   Journal_Firewall( pluginDict != NULL, errorStream, 
         "In func %s: Stg_Component Factory's dictionary is NULL.\n", __func__ );

   /* Get this plugins Dictionary */
   for( pluginIndex = 0; pluginIndex < Dictionary_Entry_Value_GetCount( (Dictionary_Entry_Value*)pluginDict ); pluginIndex++ ) {
      thisPluginDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( (Dictionary_Entry_Value*)pluginDict, pluginIndex ) );
      pluginType = StG_Strdup( Dictionary_GetString( thisPluginDict, "Type" ) );
      if( !strcmp( plugin->type, pluginType ) ){
         Memory_Free( pluginType );
         break;
      }
                Memory_Free( pluginType );
   }

   /* Get this Stg_Component's Dictionary */
   Journal_Firewall( thisPluginDict != NULL, errorStream,
         "In func %s: Can't find sub-dictionary for component '%s'.\n", __func__, plugin->name );

   /* Get Value from dictionary */
   returnVal = Dictionary_Get( thisPluginDict, key );
   if ( !returnVal && defaultVal ) {
      returnVal = Dictionary_GetDefault( thisPluginDict, key, defaultVal );
      usedDefault = True;
   }

   /* Print Stuff */
   if ( usedDefault ) {
      Journal_PrintfL( stream, 2, "Using default value = " );
      if ( Stream_IsPrintableLevel( stream, 2 ) ) 
         Dictionary_Entry_Value_Print( returnVal, stream );
      Journal_PrintfL( stream, 2, "\n" );

      return returnVal;
   }
   else if ( returnVal ) {
      Journal_PrintfL( stream, 2, "Found - Value = " );
      if ( Stream_IsPrintableLevel( stream, 2 ) ) 
         Dictionary_Entry_Value_Print( returnVal, stream );
      Journal_PrintfL( stream, 2, "\n" );
   }
   else 
      Journal_PrintfL( stream, 2, "Not found.\n" );

   return returnVal;
}