OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
RTTITypeinfo Class Reference

#include <ossimRtti.h>

Public Types

typedef std::vector< const RTTITypeinfo * > SubtypesConstVector
 

Public Member Functions

 RTTITypeinfo (const char *name, const RTTITypeinfo *bb[], void *(*)(int, void *), void *(*)())
 
 ~RTTITypeinfo ()
 
const char * getname () const
 
int same (const RTTITypeinfo *) const
 
int can_cast (const RTTITypeinfo *) const
 
int has_base (const RTTITypeinfo *) const
 
const RTTITypeinfosubclass (int=0) const
 
int num_subclasses () const
 
void * create (const RTTITypeinfo *, const char *) const
 
int can_create () const
 

Private Member Functions

void add_subtype (const RTTITypeinfo *)
 
void del_subtype (const RTTITypeinfo *)
 

Private Attributes

std::string n
 
const RTTITypeinfo ** b
 
int ns
 
SubtypesConstVector subtypes
 
void *(* new_obj )()
 
void *(* cast )(int, void *)
 

Static Private Attributes

static const RTTITypeinfo null_type = RTTITypeinfo("NULL", RTTI_base_null_type,0,0)
 

Friends

class RTTItypeid
 

Detailed Description

Definition at line 165 of file ossimRtti.h.

Member Typedef Documentation

◆ SubtypesConstVector

typedef std::vector<const RTTITypeinfo*> RTTITypeinfo::SubtypesConstVector

Definition at line 167 of file ossimRtti.h.

Constructor & Destructor Documentation

◆ RTTITypeinfo()

RTTITypeinfo::RTTITypeinfo ( const char *  name,
const RTTITypeinfo bb[],
void *  *)(int, void *,
void *  *)( 
)

Definition at line 52 of file ossimRtti.cpp.

References add_subtype(), and n.

56 {
57  n = "";
58  if(name) n = name;
59  b = bb; //ns = 0; subtypes = 0; //Create default RTTITypeinfo
60  cast = f1; //Attach casting func
61  new_obj = f2; //Attach creation func
62  int i = 0;
63  for(i=0;b[i];i++) //Add this as subtype to all its basetypes
64  ((RTTITypeinfo**)b)[i]->add_subtype(this); //REMARK: Harmless const castaway
65 }
std::string n
Definition: ossimRtti.h:190
void *(* cast)(int, void *)
Definition: ossimRtti.h:197
void *(* new_obj)()
Definition: ossimRtti.h:196
const RTTITypeinfo ** b
Definition: ossimRtti.h:191

◆ ~RTTITypeinfo()

RTTITypeinfo::~RTTITypeinfo ( )

Definition at line 73 of file ossimRtti.cpp.

74 {
75 // if(n)
76 // {
77 // free(n);
78 // n = NULL;
79 // }
80  int i = 0;
81  for(i=0;b[i];i++)
82  {
83  //Del this subtype from all its basetypes
84  ((RTTITypeinfo**)b)[i]->del_subtype(this); //REMARK: Harmless const castaway
85  }
86 }
const RTTITypeinfo ** b
Definition: ossimRtti.h:191

Member Function Documentation

◆ add_subtype()

void RTTITypeinfo::add_subtype ( const RTTITypeinfo t)
private

Definition at line 17 of file ossimRtti.cpp.

Referenced by RTTITypeinfo().

18 {
19  subtypes.push_back(t);
20  ns = subtypes.size();
21  //'subtypes' list. For this, the
22 /* const RTTITypeinfo** ptr = new const RTTITypeinfo*[ns+1]; //list is realloc'd with one extra entry.
23  int i; for(i=0;i<ns;i++) ptr[i] = subtypes[i];
24  ptr[i] = t;
25  ns++;
26  delete[] subtypes;
27  subtypes = ptr;
28  */
29 }
SubtypesConstVector subtypes
Definition: ossimRtti.h:193

◆ can_cast()

int RTTITypeinfo::can_cast ( const RTTITypeinfo p) const
inline

Definition at line 225 of file ossimRtti.h.

References has_base(), and same().

Referenced by RTTItypeid::can_cast().

226 {
227  return same(p) || p->has_base(this);
228 }
int same(const RTTITypeinfo *) const
Definition: ossimRtti.h:219
int has_base(const RTTITypeinfo *) const
Definition: ossimRtti.cpp:88

◆ can_create()

int RTTITypeinfo::can_create ( ) const
inline

Definition at line 230 of file ossimRtti.h.

References new_obj.

Referenced by RTTItypeid::can_create().

231 {
232  return new_obj!=0;
233 }
void *(* new_obj)()
Definition: ossimRtti.h:196

◆ create()

void * RTTITypeinfo::create ( const RTTITypeinfo bt,
const char *  c 
) const

Definition at line 96 of file ossimRtti.cpp.

Referenced by RTTItypeid::create().

97 { //given by char*. Searches for this type in the
98  void* p = 0; int i; //type-DAG rooted by this, creates it and returns
99  //it as cast to 'bt', where bt is either this or a
100  //direct base of this.
101  if (!strcmp(c,getname())) //Want to create an obj of this type ?
102  p = (new_obj)? new_obj() : 0; //Yes, do it if this type is instantiable.
103  else //No, try with subclasses...
104  for(i=0;i<ns && !((p=subtypes[i]->create(this,c)));i++); //Succeeded creating on ith subclass branch ?
105  if (!p) return 0; //Couldn't create it in any way, abort.
106  if (bt==this) i = -1; //Must cast to this's own type (i==-1)
107  else for(i=0;b[i] && b[i]!=bt;i++); //Search to which base of this we should cast
108  //Found: cast to ith base of this
109  return cast(i,p); //Cast to ith base of to this, return as void*
110 }
SubtypesConstVector subtypes
Definition: ossimRtti.h:193
void *(* cast)(int, void *)
Definition: ossimRtti.h:197
void *(* new_obj)()
Definition: ossimRtti.h:196
const RTTITypeinfo ** b
Definition: ossimRtti.h:191
const char * getname() const
Definition: ossimRtti.cpp:67

◆ del_subtype()

void RTTITypeinfo::del_subtype ( const RTTITypeinfo t)
private

Definition at line 31 of file ossimRtti.cpp.

32 {
33  if ( subtypes.size() > 0 )
34  {
35  SubtypesConstVector::iterator iter = std::find(subtypes.begin(), subtypes.end(), t);
36  if(iter != subtypes.end())
37  {
38  subtypes.erase(iter);
39 
40  // "ns" is private member of RTTITypeinfo
41  ns = subtypes.size();
42  }
43  }
44 
45  //of this and removes it, if found.
46 
47 // int i; for(i=0;i<ns && subtypes[i]!=t;i++);
48 // if (i<ns)
49 // for(;i<ns-1;i++) subtypes[i] = subtypes[i+1];
50 }
SubtypesConstVector subtypes
Definition: ossimRtti.h:193

◆ getname()

const char * RTTITypeinfo::getname ( ) const

Definition at line 67 of file ossimRtti.cpp.

References n.

Referenced by RTTItypeid::getname().

68 {
69  return n.c_str();
70 }
std::string n
Definition: ossimRtti.h:190

◆ has_base()

int RTTITypeinfo::has_base ( const RTTITypeinfo p) const

Definition at line 88 of file ossimRtti.cpp.

References same().

Referenced by can_cast().

89 {
90  int i = 0;
91  for(i=0;b[i];i++) //for all bases of this...
92  if (p->same(b[i]) || b[i]->has_base(p)) return 1; //match found, return 1 or no match, search deeper
93  return 0; //no match at all, return 0
94 }
int same(const RTTITypeinfo *) const
Definition: ossimRtti.h:219
int has_base(const RTTITypeinfo *) const
Definition: ossimRtti.cpp:88
const RTTITypeinfo ** b
Definition: ossimRtti.h:191

◆ num_subclasses()

int RTTITypeinfo::num_subclasses ( ) const
inline

Definition at line 209 of file ossimRtti.h.

References ns.

Referenced by RTTItypeid::num_subclasses().

210 {
211  return ns;
212 }

◆ same()

int RTTITypeinfo::same ( const RTTITypeinfo p) const
inline

Definition at line 219 of file ossimRtti.h.

References n.

Referenced by can_cast(), has_base(), RTTItypeid::operator!=(), and RTTItypeid::operator==().

220 { //First, try to see if it's the same
221  return this==p || !strcmp(n.c_str(),p->n.c_str()); //'physical' RTTITypeinfo (which should be the case,
222 } //since we create them per-class and not per-obj).
std::string n
Definition: ossimRtti.h:190

◆ subclass()

const RTTITypeinfo * RTTITypeinfo::subclass ( int  i = 0) const
inline

Definition at line 214 of file ossimRtti.h.

Referenced by RTTItypeid::subclass().

215 {
216  return (i>=0 && i<ns)? subtypes[i]: 0;
217 }
SubtypesConstVector subtypes
Definition: ossimRtti.h:193

Friends And Related Function Documentation

◆ RTTItypeid

friend class RTTItypeid
friend

Definition at line 203 of file ossimRtti.h.

Member Data Documentation

◆ b

const RTTITypeinfo** RTTITypeinfo::b
private

Definition at line 191 of file ossimRtti.h.

Referenced by RTTItypeid::baseclass(), and RTTItypeid::num_baseclasses().

◆ cast

void*(* RTTITypeinfo::cast) (int, void *)
private

Definition at line 197 of file ossimRtti.h.

◆ n

std::string RTTITypeinfo::n
private

Definition at line 190 of file ossimRtti.h.

◆ new_obj

void*(* RTTITypeinfo::new_obj) ()
private

Definition at line 196 of file ossimRtti.h.

Referenced by can_create().

◆ ns

int RTTITypeinfo::ns
private

Definition at line 192 of file ossimRtti.h.

Referenced by num_subclasses().

◆ null_type

const RTTITypeinfo RTTITypeinfo::null_type = RTTITypeinfo("NULL", RTTI_base_null_type,0,0)
staticprivate

Definition at line 195 of file ossimRtti.h.

Referenced by RTTItypeid::null_type().

◆ subtypes

SubtypesConstVector RTTITypeinfo::subtypes
private

Definition at line 193 of file ossimRtti.h.


The documentation for this class was generated from the following files: