LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
DoubleAccessObjectToIdMap.h
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#ifndef DOUBLEACCESSOBJECTTOIDMAP_H
7#define DOUBLEACCESSOBJECTTOIDMAP_H
8
9#include <map>
10#include <vector>
11#include "common/LimaCommon.h"
12#include "common/Data/strwstrtools.h" // to be removed (just for debug)
13
14namespace Lima {
15namespace Common {
16namespace Misc {
17
18// comparison functions for pointers (for insertion in map)
19template<typename Object>
21 public:
22 bool operator()(const Object* o1, const Object* o2) const {
23 return (*o1 < *o2);
24 }
25};
26
36template<typename Object, typename Id>
38{
39 public:
40 typedef std::map<const Object*,Id,CompareObjectPtr<Object> > AccessMap;
41 typedef std::vector<const Object*> ReverseAccessMap;
42
43
46
53 const Object& get(const Id&) const;
54 const Id& get(const Object&) const;
62 bool hasId(const Id&) const;
63 bool hasValue(const Object&) const;
70 Id insert(const Object&);
71
75 Id& operator[](const Object&);
76 Object& operator[](const Id&);
79 const AccessMap& getAccessMap() const
80 { return m_accessMap; }
82 { return m_reverseAccessMap; }
83
87 /*class iterator;
88
89 iterator begin();
90 iterator end();
91 iterator find(const Object& val);
92 iterator find(const Id& val);
93 */
94
95 private:
96 // object in map must be a pointer because otherwise,
97 // map may change allocation of its elements when inserting
98 // new elements => pointers in vectors become invalid
99 //
100 AccessMap m_accessMap;
101 ReverseAccessMap m_reverseAccessMap;
102};
103
104#include "DoubleAccessObjectToIdMap.tcc"
105
106
107} // end namespace
108} // end namespace
109} // end namespace
110
111#endif
bool operator()(const Object *o1, const Object *o2) const
storage for double access: from object to id and from id to object : id must be integer.
Id insert(const Object &)
insert an object if not already inserted
std::map< const Object *, Id, CompareObjectPtr< Object > > AccessMap
const Id & get(const Object &) const
const Object & get(const Id &) const
NAUTITIA.