[cig-commits] commit: Adding clean-up of dictionary to AbstractContext_Destroy.
Mercurial
hg at geodynamics.org
Mon Feb 1 15:32:07 PST 2010
changeset: 697:b7f878b09d99
branch: pcu_rejig
user: JericoRevote
date: Mon Nov 23 11:43:25 2009 +1100
files: Base/Automation/src/Stg_Component.h Base/Automation/src/Stg_ComponentFactory.c Base/Context/src/AbstractContext.c Base/Context/src/AbstractContext.h Base/Context/tests/AbstractContextSuite.c Base/IO/src/Dictionary.c Base/IO/src/Dictionary.h Base/IO/tests/DictionarySuite.c src/main.c
description:
Adding clean-up of dictionary to AbstractContext_Destroy.
This should clean the dictionary per context now.
diff -r a472698bbd09 -r b7f878b09d99 Base/Automation/src/Stg_Component.h
--- a/Base/Automation/src/Stg_Component.h Thu Nov 19 15:51:21 2009 +1100
+++ b/Base/Automation/src/Stg_Component.h Mon Nov 23 11:43:25 2009 +1100
@@ -64,58 +64,51 @@
\
/* Virtual info */ \
Stg_Component_DefaultConstructorFunction* _defaultConstructor; \
- Stg_Component_ConstructFunction* _construct; \
- Stg_Component_BuildFunction* _build; \
- Stg_Component_InitialiseFunction* _initialise; \
- Stg_Component_ExecuteFunction* _execute; \
- Stg_Component_DestroyFunction* _destroy; \
+ Stg_Component_ConstructFunction* _construct; \
+ Stg_Component_BuildFunction* _build; \
+ Stg_Component_InitialiseFunction* _initialise; \
+ Stg_Component_ExecuteFunction* _execute; \
+ Stg_Component_DestroyFunction* _destroy; \
\
/* Stg_Component info */ \
- Bool isConstructed; \
- Bool isBuilt; \
- Bool isInitialised; \
- Bool hasExecuted; \
- Bool isDestroyed; \
- Type constructType; \
- Type buildType; \
- Type initialiseType; \
- Type executeType; \
- Type destroyType;
+ Bool isConstructed; \
+ Bool isBuilt; \
+ Bool isInitialised; \
+ Bool hasExecuted; \
+ Bool isDestroyed; \
+ Type constructType; \
+ Type buildType; \
+ Type initialiseType; \
+ Type executeType; \
+ Type destroyType;
struct Stg_Component { __Stg_Component };
- #define STG_COMPONENT_DEFARGS \
- STG_CLASS_DEFARGS, \
- Stg_Component_DefaultConstructorFunction* _defaultConstructor, \
- Stg_Component_ConstructFunction* _construct, \
- Stg_Component_BuildFunction* _build, \
- Stg_Component_InitialiseFunction* _initialise, \
- Stg_Component_ExecuteFunction* _execute, \
- Stg_Component_DestroyFunction* _destroy, \
- Name name, \
- AllocationType nameAllocationType
+ #define STG_COMPONENT_DEFARGS \
+ STG_CLASS_DEFARGS, \
+ Stg_Component_DefaultConstructorFunction* _defaultConstructor, \
+ Stg_Component_ConstructFunction* _construct, \
+ Stg_Component_BuildFunction* _build, \
+ Stg_Component_InitialiseFunction* _initialise, \
+ Stg_Component_ExecuteFunction* _execute, \
+ Stg_Component_DestroyFunction* _destroy, \
+ Name name, \
+ AllocationType nameAllocationType
- #define STG_COMPONENT_PASSARGS \
- STG_CLASS_PASSARGS, _defaultConstructor, _construct, \
- _build, _initialise, _execute, _destroy, \
- name, nameAllocationType
+ #define STG_COMPONENT_PASSARGS \
+ STG_CLASS_PASSARGS, \
+ _defaultConstructor, \
+ _construct, \
+ _build, \
+ _initialise, \
+ _execute, \
+ _destroy, \
+ name, \
+ nameAllocationType
/* No Stg_Component_New or Stg_Component_Init as this is an abstract class */
/* Creation implementation */
- Stg_Component* _Stg_Component_New(
- SizeT _sizeOfSelf,
- Type type,
- Stg_Class_DeleteFunction* _delete,
- Stg_Class_PrintFunction* _print,
- Stg_Class_CopyFunction* _copy,
- Stg_Component_DefaultConstructorFunction* _defaultConstructor,
- Stg_Component_ConstructFunction* _construct,
- Stg_Component_BuildFunction* _build,
- Stg_Component_InitialiseFunction* _initialise,
- Stg_Component_ExecuteFunction* _execute,
- Stg_Component_DestroyFunction* _destroy,
- Name name,
- AllocationType nameAllocationType );
+ Stg_Component* _Stg_Component_New( STG_COMPONENT_DEFARGS );
/* Class Administration members ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
diff -r a472698bbd09 -r b7f878b09d99 Base/Automation/src/Stg_ComponentFactory.c
--- a/Base/Automation/src/Stg_ComponentFactory.c Thu Nov 19 15:51:21 2009 +1100
+++ b/Base/Automation/src/Stg_ComponentFactory.c Mon Nov 23 11:43:25 2009 +1100
@@ -744,21 +744,21 @@ Stg_Component* _Stg_ComponentFactory_Con
}
Stg_Component* _Stg_ComponentFactory_PluginConstructByKey(
- void* cf,
- void* codelet,
- Dictionary_Entry_Key componentKey,
- Type type,
- Bool isEssential,
- void* data )
+ void* cf,
+ void* codelet,
+ Dictionary_Entry_Key componentKey,
+ Type type,
+ Bool isEssential,
+ void* data )
{
- Stg_ComponentFactory* self = (Stg_ComponentFactory*)cf;
- Stg_Component* plugin = (Stg_Component*)codelet;
- Dictionary* thisPluginDict = NULL;
- Dictionary* pluginDict = Dictionary_Get( self->rootDict, "plugins" );
- Name componentName, redirect, pluginType;
- Dictionary_Entry_Value* componentEntryVal;
- Index pluginIndex;
- Stream* errorStream = Journal_Register( Error_Type, self->type );
+ Stg_ComponentFactory* self = (Stg_ComponentFactory*)cf;
+ Stg_Component* plugin = (Stg_Component*)codelet;
+ Dictionary* thisPluginDict = NULL;
+ Dictionary* pluginDict = (Dictionary*)Dictionary_Get( self->rootDict, "plugins" );
+ Name componentName, redirect, pluginType;
+ Dictionary_Entry_Value* componentEntryVal;
+ Index pluginIndex;
+ Stream* errorStream = Journal_Register( Error_Type, self->type );
Journal_Firewall( self != NULL, errorStream, "In func %s: Stg_Component is NULL.\n", __func__ );
@@ -766,6 +766,7 @@ Stg_Component* _Stg_ComponentFactory_Plu
for( pluginIndex = 0; pluginIndex < Dictionary_Entry_Value_GetCount( pluginDict ); pluginIndex++ ) {
thisPluginDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( pluginDict, pluginIndex ) );
pluginType = StG_Strdup( Dictionary_GetString( thisPluginDict, "Type" ) );
+
if( !strcmp( plugin->type, pluginType ) ){
Memory_Free( pluginType );
break;
@@ -798,7 +799,7 @@ Dictionary_Entry_Value* _Stg_ComponentFa
Stg_ComponentFactory* self = (Stg_ComponentFactory*) cf;
Stg_Component* plugin = (Stg_Component*)codelet;
Dictionary* thisPluginDict = NULL;
- Dictionary* pluginDict = Dictionary_Get( self->rootDict, "plugins" );
+ Dictionary* pluginDict = (Dictionary*)Dictionary_Get( self->rootDict, "plugins" );
Name pluginType;
Index pluginIndex;
Dictionary_Entry_Value* returnVal;
diff -r a472698bbd09 -r b7f878b09d99 Base/Context/src/AbstractContext.c
--- a/Base/Context/src/AbstractContext.c Thu Nov 19 15:51:21 2009 +1100
+++ b/Base/Context/src/AbstractContext.c Mon Nov 23 11:43:25 2009 +1100
@@ -227,10 +227,6 @@ void _AbstractContext_Delete( void* abst
Stg_Class_Delete( self->variable_Register );
- /* Temporarily disabling this line as the Underworld PCU test fails
- when this line is called. Need to look for an alternative way to delete this. */
- /*Stg_Class_Delete( self->plugins );*/
-
/* Stg_Class_Delete parent */
_Stg_Component_Delete( self );
}
@@ -607,7 +603,7 @@ void _AbstractContext_Execute( void* con
void _AbstractContext_Destroy( void* context, void* data ) {
- AbstractContext* self = (AbstractContext*)context;
+ AbstractContext* self = (AbstractContext*)context;
Journal_Printf( self->debug, "In: %s\n", __func__ );
@@ -624,13 +620,12 @@ void _AbstractContext_Destroy( void* con
/* remove the self->extensionMgr of this context from the extensionMgr_Register */
ExtensionManager_Register_Remove( extensionMgr_Register, self->extensionMgr );
Stg_Class_Delete( self->extensionMgr );
+ Stg_Class_Delete( self->dictionary );
Memory_Free( self->experimentName );
Memory_Free( self->outputPath );
Memory_Free( self->checkpointReadPath );
Memory_Free( self->checkpointWritePath );
-
- /*_AbstractContext_Delete( context );*/
}
diff -r a472698bbd09 -r b7f878b09d99 Base/Context/src/AbstractContext.h
--- a/Base/Context/src/AbstractContext.h Thu Nov 19 15:51:21 2009 +1100
+++ b/Base/Context/src/AbstractContext.h Mon Nov 23 11:43:25 2009 +1100
@@ -24,8 +24,6 @@
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**
-*/
-/** \file
** Role:
** Abstract class faciliting how "modellers"/"solvers" are laid out and execute.
**
@@ -87,83 +85,83 @@
#define __AbstractContext \
/* General info */ \
__Stg_Component \
- Dictionary* dictionary; \
+ Dictionary* dictionary; \
\
/* Virtual info */ \
- AbstractContext_SetDt* _setDt; \
+ AbstractContext_SetDt* _setDt; \
\
/* AbstractContext info */ \
- MPI_Comm communicator; \
- int rank; \
- int nproc; \
+ MPI_Comm communicator; \
+ int rank; \
+ int nproc; \
/** Start time for the simulation. */ \
- double startTime; \
+ double startTime; \
/** Stop time for the simulation. Note that if this is 0, the sim will keep running unless a
max loops criterion is met. */ \
- double stopTime; \
- double currentTime; \
- unsigned int timeStep; \
- double dtFactor; \
- double dt; \
+ double stopTime; \
+ double currentTime; \
+ unsigned int timeStep; \
+ double dtFactor; \
+ double dt; \
/** This additional timestep is necessary for checkpoint restart runs, so it can be compared against
maxTimeSteps (which is now relative to job restart).*/ \
- unsigned int timeStepSinceJobRestart; \
+ unsigned int timeStepSinceJobRestart; \
/** Maximum number of time steps to run for. If set to 0, then this will be ignored. */ \
- unsigned int maxTimeSteps; \
+ unsigned int maxTimeSteps; \
/** Final Time Step: last time step to run till, no matter if maxTimeSteps still has some
left in a checkpoint restart run. If 0 (the default), not active. */ \
- unsigned int finalTimeStep; \
- Bool gracefulQuit; \
- unsigned int frequentOutputEvery; \
- unsigned int dumpEvery; \
- unsigned int checkpointEvery; \
- unsigned int saveDataEvery; \
- double checkpointAtTimeInc; \
- double nextCheckpointTime; \
- Name experimentName; \
- char* outputPath; \
- char* checkpointReadPath; \
- char* checkpointWritePath; \
+ unsigned int finalTimeStep; \
+ Bool gracefulQuit; \
+ unsigned int frequentOutputEvery; \
+ unsigned int dumpEvery; \
+ unsigned int checkpointEvery; \
+ unsigned int saveDataEvery; \
+ double checkpointAtTimeInc; \
+ double nextCheckpointTime; \
+ Name experimentName; \
+ char* outputPath; \
+ char* checkpointReadPath; \
+ char* checkpointWritePath; \
/** user set bool to determine whether checkpoint (or data) files should be placed in a per timestep directory */ \
- Bool checkpointAppendStep; \
+ Bool checkpointAppendStep; \
/** user set bool to determine whether checkpoint restarts should interpolate to new
resolution (where resolution is different from checkpoints) */ \
- Bool interpolateRestart; \
- Bool loadFromCheckPoint; \
+ Bool interpolateRestart; \
+ Bool loadFromCheckPoint; \
/** Bool to determine whether we are storing a full checkpoint (for restart) or only data for analysis */ \
- Bool isDataSave; \
+ Bool isDataSave; \
/** flattened XML output can be disabled if desired (default True) */ \
- Bool outputFlattenedXML; \
- unsigned int restartTimestep; \
- char* checkPointPrefixString; \
- Stream* info; \
- Stream* verbose; \
- Stream* debug; \
+ Bool outputFlattenedXML; \
+ unsigned int restartTimestep; \
+ char* checkPointPrefixString; \
+ Stream* info; \
+ Stream* verbose; \
+ Stream* debug; \
\
/* These are stored keys to entrypoints in the table, used for O(1) lookup (i.e. speed) */ \
/* Contexts "are" Components implemented by entrypoints... there's an entry point per component phase */ \
- EntryPoint_Index constructK; \
- EntryPoint_Index constructExtensionsK; \
- EntryPoint_Index buildK; \
- EntryPoint_Index initialiseK; \
- EntryPoint_Index executeK; \
- EntryPoint_Index destroyK; \
- EntryPoint_Index destroyExtensionsK; \
+ EntryPoint_Index constructK; \
+ EntryPoint_Index constructExtensionsK; \
+ EntryPoint_Index buildK; \
+ EntryPoint_Index initialiseK; \
+ EntryPoint_Index executeK; \
+ EntryPoint_Index destroyK; \
+ EntryPoint_Index destroyExtensionsK; \
\
/* The following are not really part of an abstract context, and will one day be refactored somewhere else */ \
- EntryPoint_Index dtK; \
- EntryPoint_Index stepK; \
- EntryPoint_Index updateClassK; \
- EntryPoint_Index solveK; \
- EntryPoint_Index postSolveK; \
- EntryPoint_Index syncK; \
- EntryPoint_Index frequentOutputK; \
- EntryPoint_Index dumpK; \
- EntryPoint_Index dumpClassK; \
- EntryPoint_Index saveK; \
- EntryPoint_Index saveClassK; \
- EntryPoint_Index dataSaveK; \
- EntryPoint_Index dataSaveClassK; \
+ EntryPoint_Index dtK; \
+ EntryPoint_Index stepK; \
+ EntryPoint_Index updateClassK; \
+ EntryPoint_Index solveK; \
+ EntryPoint_Index postSolveK; \
+ EntryPoint_Index syncK; \
+ EntryPoint_Index frequentOutputK; \
+ EntryPoint_Index dumpK; \
+ EntryPoint_Index dumpClassK; \
+ EntryPoint_Index saveK; \
+ EntryPoint_Index saveClassK; \
+ EntryPoint_Index dataSaveK; \
+ EntryPoint_Index dataSaveClassK; \
\
Variable_Register* variable_Register; \
Pointer_Register* pointer_Register; \
@@ -282,7 +280,9 @@
/* Default construction hook, and overrides for the EP to handle the context/ptrToContext synchronisation */
void _AbstractContext_Construct_Hook( void* _context, void* data );
+
Func_Ptr _AbstractContext_Construct_EP_GetRun( void* entryPoint );
+
void _AbstractContext_Construct_EP_Run( void* entryPoint, void* data0, void* data1 );
/* Default construction hook */
@@ -292,6 +292,8 @@
void _AbstractContext_Step( void* _context, double dt );
void _AbstractContext_LoadTimeInfoFromCheckPoint( void* _context, Index timeStep, double* dtLoadedFromFile );
+
void _AbstractContext_SaveTimeInfo( void* _context );
+
void _AbstractContext_CreateCheckpointDirectory( void* _context );
#endif /* __Base_Context_AbstractContext_h__ */
diff -r a472698bbd09 -r b7f878b09d99 Base/Context/tests/AbstractContextSuite.c
--- a/Base/Context/tests/AbstractContextSuite.c Thu Nov 19 15:51:21 2009 +1100
+++ b/Base/Context/tests/AbstractContextSuite.c Mon Nov 23 11:43:25 2009 +1100
@@ -71,12 +71,10 @@ void TestSetDt( void* context, double _d
dt = _dt;
}
-
typedef struct {
TestContext* ctx;
Dictionary* dict;
} AbstractContextSuiteData;
-
TestContext* TestContext_New(
Name name,
@@ -89,7 +87,7 @@ TestContext* TestContext_New(
ctx = (TestContext*)_AbstractContext_New(
sizeof(TestContext),
- "TestContext",
+ "TestContext",
_AbstractContext_Delete,
_AbstractContext_Print,
NULL,
@@ -136,7 +134,6 @@ void TestInitialConditions( void* contex
self->computedValue = GLOBAL_COMP_VALUE[self->restartTimestep];
}
}
-
double TestDt( void* context ) {
TestContext* self = (TestContext*)context;
@@ -177,9 +174,9 @@ void TestDump( void* context ) {
}
void AbstractContextSuite_Setup( AbstractContextSuiteData* data ) {
- Stg_ComponentFactory* cf;
- MPI_Comm CommWorld;
- Index ii;
+ Stg_ComponentFactory* cf;
+ MPI_Comm CommWorld;
+ Index ii;
data->dict = Dictionary_New();
@@ -196,12 +193,7 @@ void AbstractContextSuite_Setup( Abstrac
MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
/* Build the context */
- data->ctx = TestContext_New(
- "context",
- 0,
- 0,
- CommWorld,
- data->dict );
+ data->ctx = TestContext_New( "context", 0, 0, CommWorld, data->dict );
_AbstractContext_Init( (AbstractContext*)data->ctx );
_AbstractContext_AssignFromXML( data->ctx, cf, NULL );
@@ -210,10 +202,9 @@ void AbstractContextSuite_Setup( Abstrac
}
void AbstractContextSuite_Teardown( AbstractContextSuiteData* data ) {
- Stg_Class_Delete( data->dict );
+ _Stg_Component_Delete( data->ctx );
}
-
void AbstractContextSuite_TestDefaultEPs( AbstractContextSuiteData* data ) {
ContextEntryPoint* contextEP=NULL;
@@ -286,10 +277,7 @@ void AbstractContextSuite_TestRunBasic(
pcu_check_true( data->ctx->outputHookCalled == 10 );
pcu_check_true( data->ctx->dumpHookCalled == 10/Dictionary_GetUnsignedInt(data->dict, "dumpEvery" ) );
pcu_check_true( data->ctx->checkpointHookCalled == 10/Dictionary_GetUnsignedInt(data->dict, "checkpointEvery" ) );
-
- Stg_Component_Destroy( data->ctx, 0 /* dummy */, False );
}
-
void AbstractContextSuite_TestRunNoDtDefined( AbstractContextSuiteData* data ) {
ContextEP_ReplaceAll( data->ctx, AbstractContext_EP_Build, TestBuild );
@@ -304,10 +292,7 @@ void AbstractContextSuite_TestRunNoDtDef
stJournal->enable = False;
pcu_check_assert( Stg_Component_Execute( data->ctx, 0 /* dummy */, False ) );
stJournal->enable = True;
-
- Stg_Component_Destroy( data->ctx, 0 /* dummy */, False );
}
-
void AbstractContextSuite_TestRestartFromCheckpoint( AbstractContextSuiteData* data ) {
Stg_ComponentFactory* cf;
@@ -323,18 +308,20 @@ void AbstractContextSuite_TestRestartFro
Stg_Component_Execute( data->ctx, 0 /* dummy */, False );
Stg_Component_Destroy( data->ctx, 0 /* dummy */, False );
+ data->dict = Dictionary_New();
+
+ Dictionary_Add( data->dict, "outputPath", Dictionary_Entry_Value_FromString( "output" ) );
+ Dictionary_Add( data->dict, "checkpointEvery", Dictionary_Entry_Value_FromUnsignedInt( 5 ) );
+ Dictionary_Add( data->dict, "dumpEvery", Dictionary_Entry_Value_FromUnsignedInt( 2 ) );
+ Dictionary_Add( data->dict, "maxTimeSteps", Dictionary_Entry_Value_FromUnsignedInt( 10 ) );
+
/* ReBuild the context */
Dictionary_Set( data->dict, "maxTimeSteps", Dictionary_Entry_Value_FromUnsignedInt( 20 ) );
Dictionary_Set( data->dict, "restartTimestep", Dictionary_Entry_Value_FromUnsignedInt( 5 ) );
MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
cf = Stg_ComponentFactory_New( data->dict, NULL );
- data->ctx = TestContext_New(
- "context",
- 0,
- 0,
- CommWorld,
- data->dict );
+ data->ctx = TestContext_New( "context", 0, 0, CommWorld, data->dict );
_AbstractContext_Init( (AbstractContext*)data->ctx );
_AbstractContext_AssignFromXML( data->ctx, cf, NULL );
@@ -356,10 +343,7 @@ void AbstractContextSuite_TestRestartFro
* run1_ts + run2_ts, and computed value should equal 1.1 to power (run1_ts + run2_ts) */
pcu_check_true( data->ctx->timeStep == (5 + 20) );
pcu_check_true( abs(data->ctx->computedValue - pow( 1.1, (5 + 20) )) < 1e-8 );
-
- Stg_Component_Destroy( data->ctx, 0 /* dummy */, False );
}
-
void AbstractContextSuite( pcu_suite_t* suite ) {
pcu_suite_setData( suite, AbstractContextSuiteData );
diff -r a472698bbd09 -r b7f878b09d99 Base/IO/src/Dictionary.c
--- a/Base/IO/src/Dictionary.c Thu Nov 19 15:51:21 2009 +1100
+++ b/Base/IO/src/Dictionary.c Mon Nov 23 11:43:25 2009 +1100
@@ -54,23 +54,33 @@ static const int STRUCT_DELTA = 2;
static const int STRUCT_DELTA = 2;
Dictionary* Dictionary_New( void ) {
- return _Dictionary_New( sizeof(Dictionary), Dictionary_Type, _Dictionary_Delete, _Dictionary_Print, _Dictionary_Copy,
- _Dictionary_Add, _Dictionary_AddWithSource, _Dictionary_Set, _Dictionary_SetWithSource, _Dictionary_Get, _Dictionary_GetSource );
+ return _Dictionary_New(
+ sizeof(Dictionary),
+ Dictionary_Type,
+ _Dictionary_Delete,
+ _Dictionary_Print,
+ _Dictionary_Copy,
+ _Dictionary_Add,
+ _Dictionary_AddWithSource,
+ _Dictionary_Set,
+ _Dictionary_SetWithSource,
+ _Dictionary_Get,
+ _Dictionary_GetSource );
}
Dictionary* _Dictionary_New(
- SizeT _sizeOfSelf,
- Type type,
- Stg_Class_DeleteFunction* _delete,
- Stg_Class_PrintFunction* _print,
- Stg_Class_CopyFunction* _copy,
- Dictionary_AddFunction* add,
- Dictionary_AddWithSourceFunction* addWithSource,
- Dictionary_SetFunction* set,
- Dictionary_SetWithSourceFunction* setWithSource,
- Dictionary_GetFunction* get,
- Dictionary_GetSourceFunction getSource)
-{
+ SizeT _sizeOfSelf,
+ Type type,
+ Stg_Class_DeleteFunction* _delete,
+ Stg_Class_PrintFunction* _print,
+ Stg_Class_CopyFunction* _copy,
+ Dictionary_AddFunction* add,
+ Dictionary_AddWithSourceFunction* addWithSource,
+ Dictionary_SetFunction* set,
+ Dictionary_SetWithSourceFunction* setWithSource,
+ Dictionary_GetFunction* get,
+ Dictionary_GetSourceFunction getSource)
+{
Dictionary* self;
/* Allocate memory */
@@ -93,38 +103,15 @@ Dictionary* _Dictionary_New(
return self;
}
+void _Dictionary_Init( void* dictionary ) {
+ Dictionary* self = (Dictionary*) dictionary;
-void Dictionary_Init( Dictionary* self ) {
- /* General info */
- self->_sizeOfSelf = sizeof( Dictionary );
- self->type = Dictionary_Type;
- self->_deleteSelf = False;
-
- /* Virtual info */
- _Stg_Class_Init( (Stg_Class*)self );
- self->_print = _Dictionary_Print;
- self->_delete = _Dictionary_Delete;
- self->_copy = _Dictionary_Copy;
- self->add = _Dictionary_Add;
- self->addWithSource = _Dictionary_AddWithSource;
- self->set = _Dictionary_Set;
- self->setWithSource = _Dictionary_SetWithSource;
- self->get = _Dictionary_Get;
- self->getSource = _Dictionary_GetSource;
-
- /* Dictionary info */
- _Dictionary_Init( self );
-}
-
-void _Dictionary_Init( Dictionary* self ) {
self->size = DEFAULT_INIT_SIZE;
self->delta = DEFAULT_DELTA;
self->count = 0;
self->entryPtr = Memory_Alloc_Array( Dictionary_Entry*, self->size, "Dictionary->entryPtr" );
-
self->debugStream = Journal_Register( Debug_Type, "DictionaryWarning" );
}
-
void _Dictionary_Delete( void* dictionary ) {
Dictionary* self = (Dictionary*) dictionary;
@@ -139,7 +126,6 @@ void _Dictionary_Delete( void* dictionar
_Stg_Class_Delete( self );
}
-
void _Dictionary_Print( void* dictionary, Stream* stream ) {
Dictionary* self = (Dictionary*) dictionary;
Dictionary_Index index;
@@ -154,6 +140,7 @@ void _Dictionary_Print( void* dictionary
Journal_Printf( (void*)stream, "\tentryPtr[0-%u]: {\n", self->count );
Stream_Indent( stream );
Stream_Indent( stream );
+
for( index = 0; index < self->count; index++ ) {
/*Journal_Printf( (void*)stream, "\t\t" );*/
Dictionary_Entry_Print( self->entryPtr[index], stream );
diff -r a472698bbd09 -r b7f878b09d99 Base/IO/src/Dictionary.h
--- a/Base/IO/src/Dictionary.h Thu Nov 19 15:51:21 2009 +1100
+++ b/Base/IO/src/Dictionary.h Mon Nov 23 11:43:25 2009 +1100
@@ -80,21 +80,21 @@
__Stg_Class \
\
/* Virtual info */ \
- Dictionary_AddFunction* add; \
+ Dictionary_AddFunction* add; \
Dictionary_AddWithSourceFunction* addWithSource; \
- Dictionary_SetFunction* set; \
+ Dictionary_SetFunction* set; \
Dictionary_SetWithSourceFunction* setWithSource; \
- Dictionary_GetFunction* get; \
- Dictionary_GetSourceFunction* getSource; \
+ Dictionary_GetFunction* get; \
+ Dictionary_GetSourceFunction* getSource; \
\
/* Dictionary info */ \
- Dictionary_Index size; \
- Dictionary_Index delta; \
+ Dictionary_Index size; \
+ Dictionary_Index delta; \
\
- Dictionary_Index count; \
- Dictionary_Entry** entryPtr; \
+ Dictionary_Index count; \
+ Dictionary_Entry** entryPtr; \
\
- Stream* debugStream;
+ Stream* debugStream;
struct _Dictionary { __Dictionary };
/*--------------------------------------------------------------------------------------------------------------------------
@@ -106,23 +106,20 @@
/** Constructor interface. */
Dictionary* _Dictionary_New(
- SizeT _sizeOfSelf,
- Type type,
- Stg_Class_DeleteFunction* _delete,
- Stg_Class_PrintFunction* _print,
- Stg_Class_CopyFunction* _copy,
- Dictionary_AddFunction* add,
+ SizeT _sizeOfSelf,
+ Type type,
+ Stg_Class_DeleteFunction* _delete,
+ Stg_Class_PrintFunction* _print,
+ Stg_Class_CopyFunction* _copy,
+ Dictionary_AddFunction* add,
Dictionary_AddWithSourceFunction* addWithSource,
- Dictionary_SetFunction* set,
+ Dictionary_SetFunction* set,
Dictionary_SetWithSourceFunction* setWithSource,
- Dictionary_GetFunction* get,
- Dictionary_GetSourceFunction* getSource);
-
- /** Initialises a Dictionary. */
- void Dictionary_Init( Dictionary* self );
+ Dictionary_GetFunction* get,
+ Dictionary_GetSourceFunction* getSource);
/** Init interface. */
- void _Dictionary_Init( Dictionary* self );
+ void _Dictionary_Init( void* dictionary );
/** Stg_Class_Delete dictionary implementation */
void _Dictionary_Delete( void* dictionary );
@@ -145,30 +142,28 @@
void Dictionary_Add( void* dictionary, Dictionary_Entry_Key key, Dictionary_Entry_Value* value );
/** Add an entry to the dictionary... orignal implementation... appends keys, with source file */
- void Dictionary_AddWithSource( void* dictionary, Dictionary_Entry_Key key,
- Dictionary_Entry_Value* value, Dictionary_Entry_Source source );
+ void Dictionary_AddWithSource( void* dictionary, Dictionary_Entry_Key key, Dictionary_Entry_Value* value, Dictionary_Entry_Source source );
/** Add an entry to the dictionary... specifying how the entry values are merged if key present already */
Dictionary_Entry_Value* Dictionary_AddMerge(
- void* dictionary,
- Dictionary_Entry_Key key,
- Dictionary_Entry_Value* value,
- Dictionary_MergeType mergeType );
+ void* dictionary,
+ Dictionary_Entry_Key key,
+ Dictionary_Entry_Value* value,
+ Dictionary_MergeType mergeType );
/** Add an entry to the dictionary... specifying how the entry values are merged if key present already */
Dictionary_Entry_Value* Dictionary_AddMergeWithSource(
- void* dictionary,
- Dictionary_Entry_Key key,
- Dictionary_Entry_Value* value,
- Dictionary_MergeType mergeType,
- Dictionary_Entry_Source source );
+ void* dictionary,
+ Dictionary_Entry_Key key,
+ Dictionary_Entry_Value* value,
+ Dictionary_MergeType mergeType,
+ Dictionary_Entry_Source source );
/** Set a value in the dictionary */
Bool Dictionary_Set( void* dictionary, Dictionary_Entry_Key key, Dictionary_Entry_Value* value );
/** Set a value in the dictionary */
- Bool Dictionary_SetWithSource( void* dictionary, Dictionary_Entry_Key key,
- Dictionary_Entry_Value* value, Dictionary_Entry_Source source );
+ Bool Dictionary_SetWithSource( void* dictionary, Dictionary_Entry_Key key, Dictionary_Entry_Value* value, Dictionary_Entry_Source source );
/** Get a value from the dictionary */
Dictionary_Entry_Value* Dictionary_Get( void* dictionary, Dictionary_Entry_Key key );
@@ -182,20 +177,17 @@
/** Get a value from the dictionary */
Dictionary_Entry_Value* Dictionary_GetDefault( void* dictionary, Dictionary_Entry_Key key, Dictionary_Entry_Value* value );
-
/** Add an entry to the dictionary implementation */
void _Dictionary_Add( void* dictionary, Dictionary_Entry_Key key, Dictionary_Entry_Value* value );
/** Add an entry to the dictionary implementation */
- void _Dictionary_AddWithSource( void* dictionary, Dictionary_Entry_Key key,
- Dictionary_Entry_Value* value, Dictionary_Entry_Source source );
+ void _Dictionary_AddWithSource( void* dictionary, Dictionary_Entry_Key key, Dictionary_Entry_Value* value, Dictionary_Entry_Source source );
/** Set a value in the dictionary implementation */
Bool _Dictionary_Set( void* dictionary, Dictionary_Entry_Key key, Dictionary_Entry_Value* value );
/** Set a value in the dictionary implementation */
- Bool _Dictionary_SetWithSource( void* dictionary, Dictionary_Entry_Key key,
- Dictionary_Entry_Value* value, Dictionary_Entry_Source source );
+ Bool _Dictionary_SetWithSource( void* dictionary, Dictionary_Entry_Key key, Dictionary_Entry_Value* value, Dictionary_Entry_Source source );
/** Get a value from the dictionary implementation */
Dictionary_Entry_Value* _Dictionary_Get( void* dictionary, Dictionary_Entry_Key key );
diff -r a472698bbd09 -r b7f878b09d99 Base/IO/tests/DictionarySuite.c
--- a/Base/IO/tests/DictionarySuite.c Thu Nov 19 15:51:21 2009 +1100
+++ b/Base/IO/tests/DictionarySuite.c Mon Nov 23 11:43:25 2009 +1100
@@ -110,22 +110,16 @@ void DictionarySuite_SetupTestDictData(
testStruct = Dictionary_Entry_Value_NewStruct();
Stg_asprintf( &testDD->testKeys[++iter], "test_struct" );
testDD->testValues[iter] = testStruct;
- Dictionary_Entry_Value_AddMember( testStruct, "height",
- Dictionary_Entry_Value_FromDouble( testDD->testStruct->height ) );
- Dictionary_Entry_Value_AddMember( testStruct, "anisotropic",
- Dictionary_Entry_Value_FromBool( testDD->testStruct->anisotropic ) );
- Dictionary_Entry_Value_AddMember( testStruct, "person",
- Dictionary_Entry_Value_FromString( testDD->testStruct->person ) );
+ Dictionary_Entry_Value_AddMember( testStruct, "height", Dictionary_Entry_Value_FromDouble( testDD->testStruct->height ) );
+ Dictionary_Entry_Value_AddMember( testStruct, "anisotropic", Dictionary_Entry_Value_FromBool( testDD->testStruct->anisotropic ) );
+ Dictionary_Entry_Value_AddMember( testStruct, "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, "geom", testStruct2 );
- Dictionary_Entry_Value_AddMember( testStruct2, "startx",
- Dictionary_Entry_Value_FromUnsignedInt( testDD->testStruct->geom.startx ) );
- Dictionary_Entry_Value_AddMember( testStruct2, "starty",
- Dictionary_Entry_Value_FromUnsignedInt( testDD->testStruct->geom.starty ) );
- Dictionary_Entry_Value_AddMember( testStruct2, "startz",
- Dictionary_Entry_Value_FromUnsignedInt( testDD->testStruct->geom.startz ) );
+ Dictionary_Entry_Value_AddMember( testStruct2, "startx", Dictionary_Entry_Value_FromUnsignedInt( testDD->testStruct->geom.startx ) );
+ Dictionary_Entry_Value_AddMember( testStruct2, "starty", Dictionary_Entry_Value_FromUnsignedInt( testDD->testStruct->geom.starty ) );
+ Dictionary_Entry_Value_AddMember( testStruct2, "startz", Dictionary_Entry_Value_FromUnsignedInt( testDD->testStruct->geom.startz ) );
}
void DictionarySuite_Setup( DictionarySuiteData* data ) {
@@ -206,14 +200,12 @@ void DictionarySuite_TestCopyCompare( Di
for( ii = 0; ii < data->dict->count; ii++ ) {
copiedDev = Dictionary_Entry_Value_Copy( data->testDD->testValues[ii], True );
- pcu_check_true( Dictionary_Entry_Value_Compare( data->testDD->testValues[ii],
- copiedDev ) );
+ pcu_check_true( Dictionary_Entry_Value_Compare( data->testDD->testValues[ii], copiedDev ) );
Dictionary_Entry_Value_Delete( copiedDev );
for( jj = 0; jj < data->dict->count; jj++ ) {
if ( ii == jj ) continue;
- pcu_check_true( False == Dictionary_Entry_Value_Compare( data->testDD->testValues[ii],
- data->testDD->testValues[jj] ) );
+ pcu_check_true( False == Dictionary_Entry_Value_Compare( data->testDD->testValues[ii], data->testDD->testValues[jj] ) );
}
}
}
@@ -247,8 +239,7 @@ void DictionarySuite_TestGet( Dictionary
DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD );
testStruct = Dictionary_Get( data->dict, "test_struct" );
- yValue = Dictionary_Entry_Value_GetMember(
- Dictionary_Entry_Value_GetMember(testStruct, "geom"), "starty");
+ yValue = Dictionary_Entry_Value_GetMember( Dictionary_Entry_Value_GetMember(testStruct, "geom"), "starty");
pcu_check_true( data->testDD->testStruct->geom.starty == Dictionary_Entry_Value_AsDouble( yValue ) );
}
@@ -296,8 +287,7 @@ void DictionarySuite_TestAddElement( Dic
/* turning the starty value into a list using add element */
testStruct = Dictionary_Get( data->dict, "test_struct" );
- yValue = Dictionary_Entry_Value_GetMember(
- Dictionary_Entry_Value_GetMember(testStruct, "geom"), "starty");
+ yValue = Dictionary_Entry_Value_GetMember( Dictionary_Entry_Value_GetMember(testStruct, "geom"), "starty");
Dictionary_Entry_Value_AddElement( yValue, Dictionary_Entry_Value_FromDouble(newVal) );
pcu_check_true( Dictionary_Entry_Value_Type_List == yValue->type );
@@ -321,36 +311,24 @@ void DictionarySuite_TestShortcuts( Dict
pcu_check_streq( data->testDD->testString, Dictionary_GetString_WithDefault( data->dict, "test_cstring", "heya" ) );
pcu_check_streq( "heya", Dictionary_GetString_WithDefault( data->dict, "test_cstring2", "heya" ) );
pcu_check_true( NULL != Dictionary_Get( data->dict, "test_cstring2" ) );
- pcu_check_true( data->testDD->testDouble =
- Dictionary_GetDouble_WithDefault( data->dict, "test_double", 2.8 ) );
- pcu_check_true( 2.8 ==
- Dictionary_GetDouble_WithDefault( data->dict, "test_double2", 2.8 ) );
+ pcu_check_true( data->testDD->testDouble = Dictionary_GetDouble_WithDefault( data->dict, "test_double", 2.8 ) );
+ pcu_check_true( 2.8 == Dictionary_GetDouble_WithDefault( data->dict, "test_double2", 2.8 ) );
pcu_check_true( NULL != Dictionary_Get( data->dict, "test_double2" ) );
- pcu_check_true( data->testDD->testUint =
- Dictionary_GetUnsignedInt_WithDefault( data->dict, "test_uint", 33 ) );
- pcu_check_true( 33 ==
- Dictionary_GetUnsignedInt_WithDefault( data->dict, "test_uint2", 33 ) );
+ pcu_check_true( data->testDD->testUint = Dictionary_GetUnsignedInt_WithDefault( data->dict, "test_uint", 33 ) );
+ pcu_check_true( 33 == Dictionary_GetUnsignedInt_WithDefault( data->dict, "test_uint2", 33 ) );
pcu_check_true( NULL != Dictionary_Get( data->dict, "test_uint2" ) );
- pcu_check_true( data->testDD->testInt =
- Dictionary_GetInt_WithDefault( data->dict, "test_int", -24 ) );
- pcu_check_true( -24 ==
- Dictionary_GetInt_WithDefault( data->dict, "test_int2", -24 ) );
+ pcu_check_true( data->testDD->testInt = Dictionary_GetInt_WithDefault( data->dict, "test_int", -24 ) );
+ pcu_check_true( -24 == Dictionary_GetInt_WithDefault( data->dict, "test_int2", -24 ) );
pcu_check_true( NULL != Dictionary_Get( data->dict, "test_int2" ) );
- pcu_check_true( data->testDD->testUnsignedlong =
- Dictionary_GetUnsignedLong_WithDefault( data->dict, "test_unsignedlong", 32433 ) );
- pcu_check_true( 32433 ==
- Dictionary_GetUnsignedLong_WithDefault( data->dict, "test_unsignedlong2", 32433 ) );
+ pcu_check_true( data->testDD->testUnsignedlong = Dictionary_GetUnsignedLong_WithDefault( data->dict, "test_unsignedlong", 32433 ) );
+ pcu_check_true( 32433 == Dictionary_GetUnsignedLong_WithDefault( data->dict, "test_unsignedlong2", 32433 ) );
pcu_check_true( NULL != Dictionary_Get( data->dict, "test_unsignedlong2" ) );
- pcu_check_true( data->testDD->testBool =
- Dictionary_GetBool_WithDefault( data->dict, "test_bool", False ) );
- pcu_check_true( False ==
- Dictionary_GetBool_WithDefault( data->dict, "test_bool2", False ) );
+ pcu_check_true( data->testDD->testBool = Dictionary_GetBool_WithDefault( data->dict, "test_bool", False ) );
+ pcu_check_true( False == Dictionary_GetBool_WithDefault( data->dict, "test_bool2", False ) );
pcu_check_true( NULL != Dictionary_Get( data->dict, "test_bool2" ) );
- pcu_check_streq( data->testDD->testString,
- Dictionary_GetString_WithPrintfDefault( data->dict, "test_cstring", "heya%s%u", "hey", 3 ) );
- pcu_check_streq( "heyahey3",
- Dictionary_GetString_WithPrintfDefault( data->dict, "test_cstring3", "heya%s%u", "hey", 3 ) );
+ pcu_check_streq( data->testDD->testString, Dictionary_GetString_WithPrintfDefault( data->dict, "test_cstring", "heya%s%u", "hey", 3 ) );
+ pcu_check_streq( "heyahey3", Dictionary_GetString_WithPrintfDefault( data->dict, "test_cstring3", "heya%s%u", "hey", 3 ) );
pcu_check_true( NULL != Dictionary_Get( data->dict, "test_cstring3" ) );
}
@@ -362,31 +340,23 @@ void DictionarySuite_TestMerge( Dictiona
Dictionary_Entry_Value* expectedMergedStruct=NULL;
testStruct2 = Dictionary_Entry_Value_NewStruct();
- Dictionary_Entry_Value_AddMember( testStruct2, "height",
- Dictionary_Entry_Value_FromDouble( data->testDD->testStruct->height ) );
- Dictionary_Entry_Value_AddMember( testStruct2, "anisotropic",
- Dictionary_Entry_Value_FromBool( False ) );
- Dictionary_Entry_Value_AddMember( testStruct2, "new_person",
- Dictionary_Entry_Value_FromString( "Luke" ) );
+ Dictionary_Entry_Value_AddMember( testStruct2, "height", Dictionary_Entry_Value_FromDouble( data->testDD->testStruct->height ) );
+ Dictionary_Entry_Value_AddMember( testStruct2, "anisotropic", Dictionary_Entry_Value_FromBool( False ) );
+ Dictionary_Entry_Value_AddMember( testStruct2, "new_person", Dictionary_Entry_Value_FromString( "Luke" ) );
testGeomStruct2 = Dictionary_Entry_Value_NewStruct();
Dictionary_Entry_Value_AddMember( testStruct2, "geom", testGeomStruct2 );
- Dictionary_Entry_Value_AddMember( testGeomStruct2, "startx",
- Dictionary_Entry_Value_FromUnsignedInt( data->testDD->testStruct->geom.startx ) );
- Dictionary_Entry_Value_AddMember( testGeomStruct2, "startz",
- Dictionary_Entry_Value_FromUnsignedInt( 222 ) );
+ Dictionary_Entry_Value_AddMember( testGeomStruct2, "startx", Dictionary_Entry_Value_FromUnsignedInt( data->testDD->testStruct->geom.startx ) );
+ Dictionary_Entry_Value_AddMember( testGeomStruct2, "startz", Dictionary_Entry_Value_FromUnsignedInt( 222 ) );
/* Testing Merge_Append */
DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD );
/* Do a copy of the DEV during merge, since we don't want it being deleted */
- Dictionary_AddMerge( data->dict, "test_struct",
- Dictionary_Entry_Value_Copy( testStruct2, True ), Dictionary_MergeType_Append );
+ Dictionary_AddMerge( data->dict, "test_struct", Dictionary_Entry_Value_Copy( testStruct2, True ), Dictionary_MergeType_Append );
/* OK: since this was an append, we expect _two_ entries called "test_struct",
* one preceding the other, one with the orig data, one with new data */
pcu_check_true( (data->testDD->testEntriesCount+1) == data->dict->count );
- pcu_check_true( Dictionary_Entry_Value_Compare( data->testDD->testValues[7],
- Dictionary_Get( data->dict, "test_struct" ) ) );
- pcu_check_true( Dictionary_Entry_Value_Compare( testStruct2,
- data->dict->entryPtr[8]->value ) );
+ pcu_check_true( Dictionary_Entry_Value_Compare( data->testDD->testValues[7], Dictionary_Get( data->dict, "test_struct" ) ) );
+ pcu_check_true( Dictionary_Entry_Value_Compare( testStruct2, data->dict->entryPtr[8]->value ) );
Dictionary_Empty( data->dict );
/* Testing Merge_Merge */
@@ -395,30 +365,23 @@ void DictionarySuite_TestMerge( Dictiona
/* The nicest way for this test I think is to manually build a merged struct
* to compare against */
expectedMergedStruct = Dictionary_Entry_Value_Copy( data->testDD->testValues[7], True );
- Dictionary_Set( expectedMergedStruct->as.typeStruct, "anisotropic",
- Dictionary_Entry_Value_FromBool( False ) );
- Dictionary_Add( expectedMergedStruct->as.typeStruct, "new_person",
- Dictionary_Entry_Value_FromString( "Luke" ) );
- Dictionary_Set( (Dictionary_Get( expectedMergedStruct->as.typeStruct, "geom" ))->as.typeStruct, "startz",
- Dictionary_Entry_Value_FromUnsignedInt( 222 ) );
+ Dictionary_Set( expectedMergedStruct->as.typeStruct, "anisotropic", Dictionary_Entry_Value_FromBool( False ) );
+ Dictionary_Add( expectedMergedStruct->as.typeStruct, "new_person", Dictionary_Entry_Value_FromString( "Luke" ) );
+ Dictionary_Set( (Dictionary_Get( expectedMergedStruct->as.typeStruct, "geom" ))->as.typeStruct, "startz", Dictionary_Entry_Value_FromUnsignedInt( 222 ) );
- Dictionary_AddMerge( data->dict, "test_struct",
- Dictionary_Entry_Value_Copy( testStruct2, True ), Dictionary_MergeType_Merge );
+ Dictionary_AddMerge( data->dict, "test_struct", Dictionary_Entry_Value_Copy( testStruct2, True ), Dictionary_MergeType_Merge );
/* This time, the new struct should be merged into the existing one */
pcu_check_true( data->testDD->testEntriesCount == data->dict->count );
mergedStruct = Dictionary_Get( data->dict, "test_struct" );
- pcu_check_true( Dictionary_Entry_Value_Compare( mergedStruct,
- expectedMergedStruct ) );
+ pcu_check_true( Dictionary_Entry_Value_Compare( mergedStruct, expectedMergedStruct ) );
Dictionary_Empty( data->dict );
Dictionary_Entry_Value_Delete( expectedMergedStruct );
/* Testing Merge_Replace */
DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD );
- Dictionary_AddMerge( data->dict, "test_struct",
- Dictionary_Entry_Value_Copy( testStruct2, True ), Dictionary_MergeType_Replace );
+ Dictionary_AddMerge( data->dict, "test_struct", Dictionary_Entry_Value_Copy( testStruct2, True ), Dictionary_MergeType_Replace );
pcu_check_true( data->testDD->testEntriesCount == data->dict->count );
- pcu_check_true( Dictionary_Entry_Value_Compare( testStruct2,
- Dictionary_Get( data->dict, "test_struct" ) ) );
+ pcu_check_true( Dictionary_Entry_Value_Compare( testStruct2, Dictionary_Get( data->dict, "test_struct" ) ) );
Dictionary_Empty( data->dict );
Dictionary_Entry_Value_Delete( testStruct2 );
@@ -448,72 +411,60 @@ void DictionarySuite_TestReadAllParamFro
Stg_asprintf( &argv[2], "--option");
Stg_asprintf( &argv[3], "--output-dir=");
Stg_asprintf( &expectedKeys[0], "output-dir" );
+
expectedVals[0] = Dictionary_Entry_Value_FromString( "" );
Stg_asprintf( &argv[4], "--Ra=1.0e4");
Stg_asprintf( &expectedKeys[1], "Ra" );
+
expectedVals[1] = Dictionary_Entry_Value_FromDouble( 1.0e4 );
Stg_asprintf( &argv[5], "--foo.bar=5");
Stg_asprintf( &expectedKeys[2], "foo" );
+
expectedVals[2] = Dictionary_Entry_Value_NewStruct();
- Dictionary_Entry_Value_AddMember( expectedVals[2], "bar",
- Dictionary_Entry_Value_FromDouble( 5 ) );
+ Dictionary_Entry_Value_AddMember( expectedVals[2], "bar", Dictionary_Entry_Value_FromDouble( 5 ) );
Stg_asprintf( &argv[6], "--vpac.csd.steve=cool");
Stg_asprintf( &expectedKeys[3], "vpac" );
+
expectedVals[3] = Dictionary_Entry_Value_NewStruct();
- Dictionary_Entry_Value_AddMember( expectedVals[3], "csd",
- tmpStruct = Dictionary_Entry_Value_NewStruct() );
- Dictionary_Entry_Value_AddMember( tmpStruct, "steve",
- Dictionary_Entry_Value_FromString( "cool" ) );
+ Dictionary_Entry_Value_AddMember( expectedVals[3], "csd", tmpStruct = Dictionary_Entry_Value_NewStruct() );
+ Dictionary_Entry_Value_AddMember( tmpStruct, "steve", Dictionary_Entry_Value_FromString( "cool" ) );
Stg_asprintf( &argv[7], "--foo.bot=7");
- Dictionary_Entry_Value_AddMember( expectedVals[2], "bot",
- Dictionary_Entry_Value_FromDouble( 7 ) );
+ Dictionary_Entry_Value_AddMember( expectedVals[2], "bot", Dictionary_Entry_Value_FromDouble( 7 ) );
Stg_asprintf( &argv[8], "--sports[]=hockey");
Stg_asprintf( &expectedKeys[4], "sports" );
+
expectedVals[4] = Dictionary_Entry_Value_NewList();
- Dictionary_Entry_Value_AddElement( expectedVals[4],
- Dictionary_Entry_Value_FromString( "hockey" ) );
+ Dictionary_Entry_Value_AddElement( expectedVals[4], Dictionary_Entry_Value_FromString( "hockey" ) );
Stg_asprintf( &argv[9], "--sports[]=chess");
/* This should be overwritten by next entry, so ignore */
Stg_asprintf( &argv[10], "--sports[1]=tennis");
- Dictionary_Entry_Value_AddElement( expectedVals[4],
- Dictionary_Entry_Value_FromString( "tennis" ) );
+ Dictionary_Entry_Value_AddElement( expectedVals[4], Dictionary_Entry_Value_FromString( "tennis" ) );
Stg_asprintf( &argv[11], "--sles[].name=pressure");
Stg_asprintf( &expectedKeys[5], "sles" );
+
expectedVals[5] = Dictionary_Entry_Value_NewList();
- Dictionary_Entry_Value_AddElement( expectedVals[5],
- tmpStruct = Dictionary_Entry_Value_NewStruct() );
- Dictionary_Entry_Value_AddMember( tmpStruct, "name",
- Dictionary_Entry_Value_FromString( "pressure" ) );
+ Dictionary_Entry_Value_AddElement( expectedVals[5], tmpStruct = Dictionary_Entry_Value_NewStruct() );
+ Dictionary_Entry_Value_AddMember( tmpStruct, "name", Dictionary_Entry_Value_FromString( "pressure" ) );
Stg_asprintf( &argv[12], "--sles[].name=temperature");
- Dictionary_Entry_Value_AddElement( expectedVals[5],
- tmpStruct2 = Dictionary_Entry_Value_NewStruct() );
- Dictionary_Entry_Value_AddMember( tmpStruct2, "name",
- Dictionary_Entry_Value_FromString( "temperature" ) );
+ Dictionary_Entry_Value_AddElement( expectedVals[5], tmpStruct2 = Dictionary_Entry_Value_NewStruct() );
+ Dictionary_Entry_Value_AddMember( tmpStruct2, "name", Dictionary_Entry_Value_FromString( "temperature" ) );
Stg_asprintf( &argv[13], "--sles[0].solver=mg");
- Dictionary_Entry_Value_AddMember( tmpStruct, "solver",
- Dictionary_Entry_Value_FromString( "mg" ) );
+ Dictionary_Entry_Value_AddMember( tmpStruct, "solver", Dictionary_Entry_Value_FromString( "mg" ) );
Stg_asprintf( &argv[14], "--sles[1].solver=direct");
- Dictionary_Entry_Value_AddMember( tmpStruct2, "solver",
- Dictionary_Entry_Value_FromString( "direct" ) );
+ Dictionary_Entry_Value_AddMember( tmpStruct2, "solver", Dictionary_Entry_Value_FromString( "direct" ) );
Stg_asprintf( &argv[15], "--some.crazy[].shit=here");
Stg_asprintf( &expectedKeys[6], "some" );
+
expectedVals[6] = Dictionary_Entry_Value_NewStruct();
- Dictionary_Entry_Value_AddMember( expectedVals[6], "crazy",
- tmpList = Dictionary_Entry_Value_NewList() );
- Dictionary_Entry_Value_AddElement( tmpList,
- tmpStruct = Dictionary_Entry_Value_NewStruct() );
- Dictionary_Entry_Value_AddMember( tmpStruct, "shit",
- Dictionary_Entry_Value_FromString( "here" ) );
+ Dictionary_Entry_Value_AddMember( expectedVals[6], "crazy", tmpList = Dictionary_Entry_Value_NewList() );
+ Dictionary_Entry_Value_AddElement( tmpList, tmpStruct = Dictionary_Entry_Value_NewStruct() );
+ Dictionary_Entry_Value_AddMember( tmpStruct, "shit", Dictionary_Entry_Value_FromString( "here" ) );
Dictionary_ReadAllParamFromCommandLine( data->dict, argc, argv );
for (ii=0; ii < numExp; ii++) {
- pcu_check_true( Dictionary_Entry_Compare(
- data->dict->entryPtr[ii],
- expectedKeys[ii]));
- pcu_check_true( Dictionary_Entry_Value_Compare(
- expectedVals[ii],
- data->dict->entryPtr[ii]->value ));
+ pcu_check_true( Dictionary_Entry_Compare( data->dict->entryPtr[ii], expectedKeys[ii]));
+ pcu_check_true( Dictionary_Entry_Value_Compare( expectedVals[ii], data->dict->entryPtr[ii]->value ));
}
for (ii=0; ii < argc; ii++) {
diff -r a472698bbd09 -r b7f878b09d99 src/main.c
--- a/src/main.c Thu Nov 19 15:51:21 2009 +1100
+++ b/src/main.c Mon Nov 23 11:43:25 2009 +1100
@@ -143,19 +143,19 @@ static void printRightsListItem( Stream*
int main( int argc, char* argv[] ) {
/* StGermain standard bits & pieces */
- MPI_Comm CommWorld;
- int rank;
- int numProcessors;
- Dictionary* dictionary;
+ MPI_Comm CommWorld;
+ int rank;
+ int numProcessors;
+ Dictionary* dictionary;
XML_IO_Handler* ioHandler;
- Stream* stream;
- char* helpTopic;
- char* listAllTopic;
- Stg_ObjectList* listAllTopics;
- char* listTopic;
- Stg_ObjectList* listTopics;
- Dictionary* componentDict;
- Stg_ComponentFactory* cf;
+ Stream* stream;
+ char* helpTopic;
+ char* listAllTopic;
+ Stg_ObjectList* listAllTopics;
+ char* listTopic;
+ Stg_ObjectList* listTopics;
+ Dictionary* componentDict;
+ Stg_ComponentFactory* cf;
/* Initialise PETSc, get world info */
MPI_Init( &argc, &argv );
@@ -291,7 +291,6 @@ int main( int argc, char* argv[] ) {
/* Close off everything */
Stg_Class_Delete( listAllTopics );
Stg_Class_Delete( listTopics );
- Stg_Class_Delete( dictionary );
#ifdef HAVE_PYTHON
Py_Finalize();
#endif
More information about the CIG-COMMITS
mailing list