Defined in file: hzDatabase.h
hdbObject is a single data object container. Once a hdbObject instance has been initialized to a data class, it can hold a single object of that class. hdbObject is central to the data object repository program interface. In repository FETCH operations, hdbObject acts as a data object recepticle. In INSERT and MODIFY operations, hdbObject acts as the data object donor. The hdbObject GET value and SET value functions can only be applied to ATOMIC members of the class to which the hdbObject instance is initialized. Where a data class member introduces a subclass, the only way to access a subclass object and address its members, is via a separate hdbObject instance that is initialized to the subclass. Subclass objects are fetched by calling FetchObject() on the applicable host class member. Modified subclass objects are returned to the host class member by calling UpdateObject() on the same host class member. Entirely new subclass objects are calling AddObject() on the applicable host class member. Data objects members can be:- 1) A single BOOL or TBOOL 2) A single numeric value or a pointer to an array of numeric values 3) A single string value or a pointer to an array of string values 4) A single ENUM value OR a set of ENUM values encoded as a bitmap. 5) A single binary datum address OR a pointer into a hzChain that hold the actual binary datum. 6) A single subclass object address or a pointer to an array of subclass object addresses (see note). Within hdbObject members are assigned a slot in a uchar buffer (m_pCore), either to store a single value, or the address of the first value in a list of values. The size of the slot depends on the member data type and whether the member can have multiple values. Please note the following:- - BOOL and TBOOL members are always single value as they represent attributes the host class object either does, or does not have. Both are assigned a single core byte. - Numeric members are not usually configured to accept multiple values but it is permitted for 32 and 64-bit signed and unsigned numbers, and for doubles. In the single value case, numeric members are assigned core slots of their data size (8, 4, 2 or 1 bytes). In the multiple value case, a 4-byte aligned core slot is assigned to hold the address of the first value in the list. - STRING and string-like members are 32-bit entities whose values are stored within hdbObject by casting a 4-byte space, aligned to a 4-byte boundary, to the applicable C++ class (e.g. hzString). In all cases however, 4 bytes are assigned in the core, as both the value space (single value), and the address (multiple value), are 4-bytes in size. - ENUM members are given a 1 byte slot if only one value is allowed (max pop of ENUM data type 256), and 4 bytes if multiple values are allowed. As stated above, if the ENUM population is <= 32, the ENUM is stored as a 4-byte bitmap, otherwise the 4-byte value is the string address of an ecoded idset. - BINARY members are always single value. As binary datum cannot be indexed, BINARY members must be part of a class (or subclass), that has at least one member that can be indexed, in order for the binary datum to be found. BINARY members are assigned two core slots. An 8-byte aligned slot which is cast to a hzChain to hold the value, and a 4-byte aligned slot to hold the datum id, that the chain content either already does or will have in the binary datum repository. - Subclass members are always multiple as there would be no point to them if they were limited to a single subclass instance. Members can hold a lone subclass object or even be empty, but they cannot be limited to a single subclass object. Subclass members are assigned 4-byte aligned core slots, being the address of the first subclass object in the list. Slots are assigned in decending order of size, with 16 byte slots (type DIGEST) first, followed by 8-byte slots, then 4, then 2, then 1. This ensures the 8 and 4 byte slots are aligned to 8 and 4 byte boundaries. This is particularly critical for string and string-like members, as the slots are cast to hzString or other C++ string like class. Writing code to move data between data objects and program variables requires knowledge of the data class and its members, as is the case with all forms of structured data. hdbObject has various 'Get and Set' member functions which are overloaded to cover the whole set of HadronZoo data types. These expect a reference to a program variable and a member pointer. The compiler will not be able to check for type mismatches between program variables and member, so these functions return E_TYPE in this event. There is also a generic Get and Set which works with atoms, but these likewise cannot be type checked by the compiler. Get array and Set array functions are not currently provided but are being considered for applicable data types. Calling Set() on BINARY and TXTDOC members, sets the member to the actual binary datum supplied in the hzChain. However, when hdbObject is populated by a repository FETCH, only the binary datum id is loaded. This avoids expensive seek operations for binary datum that are quite often not needed by the task in hand. Calling Get() on the member explicitly, will pull the binary datum from the binary datum repository - providing there has been an initial FETCH on a data object repository. Data objects can be transmitted between services as JSON objects (the industry standard method). Within data object repositories, data objects are manifest as EDOs (encoded data objects). hdbObject has import/export methods for both formats. JSON and EDO formats are descrbed in the synopsis "Data Encoding". Note that hdbObject is often initialized to a data object repository, from which the data class can be inferred. This is necessary if the hdbObject is to be used to extract or to insert binary datum from/to BINARY or TXTDOC members, but not otherwise.
Constructors/Detructors
| hdbObject* | hdbObject | (hdbObject&) | |
| hdbObject* | hdbObject | (void) | |
| NULL-TYPE | hdbObject | (void) | |
| void | ~hdbObject | (void) | |
| NULL-TYPE | ~hdbObject | (void) |
Public Methods:
| hdbClass* | Class | (void) | |
| const char* | Classname | (void) | |
| hzEcode | Clear | (void) | Clear all hdbObject values Arguments: None |
| hzEcode | CommitBinaries | (hdbBinRepos* pRepos) | Commit all binary member values in this, and any subclass objects, to the supplied binary datum repository. It is expected that the binary datum repository will that of the data object repository, this object is to be placed in (either in an INSERT or UPDATE operation). With binary members the litmus bit is only set by SetBinary(), which places a binary datum (presumed to be a new binary datum), in the member's core space. It is not set by retrieving the binary from a binary datum repository. In other words, the litmus bit is set if there is a new value, and not otherwise. This function checks the litmus bit before committing the datum to the target binary datum repository. Once the commit is done, the address (binary datum id), is placed in the in member's aux core space, from where it is used in the export of deltas and EDOs. |
| hzEcode | ExportDelta | (hzChain& Z) | Write out whole form delta |
| hzEcode | ExportEDO | (hzChain& E) | Export an EDO tail, which is part of the EDO commit sequence. This begins with the litmus bits and follows with the member data. There is no length indicator at this point. Note that this function does not clear the supplied chain. It simply appends the chain with the EDO of this object. |
| hzEcode | ExportJSON | (hzChain& J) | Export the hdbObject value as a JSON |
| hzEcode | GetBinary | (hzChain& Z)hdbMember* pMbr, | Place the actual binary datum member value into the supplied chain. This requires the object container to name a source repository. |
| hzEcode | GetBool | (bool& result)hdbMember* pMbr, | Get boolean member within data object. The object must be initialized to a data class, and the supplied member must exist within that class and be of datatype BOOL or TBOOL |
| hzEcode | GetMbrValue | (hzMD5& md5)hdbMember* pMbr, | Set the supplied string with the value of the supplied member |
| hzEcode | GetMbrValue | (hzString& str)hdbMember* pMbr, | Set the supplied string with the value of the supplied member |
| hzEcode | GetMbrValue | (hzDomain& dom)hdbMember* pMbr, | Set the supplied string with the value of the supplied member |
| hzEcode | GetMbrValue | (hzEmaddr& ema)hdbMember* pMbr, | Set the supplied string with the value of the supplied member |
| hzEcode | GetMbrValue | (hzUrl& url)hdbMember* pMbr, | Set the supplied URL with the value of the supplied member |
| hzEcode | GetMbrValue | (hzIpaddr& ipa)hdbMember* pMbr, | Set the supplied string with the value of the supplied member |
| hzEcode | GetMbrValue | (hzXDate& xdate)hdbMember* pMbr, | Set the supplied string with the value of the supplied member |
| hzEcode | GetMbrValue | (hzSDate& sdate)hdbMember* pMbr, | Set the supplied string with the value of the supplied member |
| hzEcode | GetMbrValue | (hzTime& time)hdbMember* pMbr, | Set the supplied string with the value of the supplied member |
| hzEcode | GetMbrValue | (uint64_t& val)hdbMember* pMbr, | |
| hzEcode | GetMbrValue | (uint32_t& val)hdbMember* pMbr, | Set the supplied string with the value of the supplied member |
| uint32_t | GetObjId | (void) | Get the object id. |
| hzEcode | GetObject | (hdbObject& sub)hdbMember* pMbr, uint32_t nOset, | Fetches a subclass object from the applicable member of this (host class) object. The supplied hdbObject (previously initialized to the subclass), is first cleared leaving its m_pRoot pointer as NULL. m_pRoot is then set to the fetched _obj_data, raising the copy count. |
| hzEcode | GetValue | (hzAtom& atom)hdbMember* pMbr, uint32_t nOset, | Set the supplied atom with the value of the supplied member. Note that for BINARY/TXTDOC members, the atom is set with the binary datum id, not the binary datum value. |
| hzEcode | ImportDelta | (hzChain& Z) | Populate object by reading in a whole object delta |
| hzEcode | ImportEDO | (hzChain& Z) | Populate the hdbObject with the supplied hzChain content, which must be an EDO. This function is strictly for the purposes of LOADING from a hdbObjRepos cache. Please note the following:- a) In the case of STRING and string-like datum, the string space address is copied from the EDO but then the member core space is cast to the applicable class in order to keep proper track of the string space copy count. b) For BINARY and TXTDOC members, the binary datum address appears in the EDO and is copied to the aux, rather than the core space. The core space only comes into play when the binary is fetched, at which point the core space is cast to a hzChain (in order to keep track of the copy count). c) For single selection ENUM members, the core space is 1 byte. For multiple selection ENUM members, the core space is however many bytes are needed to hold the bitmap covering the entire ENUM population. In the latter case, the EDO entry for the member will have a length indicator (1 byte), followed by an idset encoding. d) For subclass members, the EDO will either contain the address of the subclass objects or a list of EDOs representing the actual subclass objects - depending on the repository configuration. By default repositories do not store data objects, be those of the host native data class, or of any subclass. |
| hzEcode | ImportJSON | (hzChain& J) | Import the hdbObject value as a JSON. Note that the JSON must be compatible with the native data class. |
| hzEcode | Init | (hdbClass* pClass) | Initialize a single object container Single object containers are assigned a data class (the operational native), and a name. The name was added so that hdbObject instances in Dissemino user sessions could be referenced by form handler commands. |
| hzEcode | Init | (hdbObjRepos* pRepos) | Initialize a single object container to a repository and thus a data class |
| hzEcode | Integrity | (void) | Check integrity Arguments: None |
| hdbObject* | Node | (uint32_t nIndex) | |
| hzString | ObjKey | (void) | |
| uint32_t | ReposId | (void) | |
| hzEcode | SetBinary | (hdbMember* pMbr)hzChain& Z, | Set binary member value within data object. The object must be initialized to a data class, and the supplied member must exist within that class and be of a BINARY datatype. This function will copy the supplied chain to the core entry of the applicable member, and sets the member litmus byte to LITMUS_SET to state that the member has a new value. The chain is NOT committed to the target binary repository at this juncture. This will only happen when the onject as a whole is committed to the applicable data object repository, in either an INSERT or an UPDATE operation. Note that BINARY members have an aux core entry in addition to the standard core entry. The aux is used to store the datum id of the chain. This is only set on a FETCH. In a new object, the aux is 0. In an existing object, the aux will contain the datim id that was previously assigned. On UPDATE, if the chain has changed, the datum id in the aux is used to DELETE the previous datum. |
| hzEcode | SetBool | (hdbMember* pMbr)bool bValue, | Set boolean member within data object. The object must be initialized to a data class, and the supplied member must exist within that class and be of datatype BOOL or TBOOL |
| hzEcode | SetMbrValue | (hdbMember* pMbr)hzMD5& md5, | Set value of the supplied member in the object, with the supplied string |
| hzEcode | SetMbrValue | (hdbMember* pMbr)hzString& str, | Set value of the supplied member in the object, with the supplied string |
| hzEcode | SetMbrValue | (hdbMember* pMbr)hzDomain& dom, | Set value of the supplied member in the object, with the supplied domain |
| hzEcode | SetMbrValue | (hdbMember* pMbr)hzEmaddr& ema, | Set the supplied string with the value of the supplied member |
| hzEcode | SetMbrValue | (hdbMember* pMbr)hzUrl& url, | Set the supplied string with the value of the supplied member |
| hzEcode | SetMbrValue | (hdbMember* pMbr)hzIpaddr& ipa, | |
| hzEcode | SetMbrValue | (hdbMember* pMbr)hzXDate& xd, | Set the supplied string with the value of the supplied member |
| hzEcode | SetMbrValue | (hdbMember* pMbr)hzSDate& sd, | Set the supplied string with the value of the supplied member |
| hzEcode | SetMbrValue | (hdbMember* pMbr)hzTime& time, | Set the supplied string with the value of the supplied member |
| hzEcode | SetMbrValue | (hdbMember* pMbr)uint64_t val, | |
| hzEcode | SetMbrValue | (hdbMember* pMbr)int64_t val, | |
| hzEcode | SetMbrValue | (hdbMember* pMbr)uint32_t val, | |
| hzEcode | SetMbrValue | (hdbMember* pMbr)int32_t val, | |
| hzEcode | SetName | (hzString& objKey) | Set single object container name if required. |
| void | SetObjId | (uint32_t nObjId) | Set the object id. This is upon FETCH of a data object from a repository. Returns: None |
| hzEcode | SetObject | (hdbMember* pMbr)hdbObject& sub, | Either add a new subclass data object or return a modified subclass data object, to the supplied host class member. In the case of a new subclass data object, the object id will be zero. In the case of a modified subclass data object, this must necessarily have been fetched, so will have the object id it was given when originally added. This object must be initialized to the host data class and the supplied data object must be initialized to subclass introduced by the applicable host class member. |
| hzEcode | SetRepos | (hdbObjRepos* pRepos) | Set single object container name if required. |
| hzEcode | SetValue | (hdbMember* pMbr)hzAtom& atom, | Set member value within data object. The object must be initialized to a data class, and the supplied member must exist within that class |
| hzEcode | _export_json_r | (hzChain& json)hdbClass* pClass, uint32_t nLevel, | Recursive JSON export by class. This function writes out the opening '{', member values in the first level of the applicable data object, then the closing '}'. Member values are written in order of member position within the applicable data class. Recursion is used to export subclass objects. All atomic values are written out in full text form except BINARY and TXTDOC, which are written as Base64. |
Overloaded operators:
| hdbObject& | operator= | (hdbObject&) |
Member Variables:
| uint16_t | m_ClassId | Host class delta id | |
| hzString | m_Key | Unique name within app | |
| uint16_t | m_ReposId | Repository id | |
| uint32_t | m_Resv | Reserved | |
| hdbClass* | m_pClass | Object class | |
| hdbObjRepos* | m_pRepos | Associated data object repository | |
| _obj_data* | m_pRoot | Internal object data |