00001 #ifndef IOKERNEL__META_CLASS_H 00002 #define IOKERNEL__META_CLASS_H 00003 00004 #include "object.h" 00005 #include "iokernel_forwarders.h" 00006 #include "walker.h" 00007 #include "meta_class_iter.h" 00008 00009 00010 #define OFFSETOF( CLASSNAME, MEMBERNAME ) ((size_t)(&((CLASSNAME*)0)->MEMBERNAME)) 00011 00012 00013 00014 00015 typedef void (*InitializerFunction)( const ObjectWrapper &obj, 00016 bool is_owned, 00017 InputStream* input_stream ); 00018 00019 class MetaClassApplier { 00020 public: 00021 virtual bool operator () (MetaClass *x) = 0; 00022 virtual ~MetaClassApplier(); 00023 }; 00024 00025 class MetaClass : public Object { 00026 friend class ObjectFactory; 00027 public: 00028 00029 // returns the name of the class (For example: "IfStatement" ) 00030 virtual const LString& get_instance_name() const; 00031 00032 // returns the instance size of an object (For example: 4 for an int) 00033 virtual size_t get_size_of_instance() const; 00034 00035 // return the alignment for an instance. Must be on 0 mod alignment border 00036 virtual size_t get_alignment_of_instance() const; 00037 00038 // creates an instance of an object at 'instance' and fills it with 00039 // contents from the input_stream 00040 virtual void read ( const ObjectWrapper &obj, 00041 InputStream* inputStream ) const; 00042 00043 // writes an instance of 'this' at 'instance' address to the output_stream 00044 // 'o' 00045 virtual void write( const ObjectWrapper &obj, 00046 OutputStream* outputStream ) const; 00047 00048 // returns an iterator that iterates over the 00049 // element that 'instance' contains 00050 // If the MetaClass doesn't encapsulate any objects 00051 // 0 is returned as the iterator 00052 virtual Iterator* get_iterator( ConstAddress instance, 00053 Iterator::Contents contents = Iterator::Owned ) const; 00054 // This currently dispatches to the instance version 00055 virtual Iterator* get_iterator( const ObjectWrapper &obj, 00056 Iterator::Contents contents = Iterator::Owned ) const; 00057 00058 virtual bool is_elementary() const ; 00059 00060 // works for all 'objects' subclassed for Object 00061 virtual const MetaClass* get_meta_class( Address address ) const; 00062 00063 virtual void set_constructor_function( ConstructorFunction constructorFunction ); 00064 00065 virtual ConstructorFunction get_constructor_function() const; 00066 00067 virtual void construct_object( Address address ) const; 00068 00069 virtual void initialize( const ObjectWrapper &obj, 00070 InputStream* inputStream ) const; 00071 00072 virtual MetaClass* get_link_meta_class() const; 00073 00074 virtual void adjust_field_offsets(); 00075 00076 // walk the meta-classes referenced by a given meta class. 00077 virtual void walk_referenced_meta_classes(MetaClassApplier *x); 00078 00079 virtual MetaClassId get_meta_class_id() const; 00080 00081 virtual VirtualNode* get_virtual_node( const LString &name, const String &what ) const; 00082 00083 virtual bool defines_a_subtype_of( const MetaClass* m ) const; 00084 00085 // is the object for which this is the meta class of the given kind? 00086 bool object_is_kind_of(const LString &className) const; 00087 bool has_constructed_object() const; 00088 00089 // debugging help. Print out all meta class info. 00090 virtual String get_debug_text() const; 00091 virtual void print_debug() const; 00092 00093 // deletes all sub-parts of an object that the 00094 // default destructor does not destruct. 00095 // For example: The system reads in an object of type MethodCallInstruction 00096 // and since no MethodCallInstruction exists it is mapped to a 00097 // CallInstruction 00098 // The destructor of CallInstruction can only call the destructors 00099 // of the sub objects it owns and nothing else 00100 // This method uses the dynamic MetaClass of the object to destruct 00101 // the remaining objects 00102 virtual void destruct( const ObjectWrapper &obj, 00103 bool called_from_destructor ) const; 00104 00105 static const LString &get_class_name(); 00106 00107 virtual Walker::ApplyStatus walk(const ObjectWrapper &obj, 00108 Walker &walk) const; 00109 virtual Walker::ApplyStatus walk(const Address address,Walker &walk) const; 00110 00111 public: 00112 MetaClass( LString metaClassName = LString() ); 00113 00114 virtual ~MetaClass(); 00115 00116 virtual void set_size( size_t size ); 00117 00118 virtual void set_alignment(size_t size); 00119 00120 virtual size_t get_size() const; 00121 00122 virtual void set_meta_class_of_object( Address instance ) const; 00123 00124 virtual ObjectFactory* get_owning_factory() const; 00125 00126 protected: 00127 virtual void set_owning_factory( ObjectFactory* owning_factory ); 00128 00129 static void constructor_function( Address place ); 00130 00131 InitializerFunction _pre_init; 00132 00133 InitializerFunction _post_init; 00134 00135 protected: 00136 virtual void set_meta_class_id( MetaClassId id ); 00137 00138 LString _meta_class_name; 00139 00140 size_t _size; 00141 00142 size_t _alignment; 00143 00144 MetaClassId _meta_class_id; 00145 00146 ObjectFactory* _owning_factory; 00147 00148 // public: 00149 // void debugit(const char *doing,Address to_what); 00150 // void debugit(const char *doing,int i); 00151 private: 00152 ConstructorFunction _constructor_function; 00153 bool _has_constructed_object; 00154 00155 MetaClass(const MetaClass &); 00156 MetaClass &operator=(const MetaClass &); 00157 }; 00158 00159 00160 00161 00162 00163 #endif 00164 00165 00166 00167 00168 00169 00170