source: XMLIO_V2/dev/dev_rv/src/XMLIO/container.hpp @ 131

Last change on this file since 131 was 131, checked in by hozdoba, 14 years ago

Début Interface c<->fortran

File size: 3.3 KB
Line 
1#ifndef __XMLIO_CONTAINER__
2#define __XMLIO_CONTAINER__
3
4// Classes utilisées issues de la STL
5using std::vector;
6using std::string;
7using std::pair;
8using std::ostream;
9
10namespace XMLIOSERVER
11{
12   template<class Key, class Mapped, class HashFunc = Poco::Hash<Key> >
13      class ExHashMap
14         : private Poco::HashMap<Key, Mapped*, Poco::Hash<Key> >
15   {
16      public :
17
18         Mapped* operator[] (const Key& kval)
19                     throw (XMLIOUndefinedValueException)
20         {
21            if(!hasMappedValue(kval))
22               throw XMLIOSERVER::XMLIOUndefinedValueException
23                  ("Appel de la méthode ExHashMap::operator["+kval+"] invalide.");
24            return (find(kval)->second);
25         }
26
27         bool hasMappedValue(const Key& kval) const
28         { return (find(kval) != this->end()); }
29
30         const vector<Mapped*>& getVector(void) const
31         { return (this->_elemList); }
32
33         size_t getVectorSize(void) const
34         { return (this->_elemList.size()); }
35
36         size_t getSize(void) const
37         { return (this->size()); }
38
39      public : /* virtual */
40
41         virtual ~ExHashMap(void)
42         {/* Ne rien faire de plus */}
43
44      protected :
45
46         ExHashMap(void)
47            :  Poco::HashMap<Key, Mapped*, Poco::Hash<Key> >(), _elemList()
48         {/* Ne rien faire de plus */}
49
50         bool addValue(const Key& kval, Mapped* const element)
51         {
52            std::pair<typename ExHashMap::Iterator, bool> p = this->insert(make_pair (kval,element));
53            if(!p.second) return (false);
54            return (this->addValue(element));
55         }
56
57         bool addValue(Mapped* const element)
58         {
59            this->_elemList.insert(this->_elemList.end(), element);
60            return (true);
61         }
62
63         void removeValue(const Key& kval) // Non testé
64         {
65            Mapped* element = find(kval)->second;
66            this->removeValue(element);
67            this->erase(kval);
68         }
69
70         void removeValue(const Mapped* element) // Non testé
71         {
72            for (int i = 0; i < this->_elemList.size(); i++)
73               if (*this->_elemList[i] == element )
74                  this->_elemList.erase(this->_elemList.begin()+i);
75
76            delete element;
77         }
78
79      private :
80
81         std::vector<Mapped*> _elemList;
82
83   }; // class ExHashMap
84
85   /////////////////////////////////////////////////////////////
86
87   template<class Mapped>
88      class StrHashMap
89         : public ExHashMap<string, Mapped, Poco::Hash<string> >
90   {
91      public :
92
93         StrHashMap(void)
94            :  ExHashMap<string, Mapped, Poco::Hash<string> >()
95         {/* Ne rien faire de plus */}
96
97         bool addObject(Mapped* element)
98         {
99            if(element->hasId())
100               return(addValue(element->getId(), element));
101            return(addValue(element));
102         }
103
104         bool removeObject(const string& kval)
105         {
106            if(!ExHashMap<string, Mapped, Poco::Hash<string> >::hasMappedValue(kval)) return (false);
107            ExHashMap<string, Mapped, Poco::Hash<string> >::removeValue(kval); return (true);
108         }
109
110      public : /* virtual */
111
112         virtual ~StrHashMap(void)
113         {/* Ne rien faire de plus */}
114
115   }; // class StrHashMap
116
117} // namespace XMLIOSERVER
118
119#endif // __XMLIO_CONTAINER__
Note: See TracBrowser for help on using the repository browser.