OpenStructure
Loading...
Searching...
No Matches
build-2.11
stage
include
ost
db
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
35
class
LinearCharacterContainer
;
36
class
LinearPositionContainer
;
37
typedef
boost::shared_ptr<LinearCharacterContainer>
LinearCharacterContainerPtr
;
38
typedef
boost::shared_ptr<LinearPositionContainer>
LinearPositionContainerPtr
;
39
40
41
class
LinearCharacterContainer
{
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
72
PagedArray<char, 1048576>
data_;
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
81
class
LinearPositionContainer
{
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
129
PagedArray<uint64_t, 1048576>
data_;
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
base.hh
geom::Vec3
Three dimensional vector class, using Real precision.
Definition
vec3.hh:48
geom::Vec3List
Definition
vec3.hh:239
ost::PagedArray
Vector style container that splits content in pages, suited for large amounts of data....
Definition
paged_array.hh:39
ost::db::LinearCharacterContainer
Definition
binary_container.hh:41
ost::db::LinearCharacterContainer::GetCharacter
char GetCharacter(uint64_t idx) const
ost::db::LinearCharacterContainer::Save
void Save(const std::string &filename) const
ost::db::LinearCharacterContainer::AddCharacters
void AddCharacters(const std::string &characters)
ost::db::LinearCharacterContainer::LinearCharacterContainer
LinearCharacterContainer()
Definition
binary_container.hh:45
ost::db::LinearCharacterContainer::ClearRange
void ClearRange(std::pair< uint64_t, uint64_t > range)
ost::db::LinearCharacterContainer::GetCharacters
void GetCharacters(std::pair< uint64_t, uint64_t > range, String &s) const
ost::db::LinearCharacterContainer::operator==
bool operator==(const LinearCharacterContainer &other) const
Definition
binary_container.hh:61
ost::db::LinearCharacterContainer::GetNumElements
uint64_t GetNumElements() const
Definition
binary_container.hh:59
ost::db::LinearCharacterContainer::operator!=
bool operator!=(const LinearCharacterContainer &other) const
Definition
binary_container.hh:66
ost::db::LinearCharacterContainer::Load
static LinearCharacterContainerPtr Load(const std::string &filename)
ost::db::LinearPositionContainer
Definition
binary_container.hh:81
ost::db::LinearPositionContainer::GetPositions
void GetPositions(std::pair< uint64_t, uint64_t > range, geom::Vec3List &positions) const
ost::db::LinearPositionContainer::AddPositions
void AddPositions(const geom::Vec3List &positions)
ost::db::LinearPositionContainer::operator!=
bool operator!=(const LinearPositionContainer &other) const
Definition
binary_container.hh:107
ost::db::LinearPositionContainer::Save
void Save(const std::string &filename) const
ost::db::LinearPositionContainer::Load
static LinearPositionContainerPtr Load(const std::string &filename)
ost::db::LinearPositionContainer::LinearPositionContainer
LinearPositionContainer()
Definition
binary_container.hh:85
ost::db::LinearPositionContainer::ClearRange
void ClearRange(std::pair< uint64_t, uint64_t > range)
ost::db::LinearPositionContainer::GetPosition
void GetPosition(uint64_t idx, geom::Vec3 &pos) const
ost::db::LinearPositionContainer::operator==
bool operator==(const LinearPositionContainer &other) const
Definition
binary_container.hh:102
ost::db::LinearPositionContainer::GetNumElements
uint64_t GetNumElements() const
Definition
binary_container.hh:100
String
std::string String
Definition
base.hh:54
ost::db::LinearCharacterContainerPtr
boost::shared_ptr< LinearCharacterContainer > LinearCharacterContainerPtr
Definition
binary_container.hh:37
ost::db::LinearPositionContainerPtr
boost::shared_ptr< LinearPositionContainer > LinearPositionContainerPtr
Definition
binary_container.hh:38
ost
Definition
base.dox:1
paged_array.hh
stdint.hh
uint64_t
unsigned __int64 uint64_t
Definition
stdint_msc.hh:90
vec3.hh
Generated by
1.9.8