ObjectStore C++ API Reference

os_reference_protected

Instances of the class os_reference_protected can be used as substitutes for cross-database and cross-transaction pointers. References are valid under a wider array of circumstances than are pointers to persistent storage.

A pointer to persistent storage assigned to transient memory is valid only until the end of the outermost transaction in which the assignment occurred, unless objectstore::retain_persistent_addresses() is used. In addition, a pointer to storage in one database assigned to storage in another database is valid only until the end of the outermost transaction in which the assignment occurred, unless os_database::allow_external_pointers() or os_segment::allow_external_pointers() is used.

os_reference_protecteds, in contrast, are always valid across transaction boundaries, as well as across databases.

Once the object referred to by an os_reference_protected is deleted, use of the os_reference_protected causes an err_reference_not_found exception to be signaled. If the referent database has been deleted, err_database_not_found is signaled.

You can create a reference to serve as substitute for a pointer by initializing a variable of type os_reference_protected with the pointer, or by assigning the pointer to a variable of type os_reference_protected (implicitly invoking the conversion constructor os_reference_protected::os_reference_protected(void*)). This pointer must not point to transient memory. In general, a pointer can be used anywhere an os_reference_protected is expected, and the conversion constructor will be invoked.

      part *a_part = ... ;
      os_reference_protected part_ref = a_part;
When an os_reference_protected is cast to pointer-to-referent-type (that is, pointer to the type of object referred to by the reference), os_reference_protected::operator void*() is implicitly invoked, returning a valid pointer to the object referred to by the os_reference_protected.

      printf("%d\n", (part*)(part_ref)->part_id);
Each instance of this class stores a relative pathname to identify the referent database. The pathname is relative to the lowest common directory in the pathnames of the referent database and the database containing the reference. For example, if a reference stored in /A/B/C/db1 refers to data in /A/B/D/db2, the lowest common directory is A/B, so the relative pathname ../../D/db2 is used.

This means that if you copy a database containing a reference, the reference in the copy and the reference in the original might refer to different databases. To change the database a reference refers to, you can use the ObjectStore utility oschangedbref. See ObjectStore Management.

Using memcpy() with persistent
os_reference_protecteds
You can use the C++ memcpy() function to copy a persistent os_reference_protected only if the target object is in the same segment as the source object. This is because all persistent objects of the type os_reference_protected use os_segment::of(this) for reference resolution processing and the resoultion will be incorrect if the os_reference has been copied to a different segment.

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>.

os_reference_protected::deleted()

os_boolean deleted() const;
Returns 1 (true) if the object to which the specified reference refers has been deleted; returns 0 (false) otherwise.

os_reference_protected::dump()

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_protected::dump(void) method, the returned string does not contain an absolute database pathname. The returned string is intended to be used as the dump_str parameter of an os_Reference_protected 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_reference_protected::forget()

void forget();
Frees the memory in the underlying table used to associate the specified reference with its referent. Subsequent use of the os_reference_protected will result in a run-time error.

os_reference_protected::get_database()

os_database *get_database() const;
Returns a pointer to the database containing the object referred to by the specified reference.

os_reference_protected::get_database_key();

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.

os_reference_protected::get_open_database()

os_database *get_open_database() const;
Returns a pointer to the database containing the object referred to by the specified os_reference_protected. Opens the database.

os_reference_protected::get_os_typespec()

static os_typespec *get_os_typespec();
Returns an os_typespec* for the class os_reference_protected.

os_reference_protected::hash()

os_unsigned_int32 hash() const;
Returns an integer suitable for use as a hash table key. The value returned is always the same for an os_reference_protected to a given referent.

os_reference_protected::load()

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 or if the dump_str was dumped from a nonprotected reference.

os_reference_protected::operator void*()

operator void*() const;
Returns the valid pointer for which the specified reference is a substitute. If the referent has been deleted, err_reference_not_found is signaled. If the referent database has been deleted, err_database_not_found is signaled.

os_reference_protected::operator =()

                                                         os_reference_protected &operator=(const os_reference_protected&);
Establishes the referent of the right operand as the referent of the left operand.

os_reference_protected &operator=(const void*);
Establishes the object pointed to by the right operand as the referent of the left operand.

os_reference_protected::operator ==()

os_boolean operator ==(os_reference_protected const&) const;
Returns 1 if the arguments have the same referent; returns 0 otherwise.

os_reference_protected::operator !()

os_boolean operator !() const;
Returns nonzero if the reference has no current referent.

os_reference_protected::operator !=()

os_boolean operator !=(os_reference_protected const&) const;
Returns 1 if the arguments have different referents; returns 0 otherwise.

os_reference_protected::operator <()

os_boolean operator <(os_reference_protected const&) const;
If the first and second arguments 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_reference_protected::operator >()

os_boolean operator >(os_reference_protected const&) const;
If the first and second arguments 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_reference_protected::operator >=()

os_boolean operator >=(os_reference_protected const&) const;
If the first and second arguments 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_reference_protected::operator <=()

os_boolean operator <=(os_reference_protected const&) const;
If the first and second arguments 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_protected::os_reference_protected()

os_reference_protected(const void*);
Constructs an os_reference_protected to substitute for the specified void*. If the void* points to transient memory, err_reference_to_transient is signaled. 0 is a legal argument.

os_reference_protected::resolve()

void* resolve();
Returns the void* for which the specified os_reference_protected is a substitute. If the referent has been deleted, err_reference_not_found is signaled. If the referent database has been deleted, err_database_not_found is signaled.



[previous] [next]

Copyright © 1997 Object Design, Inc. All rights reserved.

Updated: 03/31/98 17:25:09