make it compile with modern C++
[prop.git] / include / AD / persist / ptype.h
blobf74158f5e69785232206d8b221ac011685fbfd8f
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are welcomed to incorporate any part of ADLib and Prop into
9 // your programs.
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
16 // code.
18 // This software is still under development and we welcome(read crave for)
19 // any suggestions and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef persistent_objects_type_h
26 #define persistent_objects_type_h
28 //////////////////////////////////////////////////////////////////////////////
29 // This file describes the class PObjectType, which describes the type
30 // of a persistent object.
31 //////////////////////////////////////////////////////////////////////////////
33 #include <AD/generic/generic.h>
34 #include <AD/persist/pconfig.h>
35 #include <iostream>
37 //////////////////////////////////////////////////////////////////////////////
39 // Opaque definitions
41 //////////////////////////////////////////////////////////////////////////////
42 class Pistream;
43 class Postream;
44 class PBaseFactory;
46 //////////////////////////////////////////////////////////////////////////////
48 // Persistent objects types.
50 //////////////////////////////////////////////////////////////////////////////
51 class PObjectType {
52 PObjectType (const PObjectType&);
53 void operator = (const PObjectType&);
55 public:
56 struct Entry
57 { P_OBJECT_TYPEID unique_id; // unique id for each type
58 const char * type_name; // name of object type
59 int type_name_len; // length of type name
60 PBaseFactory * factory; // object factory
63 protected:
64 // index into a table of unique id during execution
65 friend class PBaseFactory;
66 Entry * entry;
68 static Entry * lookup_entry (const char *);
69 public:
71 //////////////////////////////////////////////////////////////////////////
72 // Constructor and destructor
73 //////////////////////////////////////////////////////////////////////////
74 inline PObjectType (Entry * e = 0) : entry(e) {}
75 PObjectType (const char * name);
76 virtual ~PObjectType ();
78 friend std::ostream& operator << ( std::ostream&, const PObjectType& );
79 inline Bool operator == (const PObjectType& id) const
80 { return entry == id.entry; }
81 inline Bool operator != (const PObjectType& id) const
82 { return entry != id.entry; }
83 const char * name () const;
84 static int number_of_types ();
86 //////////////////////////////////////////////////////////////////////////
88 // Interface to the persistent object classes
90 //////////////////////////////////////////////////////////////////////////
92 //////////////////////////////////////////////////////////////////////////
94 // Read and write methods. We can't read and write PObjectType
95 // arbitrarily from and to the persistent streams.
97 //////////////////////////////////////////////////////////////////////////
98 void write ( Postream& ) const;
99 void read ( Pistream& );
102 #endif