00001 // $Id: AttributeProperties.h 85 2006-04-02 20:28:44Z bingmann $ 00002 00003 #ifndef VGS_AttributeProperties_H 00004 #define VGS_AttributeProperties_H 00005 00006 #include <string> 00007 #include <vector> 00008 #include <map> 00009 00010 #include "GraphTypes.h" 00011 #include "AnyType.h" 00012 #include "AttributeBlob_fwd.h" 00013 00014 namespace VGServer { 00015 00021 class AttributeProperties : public AnyType 00022 { 00023 public: 00024 std::string name; 00025 00028 bool varying; 00029 00032 unsigned int defbitnum; 00033 00034 // if this is a no-default, fixed length attribute and every other 00035 // attribute before it is no-default and fixed too, then this is the direct 00036 // lookup index within the attribute chain including the 00037 // default-bitfield. Else it is -1. 00038 int lookup; 00039 00040 public: 00042 AttributeProperties() 00043 : AnyType(ATTRTYPE_INVALID) 00044 { } 00045 00049 explicit AttributeProperties(const std::string& attrname, attrtype_t attrtype, bool _varying=false) 00050 : AnyType(attrtype), name(attrname), varying(_varying) 00051 { 00052 } 00053 00056 explicit AttributeProperties(const std::string& attrname, const AnyType &def, bool _varying=false) 00057 : AnyType(def), name(attrname), varying(_varying) 00058 { 00059 } 00060 00063 void resetType(attrtype_t t) 00064 { 00065 AnyType::resetType(t); 00066 varying = false; 00067 defbitnum = 0; 00068 lookup = 0; 00069 } 00070 00072 void appendBinaryFormat(class ByteOutBuffer &bob) const; 00073 }; 00074 00081 class AttributePropertiesList : public std::vector<class AttributeProperties> 00082 { 00083 public: 00085 unsigned int defbits; 00086 00088 unsigned int defbytes; 00089 00090 private: 00092 std::map<std::string, unsigned int> attrname_map; 00093 00094 public: 00096 void clear() { 00097 std::vector<class AttributeProperties>::clear(); 00098 attrname_map.clear(); 00099 defbits = defbytes = 0; 00100 } 00101 00104 void calcAttributeLookups(); 00105 00108 int lookupAttributeName(const std::string &s) const; 00109 00111 static unsigned int calcDefaultBytes(unsigned int n); 00112 00115 template <typename AttributeBlob> 00116 AttributeBlob createBlankAttributeBlob() const; 00117 00120 void appendBinaryFormat(class ByteOutBuffer &bob) const; 00121 }; 00122 00126 class AttributeIdException : public std::exception 00127 { 00128 }; 00129 00130 } // namespace VGServer 00131 00132 #endif // VGS_AttributeProperties_H