mapped_ptr_vector.h
Go to the documentation of this file.
//$$FILE$$
//$$VERSION$$
//$$DATE$$
//$$LICENSE$$
#ifndef MAPPED_PTR_VECTOR_H
#define MAPPED_PTR_VECTOR_H
#include <string>
#include <vector>
#include <map>
template <typename T, typename StringCompareT = std::less<std::string> >
class mapped_ptr_vector
{
private:
// The first integer is the index in _vector
// The second integer is the index in the file
typedef std::map<std::string, std::pair<unsigned int, unsigned int>,
StringCompareT > tIndex;
tIndex _index;
std::vector<T*> _vector;
std::string _currentName;
std::pair<unsigned int, unsigned int> _currentIndices;
bool is_equal(const std::string& first, const std::string& second,
const typename tIndex::key_compare& keyComp) const;
public:
mapped_ptr_vector();
mapped_ptr_vector(const StringCompareT& cmp);
mapped_ptr_vector(const mapped_ptr_vector& inMappedVector);
~mapped_ptr_vector();
void operator=(const mapped_ptr_vector& inMappedVector);
unsigned int size() const;
bool empty() const;
void clear();
bool operator==(const mapped_ptr_vector& inMappedVector);
void push_back(T* inP, const unsigned int fileIndex = 0);
void push_back(const std::string& name, const unsigned int fileIndex = 0);
void push_back(const std::vector<std::string>& names,
const std::vector<unsigned int>& fileIndices);
void push_back(const std::vector<std::string>& names);
void set(T* inP);
T& operator[](unsigned int index);
T& operator[](const std::string& name);
// When not found, returns size()
unsigned int find(const std::string& name);
void rename(const std::string& oldName, const std::string& newName);
void erase(const std::string& name);
bool is_read(const std::string& name);
void read(const std::string& name);
unsigned int write(const std::string& name);
std::pair<unsigned int, unsigned int> get_indices(const std::string& name);
std::string get_name(const unsigned int index);
void get_sorted_indices(std::vector<unsigned int>& sortedIndices);
};
#endif
mapped_ptr_vector
Definition: mapped_ptr_vector.h:30
mapped_ptr_vector::push_back
void push_back(const std::vector< std::string > &names, const std::vector< unsigned int > &fileIndices)
mapped_ptr_vector::get_sorted_indices
void get_sorted_indices(std::vector< unsigned int > &sortedIndices)
Definition: mapped_ptr_vector.C:465
mapped_ptr_vector::empty
bool empty() const
Definition: mapped_ptr_vector.C:87
mapped_ptr_vector::rename
void rename(const std::string &oldName, const std::string &newName)
Definition: mapped_ptr_vector.C:257
mapped_ptr_vector::~mapped_ptr_vector
~mapped_ptr_vector()
Definition: mapped_ptr_vector.C:57
mapped_ptr_vector::set
void set(T *inP)
Associate the object pointer to already entered object name.
Definition: mapped_ptr_vector.C:191
mapped_ptr_vector::size
unsigned int size() const
Definition: mapped_ptr_vector.C:78
mapped_ptr_vector::operator==
bool operator==(const mapped_ptr_vector &inMappedVector)
Definition: mapped_ptr_vector.C:109
mapped_ptr_vector::operator[]
T & operator[](unsigned int index)
Definition: mapped_ptr_vector.C:214
mapped_ptr_vector::erase
void erase(const std::string &name)
Removes object pointer.
Definition: mapped_ptr_vector.C:289
mapped_ptr_vector::is_read
bool is_read(const std::string &name)
Is object de-serialized.
Definition: mapped_ptr_vector.C:330
mapped_ptr_vector::write
unsigned int write(const std::string &name)
Serialize the object.
Definition: mapped_ptr_vector.C:371
mapped_ptr_vector::clear
void clear()
Definition: mapped_ptr_vector.C:96
mapped_ptr_vector::mapped_ptr_vector
mapped_ptr_vector()
Definition: mapped_ptr_vector.C:27
mapped_ptr_vector::operator=
void operator=(const mapped_ptr_vector &inMappedVector)
Definition: mapped_ptr_vector.C:66
mapped_ptr_vector::find
unsigned int find(const std::string &name)
Definition: mapped_ptr_vector.C:246
mapped_ptr_vector::get_name
std::string get_name(const unsigned int index)
Definition: mapped_ptr_vector.C:440
mapped_ptr_vector::operator[]
T & operator[](const std::string &name)
mapped_ptr_vector::push_back
void push_back(const std::vector< std::string > &names)
mapped_ptr_vector::push_back
void push_back(const std::string &name, const unsigned int fileIndex=0)
mapped_ptr_vector::get_indices
std::pair< unsigned int, unsigned int > get_indices(const std::string &name)
Definition: mapped_ptr_vector.C:402
mapped_ptr_vector::push_back
void push_back(T *inP, const unsigned int fileIndex=0)
Definition: mapped_ptr_vector.C:119
mapped_ptr_vector::read
void read(const std::string &name)
De-serialize the object.
Definition: mapped_ptr_vector.C:354