void DictionarySuite_TestCreateValues( DictionarySuiteData* data ) { Dictionary_Entry_Value* dev; /* Don't use the pre-created test values. Want to do a very fundamental test here */ dev = Dictionary_Entry_Value_FromString( "hello" ); pcu_check_true( Dictionary_Entry_Value_Type_String == dev->type ); pcu_check_streq( "hello", dev->as.typeString ); Dictionary_Entry_Value_Delete( dev ); dev = Dictionary_Entry_Value_FromDouble( 45.567 ); pcu_check_true( Dictionary_Entry_Value_Type_Double == dev->type ); pcu_check_true( 45.567 == dev->as.typeDouble ); Dictionary_Entry_Value_Delete( dev ); dev = Dictionary_Entry_Value_FromUnsignedInt( 5 ); pcu_check_true( Dictionary_Entry_Value_Type_UnsignedInt == dev->type ); pcu_check_true( 5 == dev->as.typeUnsignedInt ); Dictionary_Entry_Value_Delete( dev ); dev = Dictionary_Entry_Value_FromInt( -5 ); pcu_check_true( Dictionary_Entry_Value_Type_Int == dev->type ); pcu_check_true( -5 == dev->as.typeInt ); Dictionary_Entry_Value_Delete( dev ); dev = Dictionary_Entry_Value_FromUnsignedLong( 52342423 ); pcu_check_true( Dictionary_Entry_Value_Type_UnsignedLong == dev->type ); pcu_check_true( 52342423 == dev->as.typeUnsignedLong ); Dictionary_Entry_Value_Delete( dev ); dev = Dictionary_Entry_Value_FromBool( True ); pcu_check_true( Dictionary_Entry_Value_Type_Bool == dev->type ); pcu_check_true( True == dev->as.typeBool ); Dictionary_Entry_Value_Delete( dev ); /* Since we know the DEV Struct is basically a Dictionary, won't test that one * until after we've tested Dictionary_Add works */ }
int Dictionary_GetInt_WithDefault( Dictionary* dictionary, Dictionary_Entry_Key key, const int defaultVal ) { return Dictionary_Entry_Value_AsInt( Dictionary_GetDefault( dictionary, key, Dictionary_Entry_Value_FromInt( defaultVal ) ) ); }
void Dictionary_Entry_Value_AddElementWithSource( Dictionary_Entry_Value* self, Dictionary_Entry_Value* element, Dictionary_Entry_Source source ) { /* check type - convert to a list if not so... */ if (Dictionary_Entry_Value_Type_List != self->type) { Dictionary_Entry_Value* copy; switch (self->type) { case Dictionary_Entry_Value_Type_String: copy = Dictionary_Entry_Value_FromString( self->as.typeString ); break; case Dictionary_Entry_Value_Type_Double: copy = Dictionary_Entry_Value_FromDouble( self->as.typeDouble ); break; case Dictionary_Entry_Value_Type_UnsignedInt: copy = Dictionary_Entry_Value_FromUnsignedInt( self->as.typeUnsignedInt ); break; case Dictionary_Entry_Value_Type_Int: copy = Dictionary_Entry_Value_FromInt( self->as.typeInt ); break; case Dictionary_Entry_Value_Type_UnsignedLong: copy = Dictionary_Entry_Value_FromUnsignedLong( self->as.typeUnsignedLong ); break; case Dictionary_Entry_Value_Type_Bool: copy = Dictionary_Entry_Value_FromBool( self->as.typeBool ); break; case Dictionary_Entry_Value_Type_Struct: copy = Dictionary_Entry_Value_NewStruct(); copy->as.typeStruct = self->as.typeStruct; break; 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 ); } } Dictionary_Entry_Value_SetNewList( self ); Dictionary_Entry_Value_AddElementWithSource( self, copy, source ); } if (!self->as.typeList->first) { self->as.typeList->first = element; } else { self->as.typeList->last->next = element; } self->as.typeList->last = element; self->as.typeList->count++; }
void DictionarySuite_SetupTestDictData( DictionarySuite_TestDictData* testDD ) { Index ii=0; Index iter=0; Dictionary_Entry_Value* testStruct; Dictionary_Entry_Value* testStruct2; Dictionary_Entry_Value* testList; testDD->testEntriesCount = 9; testDD->testKeys = Memory_Alloc_Array_Unnamed( char*, testDD->testEntriesCount ); testDD->testValues = Memory_Alloc_Array_Unnamed( Dictionary_Entry_Value*, testDD->testEntriesCount ); for ( ii=0; ii< testDD->testEntriesCount; ii++ ) { testDD->testKeys[ii] = NULL; testDD->testValues[ii] = NULL; } Stg_asprintf( &testDD->testString, "hello" ); Stg_asprintf( &testDD->testPlaceHolder, "test_double" ); testDD->testDouble=45.567; testDD->testUint = 5; testDD->testInt = -5; testDD->testUnsignedlong = 52342423; testDD->testBool = True; iter = 0; Stg_asprintf( &testDD->testKeys[iter], "test_cstring" ); testDD->testValues[iter] = Dictionary_Entry_Value_FromString( testDD->testString ); Stg_asprintf( &testDD->testKeys[++iter], "test_double" ); testDD->testValues[iter] = Dictionary_Entry_Value_FromDouble( testDD->testDouble ); Stg_asprintf( &testDD->testKeys[++iter], "test_uint" ); testDD->testValues[iter] = Dictionary_Entry_Value_FromUnsignedInt( testDD->testUint ); Stg_asprintf( &testDD->testKeys[++iter], "test_int" ); testDD->testValues[iter] = Dictionary_Entry_Value_FromInt( testDD->testInt ); Stg_asprintf( &testDD->testKeys[++iter], "test_unsignedlong" ); testDD->testValues[iter] = Dictionary_Entry_Value_FromUnsignedLong( testDD->testUnsignedlong ); Stg_asprintf( &testDD->testKeys[++iter], "test_bool" ); testDD->testValues[iter] = Dictionary_Entry_Value_FromUnsignedInt( testDD->testBool ); Stg_asprintf( &testDD->testKeys[++iter], "test_placeholder" ); testDD->testValues[iter] = Dictionary_Entry_Value_FromString( testDD->testPlaceHolder ); /* adding a list */ testDD->testListCount = 5; testDD->testList = Memory_Alloc_Array_Unnamed( double, testDD->testListCount ); for (ii=0; ii<testDD->testListCount; ii++ ) { testDD->testList[ii] = 10.0 * ii; } testList = Dictionary_Entry_Value_NewList(); Stg_asprintf( &testDD->testKeys[++iter], "test_list" ); testDD->testValues[iter] = testList; for (ii=0; ii < testDD->testListCount; ii++ ) { Dictionary_Entry_Value_AddElement( testList, Dictionary_Entry_Value_FromDouble(testDD->testList[ii]) ); } /* Adding members to a struct */ testDD->testStruct = Memory_Alloc_Unnamed( TestStruct ); testDD->testStruct->height = 37; testDD->testStruct->anisotropic = True; Stg_asprintf( &testDD->testStruct->person, "Patrick" ); testDD->testStruct->geom.startx = 45; testDD->testStruct->geom.starty = 60; testDD->testStruct->geom.startz = 70; testStruct = Dictionary_Entry_Value_NewStruct(); Stg_asprintf( &testDD->testKeys[++iter], "test_struct" ); testDD->testValues[iter] = testStruct; Dictionary_Entry_Value_AddMember( testStruct, (Dictionary_Entry_Key)"height", Dictionary_Entry_Value_FromDouble( testDD->testStruct->height ) ); Dictionary_Entry_Value_AddMember( testStruct, (Dictionary_Entry_Key)"anisotropic", Dictionary_Entry_Value_FromBool( testDD->testStruct->anisotropic ) ); Dictionary_Entry_Value_AddMember( testStruct, (Dictionary_Entry_Key)"person", Dictionary_Entry_Value_FromString( testDD->testStruct->person ) ); /* Adding a 2nd struct within the first struct */ testStruct2 = Dictionary_Entry_Value_NewStruct( ); Dictionary_Entry_Value_AddMember( testStruct, (Dictionary_Entry_Key)"geom", testStruct2 ); Dictionary_Entry_Value_AddMember( testStruct2, (Dictionary_Entry_Key)"startx", Dictionary_Entry_Value_FromUnsignedInt( testDD->testStruct->geom.startx ) ); Dictionary_Entry_Value_AddMember( testStruct2, (Dictionary_Entry_Key)"starty", Dictionary_Entry_Value_FromUnsignedInt( testDD->testStruct->geom.starty ) ); Dictionary_Entry_Value_AddMember( testStruct2, (Dictionary_Entry_Key)"startz", Dictionary_Entry_Value_FromUnsignedInt( testDD->testStruct->geom.startz ) ); }
int Stg_ComponentFactory_PluginGetInt( void* cf, void *codelet, Dictionary_Entry_Key key, int defaultVal ) { return Dictionary_Entry_Value_AsInt( _Stg_ComponentFactory_PluginGetNumericalValue( cf, codelet, key, Dictionary_Entry_Value_FromInt( defaultVal ))); }
int _Stg_ComponentFactory_GetInt( void* cf, Name componentName, Dictionary_Entry_Key key, int defaultVal ) { return Dictionary_Entry_Value_AsInt( _Stg_ComponentFactory_GetNumericalValue( cf, componentName, key, Dictionary_Entry_Value_FromInt( defaultVal ) ) ); }
void _UnderworldContext_Init( UnderworldContext* self ) { self->isConstructed = True; /* always generate XDMF files when we generate HDF5 checkpoints */ #ifdef WRITE_HDF5 if( Dictionary_Entry_Value_AsBool( Dictionary_GetDefault( self->dictionary, "generateXDMF", Dictionary_Entry_Value_FromBool( True ) ) ) ){ ContextEP_Append( self, AbstractContext_EP_Save, XDMFGenerator_GenerateAll ); ContextEP_Append( self, AbstractContext_EP_DataSave, XDMFGenerator_GenerateAll ); if( Dictionary_Entry_Value_AsInt( Dictionary_GetDefault( self->dictionary, "checkpointEvery" , Dictionary_Entry_Value_FromInt( 0 ) ) ) || Dictionary_Entry_Value_AsInt( Dictionary_GetDefault( self->dictionary, "saveDataEvery" , Dictionary_Entry_Value_FromInt( 0 ) ) ) || Dictionary_Entry_Value_AsInt( Dictionary_GetDefault( self->dictionary, "checkpointAtTimeInc", Dictionary_Entry_Value_FromInt( 0 ) ) ) ){ ContextEP_Append( self, AbstractContext_EP_Build, XDMFGenerator_GenerateTemporalTopLevel ); } } #endif }
Dictionary_Entry_Value* Dictionary_Entry_Value_Copy( Dictionary_Entry_Value* self, Bool deep ) { Dictionary_Entry_Value* copy = NULL; switch (self->type) { case Dictionary_Entry_Value_Type_String: copy = Dictionary_Entry_Value_FromString( self->as.typeString ); break; case Dictionary_Entry_Value_Type_Double: copy = Dictionary_Entry_Value_FromDouble( self->as.typeDouble ); break; case Dictionary_Entry_Value_Type_UnsignedInt: copy = Dictionary_Entry_Value_FromUnsignedInt( self->as.typeUnsignedInt ); break; case Dictionary_Entry_Value_Type_Int: copy = Dictionary_Entry_Value_FromInt( self->as.typeInt ); break; case Dictionary_Entry_Value_Type_UnsignedLong: copy = Dictionary_Entry_Value_FromUnsignedLong( self->as.typeUnsignedLong ); break; case Dictionary_Entry_Value_Type_Bool: copy = Dictionary_Entry_Value_FromBool( self->as.typeBool ); break; case Dictionary_Entry_Value_Type_List: if ( False == deep ) { Stream* errorStream = Journal_Register( Error_Type, "Dictionary_Entry_Value" ); Journal_Firewall( False, errorStream, "In func %s: Shallow copy operation of list DEV not supported.\n", __func__ ); } else { Dictionary_Entry_Value* cur = self->as.typeList->first; Dictionary_Entry_Value* copiedEntry = NULL; copy = Dictionary_Entry_Value_NewList(); while ( cur ) { copiedEntry = Dictionary_Entry_Value_Copy( cur, True ); Dictionary_Entry_Value_AddElement( copy, copiedEntry ); cur = cur->next; } } break; case Dictionary_Entry_Value_Type_Struct: if ( False == deep ) { copy = Dictionary_Entry_Value_FromStruct( self->as.typeStruct ); } else { Dictionary* copiedDict; copiedDict = (Dictionary*)Stg_Class_Copy( self->as.typeStruct, NULL, True, NULL, NULL ); copy = Dictionary_Entry_Value_FromStruct( copiedDict ); } break; 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 ); } } return copy; }