librcsb-core-wrapper  1.000
mapped_ptr_vector.h
Go to the documentation of this file.
1 //$$FILE$$
2 //$$VERSION$$
3 //$$DATE$$
4 //$$LICENSE$$
5 
6 
12 #ifndef MAPPED_PTR_VECTOR_H
13 #define MAPPED_PTR_VECTOR_H
14 
15 
16 #include <string>
17 #include <vector>
18 #include <map>
19 
20 
28 template <typename T, typename StringCompareT = std::less<std::string> >
30 {
31  private:
32  // The first integer is the index in _vector
33  // The second integer is the index in the file
34  typedef std::map<std::string, std::pair<unsigned int, unsigned int>,
35  StringCompareT > tIndex;
36 
37  tIndex _index;
38 
39  std::vector<T*> _vector;
40 
41  std::string _currentName;
42  std::pair<unsigned int, unsigned int> _currentIndices;
43 
44  bool is_equal(const std::string& first, const std::string& second,
45  const typename tIndex::key_compare& keyComp) const;
46 
47  public:
49  mapped_ptr_vector(const StringCompareT& cmp);
50  mapped_ptr_vector(const mapped_ptr_vector& inMappedVector);
52 
53  void operator=(const mapped_ptr_vector& inMappedVector);
54 
55  unsigned int size() const;
56  bool empty() const;
57  void clear();
58 
59  bool operator==(const mapped_ptr_vector& inMappedVector);
60 
61  void push_back(T* inP, const unsigned int fileIndex = 0);
62  void push_back(const std::string& name, const unsigned int fileIndex = 0);
63  void push_back(const std::vector<std::string>& names,
64  const std::vector<unsigned int>& fileIndices);
65  void push_back(const std::vector<std::string>& names);
66 
68  void set(T* inP);
69 
70  T& operator[](unsigned int index);
71  T& operator[](const std::string& name);
72 
73  // When not found, returns size()
74  unsigned int find(const std::string& name);
75 
76  void rename(const std::string& oldName, const std::string& newName);
77 
79  void erase(const std::string& name);
80 
82  bool is_read(const std::string& name);
83 
85  void read(const std::string& name);
86 
88  unsigned int write(const std::string& name);
89 
90  std::pair<unsigned int, unsigned int> get_indices(const std::string& name);
91  std::string get_name(const unsigned int index);
92  void get_sorted_indices(std::vector<unsigned int>& sortedIndices);
93 };
94 
95 
96 #endif