librcsb-core-wrapper 1.005
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
28template <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
Definition: mapped_ptr_vector.h:30
void push_back(const std::vector< std::string > &names, const std::vector< unsigned int > &fileIndices)
void get_sorted_indices(std::vector< unsigned int > &sortedIndices)
Definition: mapped_ptr_vector.C:465
T & operator[](const std::string &name)
bool empty() const
Definition: mapped_ptr_vector.C:87
void rename(const std::string &oldName, const std::string &newName)
Definition: mapped_ptr_vector.C:257
~mapped_ptr_vector()
Definition: mapped_ptr_vector.C:57
void set(T *inP)
Associate the object pointer to already entered object name.
Definition: mapped_ptr_vector.C:191
unsigned int size() const
Definition: mapped_ptr_vector.C:78
bool operator==(const mapped_ptr_vector &inMappedVector)
Definition: mapped_ptr_vector.C:109
T & operator[](unsigned int index)
Definition: mapped_ptr_vector.C:214
void erase(const std::string &name)
Removes object pointer.
Definition: mapped_ptr_vector.C:289
bool is_read(const std::string &name)
Is object de-serialized.
Definition: mapped_ptr_vector.C:330
unsigned int write(const std::string &name)
Serialize the object.
Definition: mapped_ptr_vector.C:371
void clear()
Definition: mapped_ptr_vector.C:96
mapped_ptr_vector()
Definition: mapped_ptr_vector.C:27
void operator=(const mapped_ptr_vector &inMappedVector)
Definition: mapped_ptr_vector.C:66
unsigned int find(const std::string &name)
Definition: mapped_ptr_vector.C:246
std::string get_name(const unsigned int index)
Definition: mapped_ptr_vector.C:440
void push_back(const std::vector< std::string > &names)
void push_back(const std::string &name, const unsigned int fileIndex=0)
std::pair< unsigned int, unsigned int > get_indices(const std::string &name)
Definition: mapped_ptr_vector.C:402
void push_back(T *inP, const unsigned int fileIndex=0)
Definition: mapped_ptr_vector.C:119
void read(const std::string &name)
De-serialize the object.
Definition: mapped_ptr_vector.C:354