ObjectStore C++ API Reference

os_class_type

class os_class_type : public os_type
This class is part of the ObjectStore metaobject protocol, which provides access to ObjectStore schemas. An instance of os_class_type represents a C++ class. os_class_type is derived from os_type.

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.

Programs using this class must include <ostore/ostore.hh>, followed by <ostore/coll.hh> (if used), followed by <ostore/mop.hh>.

os_class_type::Anonymous_union

This enumerator is a possible return value from os_class_type::kind(). It indicates an anonymous union type.

os_class_type::Class

This enumerator is a possible return value from os_class_type::kind(). It indicates a class declared with the class-key class.

os_class_type::create()

static os_class_type &create(const char *name);
Creates a new class with the specified name (which is copied by ObjectStore). It initializes the other attributes of os_class_type as follows:
AttributeValue
base_classesempty os_List<os_base_class*>
membersempty os_List<os_member*>
defines_virtual_functions0
class_kindos_class_type::Class
defines_get_os_typespec_function0
is_template_class0
is_persistent0
is_forward_definition1

static os_class_type &create(
      const char *name,
      os_List<os_base_class*> &base_classes,
      os_List<os_member*> &members,
      os_boolean defines_virtual_functions
);
Creates a new class. The arguments specify the initial values for the attributes name, base_classes, members, and defines_virtual_functions. The initial values for the remaining attributes are as follows:
AttributeValue
class_kindos_class_type::Class
defines_get_os_typespec_function0
is_template_class0
is_persistent0
is_forward_definition0

If you create a class with the metaobject protocol, there is no direct way to make it compiler heterogeneous.

os_class_type::declares_get_os_typespec_function()

os_boolean declares_get_os_typespec_function() const;
Returns nonzero if and only if the specified class declares a get_os_typespec() member function.

os_class_type::defines_virtual_functions()

os_boolean defines_virtual_functions() const;
Returns nonzero if and only if the specified class defines any virtual functions.

os_class_type::find_base_class()

const os_base_class *find_base_class(const char *classname) 
const;
Returns a pointer to the const os_base_class whose class has the given name and is a base class of this. Either the inheritance is direct or the base class is a virtual base class. If there is no such class, 0 is returned. err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_base_class *find_base_class(const char *classname);
Returns a pointer to the non-const os_base_class whose class has the given name and is a base class of this. Either the inheritance is direct or the base class is a virtual base class. If there is no such class, 0 is returned. err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_class_type::find_member_variable()

const os_member_variable *find_member_variable(
      const char *name
) const;
Returns a pointer to a const os_member_variable representing the data member of this with the given name. The member must be defined by this, not inherited by it. If there is no such data member, 0 is returned. err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_member_variable *find_member_variable(const char *name);
Returns a pointer to a non-const os_member_variable representing the data member of this with the given name. The member must be defined by this, not inherited by it. If there is no such data member, 0 is returned. err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_class_type::get_access_of_get_os_typespec_function()

os_member::os_member_access get_access_of_get_os_
typespec_function() const;
Returns os_member::Private, os_member::Protected, or os_member::Public.

os_class_type::get_allocated_virtual_base_classes()

os_list get_allocated_virtual_base_classes() const;
Returns a list of pointers to const os_base_class objects. Each os_base_class object represents a virtual base class from which the specified class inherits (that is, whose storage is allocated as part of the specified class). The order of list elements is not significant. err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_list get_allocated_virtual_base_classes();
Returns a list of pointers to non-const os_base_class objects. Each os_base_class object represents a virtual base class from which the specified class inherits (that is, whose storage is allocated as part of the specified class). The order of list elements is not significant. err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_class_type::get_base_classes()

os_list get_base_classes() const;
Returns a list, in declaration order, of pointers to const os_base_class objects. Each os_base_class object represents a class from which the given class is derived, together with the nature of the derivation (virtual or nonvirtual, and public, private, or protected). err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_list get_base_classes();
Returns a list, in declaration order, of pointers to non-const os_base_class objects. Each os_base_class object represents a class from which the given class is derived, together with the nature of the derivation (virtual or nonvirtual, and public, private, or protected). err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_class_type::get_class_kind()

os_unsigned_int32 get_class_kind() const;
Returns an enumerator indicating the kind of class represented by the specified instance of os_class_type. os_class_type::Struct indicates a struct; os_class_type::Union indicates a named union type; os_class_type::Anonymous_union indicates an anonymous union type; and os_class_type::Class indicates a class declared with the class-key class.

os_class_type::get_dispatch_table_pointer_offset()

os_int32 get_dispatch_table_pointer_offset() const;
Returns the offset at which the pointer to the dispatch table is stored. Signals err_mop if there is no dispatch table.

os_class_type::get_indirect_virtual_base_classes()

os_list get_indirect_virtual_base_classes() const;
Returns a list of pointers to const os_base_class objects. Each os_base_class object represents a virtual base class from which the specified class inherits virtually and indirectly. The order of list elements is not significant. err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_list get_indirect_virtual_base_classes();
Returns a list of pointers to non-const os_base_class objects. Each os_base_class object represents a virtual base class from which the specified class inherits virtually and indirectly. The order of list elements is not significant. err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_class_type::get_members()

os_list get_members() const;
Returns a list, in declaration order, of pointers to const os_member objects. Each os_member object represents a member defined by the specified class. Note that currently only discriminant member functions are stored in the schema. err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_list get_members();
Returns a list, in declaration order, of pointers to non-const os_member objects. Each os_member object represents a member defined by the specified class. Note that currently only discriminant member functions are stored in the schema. err_mop_forward_definition is signaled if the specified class is known only through a forward definition.

os_class_type::get_most_derived_class()

static const os_class_type &get_most_derived_class(
      const void *object, 
      const void* &most_derived_object
) const;
If object points to the value of a data member for some other object, o, this function returns a reference to the most derived class of which o is an instance. A class, c1, is more derived than another class, c2, if c1 is derived from c2, or derived from a class derived from c2, and so on. most_derived_object is set to the beginning of the instance of the most derived class. There is one exception to this behavior, described below.

If object points to an instance of a class, o, but not to one of its data members (for example, because the memory occupied by the instance begins with a virtual table pointer rather than a data member value), the function returns a reference to the most derived class of which o is an instance. most_derived_object is set to the beginning of the instance of the most derived class. There is one exception to this behavior, described below.

If object does not point to the memory occupied by an instance of a class, most_derived_object is set to 0, and err_mop is signaled. ObjectStore issues an error message like the following:

<err-0008-0010>Unable to get the most derived class in os_class_
type::get_most_derived_class() containing the address 0x%lx.
Here is an example:

class B {
public:
int ib ;
} ;

class D : public B {
public:
int id ;
} ;

class C {
public:
int ic ;
D cm ;
} ;

void baz () {
C* pC = new (db) C;
D *pD = &C->cm ;
int *pic = &pC->ic, *pid = &pC->cm.id, *pib = &pC->cm.ib ;
...
} 
Invoking get_most_derived_class() on the pointers pic, pid, and pib has the results shown in the following table:
object most_derived_object os_class_type
picpCC
pidpDD
pibpDD

The exception to the behavior described above can occur when a class-valued data member is collocated with a base class of the class that defines the data member. If a pointer to such a data member (which is also a pointer to such a base class) is passed to get_most_derived_class(), a reference to the value type of the data member is returned, and most_derived_object is set to the same value as object.

Consider, for example, the following class hierarchy:

class C0 {
public:
int i0;
};

class B0 {
public:
void f0();
};

class B1 : public B0 {
public:
virtual void f1();
C0 c0;
};

class C1 : public B1 {
public:
static os_typespec* get_os_typespec();
int i1;
};
Some compilers will optimize B0 so that it has zero size in B1 (and C1). This means the class-valued data member c0 is collocated with a base class, B0, of the class, C1, that defines the data member.

Given

      C1 c1;
      C1 * pc1 = & c1;
      B0 * pb0 = (B0 *)pc1;
      C0 * pc0 = & pc1->c0;
the pointers pb0 and pc0 will have the same value, because of this optimization.

In this case get_most_derived_class() called on the pb0 or pc0 will return a reference to the os_class_type for C0 (the value type of the data member c0) and most_derived_object is set to the same value as object.

If B1 is instead defined as

class B1 : public B0 {
public:
      virtual void f1();
      int i;
      C0 c0;
};
and

      int * pi = & pc1->i;
pb0 and pi have the same value because of the optimization, but the base class, B0, is collocated with an int-valued data member rather than a class-valued data member. get_most_derived_class() called on pb0 or pi returns a pointer to the os_class_type for the class C1 and sets most_derived_object to the same value as pc1.

os_class_type::get_name()

const char *get_name() const;
Returns the name of the specified class.

os_class_type::get_pragmas()

os_List<os_pragma*> get_pragmas() const;
Returns the pragmas associated with the specified class.

os_class_type::get_size_as_base()

os_unsigned_int32 get_size_as_base() const;
Returns the size of the specified class when serving as a base class.

os_class_type::get_source_position()

void get_source_position(
      const char* &file, 
      os_unsigned_int32 &line
) const;
Returns the source position associated with the specified class.

os_class_type::has_constructor()

os_boolean has_constructor() const;
Returns nonzero if the class defines a constructor.

os_class_type::has_destructor()

os_boolean has_destructor() const;
Returns nonzero if the class defines a destructor.

os_class_type::has_dispatch_table()

os_boolean has_dispatch_table() const;
Returns nonzero if the class has a dispatch table.

os_class_type::introduces_virtual_functions()

os_boolean introduces_virtual_functions() const;
Returns nonzero if and only if the class defines, rather than merely inherits, a virtual function.

You can set this attribute with set_introduces_virtual_functions().

os_class_type::is_abstract()

os_boolean is_abstract() const;
Returns nonzero if and only if the specified class is abstract.

os_class_type::is_forward_definition()

os_boolean is_forward_definition() const;
Returns 1 if and only if the specified class is known only through a forward definition.

os_class_type::is_persistent()

os_boolean is_persistent() const;
Returns nonzero if and only if the specified class is marked as persistent.

os_class_type::is_template_class()

os_boolean is_template_class() const;
Returns 1 if and only if the specified class is a template class.

os_class_type::operator os_instantiated_class_type&()

operator const os_instantiated_class_type&() const;
Provides for safe casts from os_class_type to const os_instantiated_class type. If the cast is not permissible, err_mop_illegal_cast is signaled.

operator os_instantiated_class_type&();
Provides for non-const casts from os_class_type to os_instantiated_class type. If the cast is not permissible, err_mop_illegal_cast is signaled.

os_class_type::set_access_of_get_os_typespec_function()

void set_access_of_get_os_typespec_function(
      os_member::os_member_access
);
Pass os_member::Private, os_member::Protected, or os_member::Public to specify the type of access allowed to the class's get_os_typespec() function.

os_class_type::set_base_classes()

void set_base_classes(os_List<os_base_class*>&);
Sets the list, in declaration order, of os_base_classes of the specified class. Each os_base_class object represents a class from which the given class is derived, together with the nature of the derivation (virtual or nonvirtual, and public, private, or protected).

os_class_type::set_class_kind()

void set_class_kind(os_unsigned_int32);
Sets the class kind of the specified class. The argument should be an enumerator indicating the kind of class represented by the specified instance of os_class_type. os_class_type::Struct indicates a struct; os_class_type::Union indicates a named union type; os_class_type::Anonymous_union indicates an anonymous union type; and os_class_type::Class indicates a class declared with the class-key class.

os_class_type::set_declares_get_os_typespec_function()

void set_declares_get_os_typespec_function(os_boolean);
Specifies whether this declares a get_os_typespec() member function.

os_class_type::set_defines_virtual_functions()

void set_defines_virtual_functions(os_boolean);
Specifies whether the specified class defines any virtual functions.

os_class_type::set_dispatch_table_pointer_offset()

void set_dispatch_table_pointer_offset(os_int32);
Sets the offset at which the pointer to the dispatch table is stored.

os_class_type::set_has_constructor()

void set_has_constructor(os_boolean);
Specifies whether the class defines a constructor.

os_class_type::set_has_destructor()

void set_has_destructor(os_boolean);
Specifies whether the class defines a destructor.

os_class_type::set_indirect_virtual_base_classes()

void set_indirect_virtual_base_classes(os_List<os_base_class*>);
Sets the indirect virtual base classes of the specified class.

os_class_type::set_introduces_virtual_functions()

void set_introduces_virtual_functions(os_boolean);
Passing a nonzero value specifies that the class defines, rather than merely inherits, a virtual function.

os_class_type::set_is_abstract()

void set_is_abstract(os_boolean);
Specifies whether the specified class is abstract.

os_class_type::set_is_forward_definition()

void set_is_forward_definition(os_boolean);
Specifies whether the specified class is known only through a forward definition.

os_class_type::set_is_persistent()

void set_is_persistent(os_boolean);
Specifies whether the specified class is marked as persistent. In order to be installed into a database schema, a class must either be marked as persistent or be reachable from a persistent class. Making a class persistent with set_is_persistent() is similar to marking it with OS_MARK_SCHEMA_TYPE().

os_class_type::set_members()

void set_members(os_List<os_member*>&);
Sets the members, in declaration order, of the specified class.

os_class_type::set_name()

void set_name(const char *);
Sets the name of the specified class. ObjectStore copies the character array pointed to by the argument.

os_class_type::set_pragmas()

void set_pragmas(os_List<os_pragma*>);
Sets the pragmas associated with the specified class.

os_class_type::set_source_position()

void set_source_position(
      const char* file, 
      os_unsigned_int32 line
);
Sets the source position associated with the specified class.

os_class_type::Struct

This enumerator is a possible return value from os_class_type::kind(). It indicates a struct.

os_class_type::Union

This enumerator is a possible return value from os_class_type::kind(). It indicates a named union type.



[previous] [next]

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

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