Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
portable_storage_base.h
Go to the documentation of this file.
1
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
2
// All rights reserved.
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
6
// * Redistributions of source code must retain the above copyright
7
// notice, this list of conditions and the following disclaimer.
8
// * Redistributions in binary form must reproduce the above copyright
9
// notice, this list of conditions and the following disclaimer in the
10
// documentation and/or other materials provided with the distribution.
11
// * Neither the name of the Andrey N. Sabelnikov nor the
12
// names of its contributors may be used to endorse or promote products
13
// derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
19
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
//
26
27
28
29
#pragma once
30
31
#include <boost/variant.hpp>
32
#include <boost/any.hpp>
33
#include <string>
34
#include <vector>
35
#include <deque>
36
37
#define PORTABLE_STORAGE_SIGNATUREA 0x01011101
38
#define PORTABLE_STORAGE_SIGNATUREB 0x01020101
// bender's nightmare
39
#define PORTABLE_STORAGE_FORMAT_VER 1
40
41
#define PORTABLE_RAW_SIZE_MARK_MASK 0x03
42
#define PORTABLE_RAW_SIZE_MARK_BYTE 0
43
#define PORTABLE_RAW_SIZE_MARK_WORD 1
44
#define PORTABLE_RAW_SIZE_MARK_DWORD 2
45
#define PORTABLE_RAW_SIZE_MARK_INT64 3
46
47
#ifndef MAX_STRING_LEN_POSSIBLE
48
#define MAX_STRING_LEN_POSSIBLE 2000000000
//do not let string be so big
49
#endif
50
51
//data types
52
#define SERIALIZE_TYPE_INT64 1
53
#define SERIALIZE_TYPE_INT32 2
54
#define SERIALIZE_TYPE_INT16 3
55
#define SERIALIZE_TYPE_INT8 4
56
#define SERIALIZE_TYPE_UINT64 5
57
#define SERIALIZE_TYPE_UINT32 6
58
#define SERIALIZE_TYPE_UINT16 7
59
#define SERIALIZE_TYPE_UINT8 8
60
#define SERIALIZE_TYPE_DUOBLE 9
61
#define SERIALIZE_TYPE_STRING 10
62
#define SERIALIZE_TYPE_BOOL 11
63
#define SERIALIZE_TYPE_OBJECT 12
64
#define SERIALIZE_TYPE_ARRAY 13
65
66
#define SERIALIZE_FLAG_ARRAY 0x80
67
68
69
namespace
epee
70
{
71
namespace
serialization
72
{
73
struct
section;
74
75
template
<
typename
T>
struct
entry_container
{
typedef
std::vector<T>
type
;
static
void
reserve
(
type
&t,
size_t
n) { t.reserve(n); } };
76
template
<>
struct
entry_container
<bool> {
typedef
std::deque<bool>
type
;
static
void
reserve
(
type
&t,
size_t
n) {} };
77
78
/************************************************************************/
79
/* */
80
/************************************************************************/
81
template
<
class
t_entry_type>
82
struct
array_entry_t
83
{
84
array_entry_t
():
m_it
(
m_array
.end()){}
85
array_entry_t
(
const
array_entry_t
& other):
m_array
(other.
m_array
),
m_it
(
m_array
.end()){}
86
87
const
t_entry_type*
get_first_val
()
const
88
{
89
m_it
=
m_array
.begin();
90
return
get_next_val
();
91
}
92
93
t_entry_type*
get_first_val
()
94
{
95
m_it
=
m_array
.begin();
96
return
get_next_val
();
97
}
98
99
100
const
t_entry_type*
get_next_val
()
const
101
{
102
if
(
m_it
==
m_array
.end())
103
return
nullptr
;
104
return
&(*(
m_it
++));
105
}
106
107
t_entry_type*
get_next_val
()
108
{
109
if
(
m_it
==
m_array
.end())
110
return
nullptr
;
111
return
(t_entry_type*)&(*(
m_it
++));
//fuckoff
112
}
113
114
t_entry_type&
insert_first_val
(
const
t_entry_type& v)
115
{
116
m_array
.clear();
117
m_it
=
m_array
.end();
118
return
insert_next_value
(v);
119
}
120
121
t_entry_type&
insert_next_value
(
const
t_entry_type& v)
122
{
123
m_array
.push_back(v);
124
return
m_array
.back();
125
}
126
127
void
reserve
(
size_t
n)
128
{
129
entry_container<t_entry_type>::reserve
(
m_array
, n);
130
}
131
132
typename
entry_container<t_entry_type>::type
m_array
;
133
mutable
typename
entry_container<t_entry_type>::type::const_iterator
m_it
;
134
};
135
136
137
typedef
boost::make_recursive_variant<
138
array_entry_t<section>
,
139
array_entry_t<uint64_t>
,
140
array_entry_t<uint32_t>
,
141
array_entry_t<uint16_t>
,
142
array_entry_t<uint8_t>
,
143
array_entry_t<int64_t>
,
144
array_entry_t<int32_t>
,
145
array_entry_t<int16_t>
,
146
array_entry_t<int8_t>
,
147
array_entry_t<double>
,
148
array_entry_t<bool>
,
149
array_entry_t<std::string>
,
150
array_entry_t<section>
,
151
array_entry_t<boost::recursive_variant_>
152
>::type
array_entry
;
153
154
typedef
boost::variant<uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string, section, array_entry>
storage_entry
;
155
156
typedef
std::string
binarybuffer
;
//it's ok
157
158
/************************************************************************/
159
/* */
160
/************************************************************************/
161
struct
section
162
{
163
std::map<std::string, storage_entry>
m_entries
;
164
};
165
166
//handle-like aliases
167
typedef
section
*
hsection
;
168
typedef
array_entry
*
harray
;
169
}
170
}
epee::serialization::hsection
section * hsection
Definition
portable_storage_base.h:167
epee::serialization::binarybuffer
std::string binarybuffer
Definition
portable_storage_base.h:156
epee::serialization::storage_entry
boost::variant< uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string, section, array_entry > storage_entry
Definition
portable_storage_base.h:154
epee::serialization::array_entry
boost::make_recursive_variant< array_entry_t< section >, array_entry_t< uint64_t >, array_entry_t< uint32_t >, array_entry_t< uint16_t >, array_entry_t< uint8_t >, array_entry_t< int64_t >, array_entry_t< int32_t >, array_entry_t< int16_t >, array_entry_t< int8_t >, array_entry_t< double >, array_entry_t< bool >, array_entry_t< std::string >, array_entry_t< section >, array_entry_t< boost::recursive_variant_ > >::type array_entry
Definition
portable_storage_base.h:152
epee::serialization::harray
array_entry * harray
Definition
portable_storage_base.h:168
epee
Definition
ado_db_helper.h:67
serialization
Definition
binary_utils.h:37
epee::serialization::array_entry_t
Definition
portable_storage_base.h:83
epee::serialization::array_entry_t::get_next_val
t_entry_type * get_next_val()
Definition
portable_storage_base.h:107
epee::serialization::array_entry_t::reserve
void reserve(size_t n)
Definition
portable_storage_base.h:127
epee::serialization::array_entry_t::array_entry_t
array_entry_t()
Definition
portable_storage_base.h:84
epee::serialization::array_entry_t::get_first_val
t_entry_type * get_first_val()
Definition
portable_storage_base.h:93
epee::serialization::array_entry_t::insert_next_value
t_entry_type & insert_next_value(const t_entry_type &v)
Definition
portable_storage_base.h:121
epee::serialization::array_entry_t::m_it
entry_container< t_entry_type >::type::const_iterator m_it
Definition
portable_storage_base.h:133
epee::serialization::array_entry_t::get_first_val
const t_entry_type * get_first_val() const
Definition
portable_storage_base.h:87
epee::serialization::array_entry_t::insert_first_val
t_entry_type & insert_first_val(const t_entry_type &v)
Definition
portable_storage_base.h:114
epee::serialization::array_entry_t::get_next_val
const t_entry_type * get_next_val() const
Definition
portable_storage_base.h:100
epee::serialization::array_entry_t::m_array
entry_container< t_entry_type >::type m_array
Definition
portable_storage_base.h:132
epee::serialization::array_entry_t::array_entry_t
array_entry_t(const array_entry_t &other)
Definition
portable_storage_base.h:85
epee::serialization::entry_container< bool >::type
std::deque< bool > type
Definition
portable_storage_base.h:76
epee::serialization::entry_container< bool >::reserve
static void reserve(type &t, size_t n)
Definition
portable_storage_base.h:76
epee::serialization::entry_container
Definition
portable_storage_base.h:75
epee::serialization::entry_container::reserve
static void reserve(type &t, size_t n)
Definition
portable_storage_base.h:75
epee::serialization::entry_container::type
std::vector< T > type
Definition
portable_storage_base.h:75
epee::serialization::section
Definition
portable_storage_base.h:162
epee::serialization::section::m_entries
std::map< std::string, storage_entry > m_entries
Definition
portable_storage_base.h:163
contrib
epee
include
storages
portable_storage_base.h
Generated on
for Electroneum by
1.17.0