Once the object referred to by a reference is deleted, use of the reference accesses arbitrary data and might cause a segmentation violation.
The class os_Reference_this_DB is parameterized, with a parameter for indicating the type of the object referred to by a reference. This means that when specifying os_Reference_this_DB as a function's formal parameter, or as the type of a variable or data member, you must specify the parameter - the reference's referent type. You do this by appending to os_Reference_this_DB the name of the referent type enclosed in angle brackets (< >):
os_Reference_this_DB<referent-type-name>The referent type must be a class. For references to built-in types, such as int and char, see os_reference_this_DB.
The referent type parameter, T, occurs in the signatures of some of the functions described below. The parameter is used by the compiler to detect type errors.
part *a_part = ... ; os_Reference_this_DB<part> part_ref = a_part;When an os_Reference_this_DB<T*> is used where a T* is expected, os_Reference_this_DB::operator ->() or os_Reference_this_DB::operator T*() is implicitly invoked, returning a valid pointer to the object referred to by the os_Reference_this_DB.
printf("%d\n", part_ref->part_id);Not all C++ operators have special reference class overloadings. References do not behave like pointers in the context of [] and ++, for example.
In some cases involving multiple inheritance, comparing two references has a different result from comparing the corresponding pointers. For example, for == comparisons, if the referent type of one operand is a nonleftmost base class of the referent type of the other operand, the result is always 1. This is because comparing references never results in the pointer adjustment described in Section 10.3c of the C++ Annotated Reference Manual.
The types os_int32 and os_boolean, used throughout this manual, are each defined as a signed 32-bit integer type. The type os_unsigned_int32 is defined as an unsigned 32-bit integer type.
All ObjectStore programs must include the header file <ostore/ostore.hh>.
char* dump(const char* db_str) const;Returns a heap-allocated string for the reference that the method was called. However, unlike the string returned by the char* os_Reference_this_DB::dump(void) method, the returned string does not contain an absolute database pathname. The returned string is intended for use as the dump_str parameter of an os_Reference_this_DB load method of the form load(const char* dump_str, os_database* db). It is the responsibility of the caller of load to ensure that the db parameter passed to the load method is the same as the database of the dumped reference. It is the user's responsibility to delete the returned string when finished using the string.
This operation is useful in those applications in which you do not want the overhead of storing the absolute database path in the dumped strings.
os_database *get_database() const;Returns a pointer to the database containing the object referred to by the specified reference.
char* get_database_key(const char* dump_str);Returns a heap-allocated string containing the database_key component of the string dump_str. dump_str must have been generated using the dump operation. Otherwise, the exception err_reference_syntax is raised. It is the user's responsibility to delete the returned string when finished using the string.
static os_typespec *get_os_typespec();Returns an os_typespec* for the class os_Reference_this_DB.
os_unsigned_int32 hash() const;Returns an integer suitable for use as a hash table key. The value returned is always the same for a reference to a given referent.
void load(const char* dump_str, const os_database* db);The dump_str parameter is assumed to be the result of a call to a compatible os_Reference dump method. It is the responsibility of the caller of load to ensure that the db parameter passed to the load method is the same as the database of the originally dumped reference. The loaded reference refers to the same object as the os_Reference used to dump the string as long as the db parameter is the same as the database of the dumped reference. The exception err_reference_syntax is raised if the dump_str is not in the expected format.
operator T*() const;Returns the valid T* for which the specified reference is a substitute.
T* operator ->() const;Returns the valid T* for which the specified reference is a substitute.
os_Reference_this_DB<T> &operator=(Establishes the referent of the right operand as the referent of the left operand.
const os_Reference_this_DB<T>&
);
os_Reference_this_DB<T> &operator=(const T*);Establishes the object pointed to by the right operand as the referent of the left operand.
os_boolean operator ==(os_Reference_this_DB const&) const;Returns 1 if the arguments have the same referent; returns 0 otherwise.
os_boolean operator !=(os_Reference_this_DB const&) const;Returns 1 if the arguments have different referents; returns 0 otherwise.
os_boolean operator <(os_Reference_this_DB const&) const;If the first argument and second argument refer to elements of the same array or one beyond the end of the array, a return value of 1 indicates that the referent of the first argument precedes the referent of the second, and a return value of 0 indicates that it does not. Otherwise the results are undefined.
os_boolean operator >(os_Reference_this_DB const&) const;If the first argument and second argument refer to elements of the same array or one beyond the end of the array, a return value of 1 indicates that the referent of the first argument follows the referent of the second, and a return value of 0 indicates that it does not. Otherwise the results are undefined.
os_boolean operator >=(os_Reference_this_DB const&) const;If the first argument and second argument refer to elements of the same array or one beyond the end of the array, a return value of 1 indicates that the referent of the first argument follows or is the same as the referent of the second, and a return value of 0 indicates that it does not. Otherwise the results are undefined.
os_boolean operator <=(os_Reference_this_DB const&) const;If the first argument and second argument refer to elements of the same array or one beyond the end of the array, a return value of 1 indicates that the referent of the first argument precedes or is the same as the referent of the second, and a return value of 0 indicates that it does not. Otherwise the results are undefined.
os_Reference_this_DB(T*);Constructs a reference to substitute for the specified T*.
T *resolve() const;Returns the valid T* for which the specified reference is a substitute.
Updated: 03/31/98 17:25:09