ztsdb
dname.hpp
1 // (C) 2015 Leonardo Silvestri
2 //
3 // This file is part of ztsdb.
4 //
5 // ztsdb is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // ztsdb is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with ztsdb. If not, see <http://www.gnu.org/licenses/>.
17 
18 
19 #ifndef DNAME_H
20 #define DNAME_H
21 
22 #include <map>
23 #include <sys/types.h>
24 #include "vector.hpp"
25 #include "string.hpp"
26 
27 
28 namespace arr {
29 
32  struct Dname {
33  Dname(size_t n=0, Vector<zstring>&& names_p=Vector<zstring>());
34 
35  void resize(size_t n, size_t from=0);
36  void assign(size_t i, const std::string& s);
37  void addafter(const std::string& s);
38  void addafter(const Dname& dn);
39  void remove(size_t n, const std::string& nm);
40  void remove(size_t n);
41  void remove(const std::string& nm);
42  void addprefix(const std::string& prefix);
43  bool hasNames() const { return sz && sz == names.size(); }
44 
45  bool operator==(const Dname& d) const;
46  bool operator!=(const Dname& d) { return !(*this == d); }
47  size_t operator[](const std::string& s) const; // if multiple s, returns the first
48  std::string operator[](size_t i) const;
49 
50  inline size_t size() const { return names.size(); }
51 
52  Vector<zstring>::iterator begin() { return names.begin(); }
53  Vector<zstring>::iterator end() { return names.end(); }
54 
55  size_t sz; // the size of the index
56  Vector<zstring> names;
57  std::map<std::string, std::set<size_t>> namesMap;
58  };
59 
60 }
61 
62 #endif
arr::Vector
Definition: vector_base.hpp:103
arr::vector_iterator
Definition: vector_base.hpp:55
arr::Dname
Definition: dname.hpp:32
arr
Contains the classes and functions that implement a multidimentional array type.
Definition: allocator.hpp:29