Classes and repositories are global and persist for runtime duration. So in all cases, implimentation of the HDB in an program begins with declaring one or more data classes in the global space. Then repositories that will store objects of the data classes are declared in the global space. Then before using a data object of any given class, a 'working' object to ferry data in and out of the applicable repository, is required. These do not nessesarily need to be decalared as global but are generally done so for efficiency reasons. So our declaration block would be something like this:-
<pre> hzClass myClass ; // The data class hdbObjRepos myRepos ; // Repository for the data class hzObject myObject ; // An working instance of the data class </pre>
And then in the initialization part of the program, we first initialize the data class(es). For each data class there is a three part initialization sequence begining with a single call to hzClass::InitStart, a series of calls to hzClass::InitMember (one call per member) and ending with a single call to hzClass::InitDone.
<pre> myClass.InitStart() ; myClass.InitMember(member1_name, member1_type, popCtl) ; myClass.InitMember(member2_name, member2_type, popCtl) ; myDataClass.InitDone() ; </pre>
Next we set up the repository which has a similar three part initialization sequence only this time the repository InitStart function requires an initialized hzClass and instead of adding members we are adding indexes via a call to AddIndex(). like this:-
<pre> myRepos.InitStart(myDataClass) ; myRepos.AddIndex(member_name, true/false) ; myRepos.InitDone() ; </pre>
Note that AddIndex() has a flag. This is to state if the member must be unique or not. If it is then there may only be one object with a member of any given value. Note also that if this member has previously been added to the data class as multiple (maxPop not 1) then this flag being true generates an error.
Initialization of the working object is just a one step init as follows:-
myObject.Init(myClass) ;
You now have a native HadronZoo database in operation! You can insert, delete and retrieve data using myObject follows:-
<pre> myObject.Clear() ; myObject.SetValue(member_name, value) ; .. more set value calls myRepos.Insert(&myObject) ; </pre>
To retrieve, delete or modify an object you will need the object_id that the repository assigns to the object on Insert() - and the only way of keeping track of ids is to have the indexes do it for you (see below)
<pre> myRepos.Delete(objId) ; myRepos.Update(&myObject, objId) ; myRepos.Fetch(&myObject, objId) ; </pre>
The fetch operation will assemble the whole object into myObject. And if you are using hdbObjStore that would be all you could do. But you often don't need the whole object and if you are using hdbObjCache (because it is memory resident) you can instead just fetch the value of a given member like this:-
<pre> hzAtom myVal ;
myRepos.Fetchval(myVal, member_name, objId) ; </pre>