attribute_map.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00027 #ifndef MESH3D__ATTRIBUTE_MAP__H
00028 #define MESH3D__ATTRIBUTE_MAP__H
00029
00030 #include "mesh3d/exception.h"
00031 #include <map>
00032 #include <vector>
00033 #include <typeinfo>
00034 #include <cassert>
00035
00036 namespace mesh3d {
00037
00038 typedef size_t index_type;
00039 typedef __int32 uint32;
00040
00041 template<typename Key>
00042 class attribute_map_base
00043 {
00044 public:
00045 typedef std::vector<Key> key_array;
00046 typedef std::map<Key,index_type> key_index_map;
00047
00048 virtual ~attribute_map_base();
00049
00050 public:
00051 virtual std::type_info const& value_type_id() const = 0;
00052
00053 protected:
00054 attribute_map_base();
00055 };
00056
00058 template<typename Key, typename Value>
00059 class attribute_map
00060 : public attribute_map_base<Key>
00061 {
00062 public:
00063 typedef Key key_type;
00064 typedef Value value_type;
00065
00066 attribute_map();
00067
00068 bool empty () const;
00069 index_type size () const;
00070 void begin_insertion(index_type estimated_count = 0);
00071 void insert (Key const &key, Value const &value);
00072 void end_insertion ();
00073 bool is_inserting () const;
00074 void set_value (Key const &key, Value const &value);
00075 Value value (Key const &key) const;
00076 bool has (Key const &key) const;
00077 void optimize ();
00078 bool is_optimized () const;
00079
00080 public:
00081 std::type_info const &value_type_id() const;
00082
00083 private:
00084 struct entry
00085 {
00086 bool operator==(entry const &other) const;
00087 bool operator< (entry const &other) const;
00088
00089 Key key;
00090 Value value;
00091 };
00092
00093 typedef std::vector<entry> entry_container;
00094
00095 private:
00096 typename entry_container::const_iterator find(Key const &key) const;
00097 typename entry_container::iterator find(Key const &key);
00098
00099 void insert_entry(Key const &key, Value const &value);
00100
00101 private:
00102 entry_container m_entries;
00103 bool m_is_optimized;
00104 bool m_is_inserting;
00105 };
00106
00107 }
00108
00109 #include "attribute_map.inl"
00110
00111 #endif
00112