OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
binary_container.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 
20 
21 #ifndef OST_DB_LINEAR_BINARY_CONTAINER_HH
22 #define OST_DB_LINEAR_BINARY_CONTAINER_HH
23 
24 #include <vector>
25 #include <boost/shared_ptr.hpp>
26 #include <ost/base.hh>
27 #include <ost/stdint.hh>
28 #include <ost/geom/vec3.hh>
29 #include <ost/paged_array.hh>
30 
31 
32 namespace ost { namespace db {
33 
34 
37 typedef boost::shared_ptr<LinearCharacterContainer> LinearCharacterContainerPtr;
38 typedef boost::shared_ptr<LinearPositionContainer> LinearPositionContainerPtr;
39 
40 
42 
43 public:
44 
45  LinearCharacterContainer(): num_elements_(0) { }
46 
47  static LinearCharacterContainerPtr Load(const std::string& filename);
48 
49  void Save(const std::string& filename) const;
50 
51  void AddCharacters(const std::string& characters);
52 
53  void ClearRange(std::pair<uint64_t, uint64_t> range);
54 
55  char GetCharacter(uint64_t idx) const;
56 
57  void GetCharacters(std::pair<uint64_t, uint64_t> range, String& s) const;
58 
59  uint64_t GetNumElements() const { return num_elements_; }
60 
61  bool operator==(const LinearCharacterContainer& other) const {
62  return data_ == other.data_; // no check for num_elements_
63  // they are coupled anyway
64  }
65 
66  bool operator!=(const LinearCharacterContainer& other) const {
67  return !(*this == other);
68  }
69 
70 private:
71 
73  // we track number of entries manually for fast checking of indices
74  // the .size() function of data_ is too slow
75  uint64_t num_elements_;
76 };
77 
78 
79 
80 
82 
83 public:
84 
85  LinearPositionContainer(): num_elements_(0) { }
86 
87  static LinearPositionContainerPtr Load(const std::string& filename);
88 
89  void Save(const std::string& filename) const;
90 
91  void AddPositions(const geom::Vec3List& positions);
92 
93  void ClearRange(std::pair<uint64_t, uint64_t> range);
94 
95  void GetPosition(uint64_t idx, geom::Vec3& pos) const;
96 
97  void GetPositions(std::pair<uint64_t, uint64_t> range,
98  geom::Vec3List& positions) const;
99 
100  uint64_t GetNumElements() const { return num_elements_; }
101 
102  bool operator==(const LinearPositionContainer& other) const {
103  return data_ == other.data_; // no check for num_elements_
104  // they are coupled anyway
105  }
106 
107  bool operator!=(const LinearPositionContainer& other) const {
108  return !(*this == other);
109  }
110 
111 private:
112 
113  // 21 bits starting at index 1 are set
114  static const uint64_t X_POS_MASK = 9223367638808264704;
115  static const int X_POS_SHIFT = 42;
116 
117  // 21 bits starting at index 22 are set
118  static const uint64_t Y_POS_MASK = 4398044413952;
119  static const int Y_POS_SHIFT = 21;
120 
121  // 21 bits starting at index 43 (the last 21 bits) are set
122  static const uint64_t Z_POS_MASK = 2097151;
123  static const int Z_POS_SHIFT = 0;
124 
125  // range that can be represented as 21 bit integer
126  static const int CUSTOM_INT_MIN = -1048576;
127  static const int CUSTOM_INT_MAX = 1048576;
128 
130  // we track number of entries manually for fast checking of indices
131  // the .size() function of data_ is too slow
132  uint64_t num_elements_;
133 };
134 
135 
136 }} //ns
137 
138 #endif
void Save(const std::string &filename) const
char GetCharacter(uint64_t idx) const
std::string String
Definition: base.hh:54
void GetPositions(std::pair< uint64_t, uint64_t > range, geom::Vec3List &positions) const
bool operator!=(const LinearPositionContainer &other) const
static LinearPositionContainerPtr Load(const std::string &filename)
bool operator==(const LinearCharacterContainer &other) const
void GetPosition(uint64_t idx, geom::Vec3 &pos) const
unsigned __int64 uint64_t
Definition: stdint_msc.hh:90
bool operator!=(const LinearCharacterContainer &other) const
void ClearRange(std::pair< uint64_t, uint64_t > range)
void AddPositions(const geom::Vec3List &positions)
void AddCharacters(const std::string &characters)
static LinearCharacterContainerPtr Load(const std::string &filename)
void GetCharacters(std::pair< uint64_t, uint64_t > range, String &s) const
boost::shared_ptr< LinearPositionContainer > LinearPositionContainerPtr
boost::shared_ptr< LinearCharacterContainer > LinearCharacterContainerPtr
Three dimensional vector class, using Real precision.
Definition: vec3.hh:43
bool operator==(const LinearPositionContainer &other) const
void ClearRange(std::pair< uint64_t, uint64_t > range)
void Save(const std::string &filename) const