00001 #ifndef IOKERNEL_UNIONMETACLASS_H_ 00002 #define IOKERNEL_UNIONMETACLASS_H_ 00003 00004 #include "aggregate_meta_class.h" 00005 #include "iokernel_forwarders.h" 00006 00007 00008 00009 // used for writing/initializing only if the 00010 // UnionMetaClass::_offset field is not set!! 00011 typedef int (*UnionSelector)( Address address ); 00012 00013 00014 class UnionMetaClass : public AggregateMetaClass { 00015 friend class ObjectFactory; 00016 friend class UnionIterator; 00017 void zero_field(Address address) const; 00018 public: 00019 UnionMetaClass( LString meta_class_name = LString() ); 00020 virtual ~UnionMetaClass(); 00021 00022 virtual void add_union_field( LString field_name, 00023 MetaClass* meta_class, 00024 size_t offset ); 00025 00026 // use exactly one of the following two methods 00027 virtual void set_union_selector( UnionSelector union_selector ); // the function returning the tag 00028 virtual void set_offset( int offset ); // the offset for the tag which is of type 'int' 00029 00030 virtual void write( const ObjectWrapper &obj, 00031 OutputStream* outputStream ) const; 00032 00033 virtual void read( const ObjectWrapper &obj, 00034 InputStream* inputStream ) const; 00035 00036 virtual void initialize( const ObjectWrapper &obj, 00037 InputStream* inputStream ) const; 00038 00039 virtual void adjust_field_offsets(); 00040 00041 virtual Iterator* get_local_iterator( Address instance ) const; 00042 00043 virtual const MetaClass* get_meta_class( Address address ) const; 00044 00045 virtual void set_meta_class_of_object( Address instance ) const; 00046 00047 Walker::ApplyStatus walk(const Address address,Walker &walk) const; 00048 00049 static const LString &get_class_name(); 00050 00051 virtual size_t get_proper_field_count(const Address address) const; 00052 00053 virtual FieldDescription* get_proper_field_description(const Address address, 00054 const LString& field_name ) const; 00055 virtual FieldDescription* get_proper_field_description(const Address address, 00056 size_t i) const; 00057 00058 virtual void walk_referenced_meta_classes(MetaClassApplier *x); 00059 00060 protected: 00061 static void constructor_function( Address address ); 00062 00063 virtual int get_tag_num( Address instance ) const; 00064 private: 00065 00066 suif_vector<FieldDescription*>* _union_fields; 00067 // the UnionMetaClass uses either the _tag_offset or the _union_selector, but not both! 00068 // the other one is 0 (_union_selector) or -1 (_tag_offset) to specifiy an invalide entry 00069 int _tag_offset; 00070 UnionSelector _union_selector; 00071 private: 00072 UnionMetaClass(const UnionMetaClass &); 00073 UnionMetaClass &operator=(const UnionMetaClass &); 00074 00075 }; 00076 00077 00078 00079 #endif 00080 00081 00082 00083 00084 00085