Using C++ with Caché
Reference for Object Datatype Classes
[Back] [Next]
   
Server:docs1
Instance:LATEST
User:UnknownUser
 
-
Go to:
Search:    

This chapter describes a set of predefined proxy classes that correspond to Caché object datatype classes such as lists, arrays, and streams. All of these proxy classes inherit from both Dyn_obj and Obj_t classes. All of them have the standard open(), create_new(), openid(), and openref() methods.

Collection classes:
Stream classes:
Relationships:
Collection Classes
Caché supports two kinds of collections: lists and arrays. These are two different kinds of groupings of elements of a single type:
Operations on a C++ client usually assume the collection's prior existence.
Class Template d_vector<S> (List Collections)
Proxies for %ListOfObjects and %ListOfDataTypes provide an interface which is almost identical to the interface of std::vector.
Because Caché list objects are generated as d_obj_vector<T> and d_prim_vector<T> classes, they provide the same interface that is specified by d_vector.
List Operations, Stack Operations, and Element Access
Size and Capacity
Iterators
Class Template d_map<S> (Array Collections)
Proxies for %ArrayOfObjects and %ArrayOfDataTypes provide an interface which is almost identical to the interface of std::map.
Because Caché array objects are generated as d_obj_map<T> and d_prim_map<T> classes, they provide the same interface that is specified by d_map.
List Operations and Element Access
Size and Capacity
Iterators
Streams
Proxies for Caché streams use adapters that fit them into the standard C++ library streams framework and optimize their performance. There are also a set of proxy classes for streams that inherit their common interface from the d_stream class. The adapters are the recommended way of working with streams. The adapters make the streams buffered, so avoid mixing calls to adapters and proxy objects that change the stream read/write position (as a result of reading or writing to a stream or a direct change in position).
Stream Objects
The following table describes the mapping of Caché stream classes:
Caché Class
C++ Class
d_char_stream
d_bin_stream
d_file_bin_stream
d_file_char_stream
All stream classes have static open() and create_new() methods. The d_file_char_stream class has an is_unicode() method, which checks if the stream contains Unicode data.
C++ Stream Adapters
The stream adapters can be used exactly as streams from the C++ standard library, and all the unique to Caché methods that are common to all Caché streams can be also accessed from them.
The adapter classes are:
All C++ adapter objects can be constructed from a d_ref to a stream object proxy. For example:
   // create a low level stream object
   d_ref<d_char_stream> stream = d_char_stream::create_new(&db); 
   // create an IOStreams extension stream object 
   d_iostream io(stream);
All adapters have helper methods that allow you to work with a stream only via its adapter. All C++ adapter objects can be constructed from a d_ref to a stream object proxy. For example:
   // create a low level stream object 
   d_ref<d_char_stream> stream = d_char_stream::create_new(&db); 
   // create an IOStreams extension stream object 
   d_iostream io(stream);
Stream Adapter Classes
d_basic_ostream
There are typedefs d_ostream and d_wostream. In addition to std::basic_ostream interface, the class provides the following methods:
   d_binary oid(); 
   long size(); 
   d_status erase(); 
   d_status save();
d_basic_istream
There are typedefs d_istream and d_wistream. In addition to std::basic_istream interface, the class provides the following methods:
   d_binary oid(); 
   long size(); 
   d_status rewind();
d_basic_iostream
There are typedefs d_iostream and d_wiostream. In addition to std::basic_iostream interface, the class provides the following methods:
   d_binary oid(); 
   long size(); 
   d_status rewind(); 
   d_status move_to_end(); 
   d_status erase(); 
   d_status save();
Class d_stream
The d_stream class provides the common interface for all streams. The d_file_stream class adds to it the common interface for all file streams.
d_stream Methods
The d_stream methods in common between character and binary streams are:
   d_binary oid(); 
   d_status save(); 
   d_status clear(); 
   d_status rewind(); 
   d_status move_to_end(); 
   long size(); 
   d_stream& copy(const abs_d_ref& stream);
Methods specific to character streams are:
   void read(d_int& len, d_string& res); 
   void readline(d_int& len, d_string& res); 
   void write(const d_string& data);
Methods specific to binary streams are:
   void read(d_int& len, d_binary& res); 
   void write(const d_binary& data);
d_file_stream Methods
The additionally available methods from the d_file_stream class are:
   d_string get_filename(); 
   void set_filename(const d_string& fname); 
   d_timestamp last_modified(); 
   d_status link_to_file(const_name_t fname);   
   // const_name_t is a typedef for const wchar_t*
Class Template d_relationship<S>
As in Caché, relationships are treated as properties. If there is a relationship between classes P and Q where P is the single-valued side and Q is the multi-valued side, then the single-valued side is generated as a property of type P (d_ref<P>), and the multi-valued side is generated as a property of type d_relationship<Q> (d_ref<d_relationship<Q>>). As with other properties, when P or Q can be determined only at runtime, P or Q (or both) become Dyn_obj (a dynamic object).
d_relationship Methods
The d_relationship<P> class is a standard container that supports the following methods: