libzypp
17.14.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Map.cc
Go to the documentation of this file.
1
/*---------------------------------------------------------------------\
2
| ____ _ __ __ ___ |
3
| |__ / \ / / . \ . \ |
4
| / / \ V /| _/ _/ |
5
| / /__ | | | | | | |
6
| /_____||_| |_| |_| |
7
| |
8
\---------------------------------------------------------------------*/
11
extern
"C"
12
{
13
#include <solv/bitmap.h>
14
}
15
#include <iostream>
16
#include <exception>
17
#include "
zypp/base/LogTools.h
"
18
#include "
zypp/base/String.h
"
19
20
#include "
zypp/sat/Map.h
"
21
#include "
zypp/sat/Pool.h
"
22
23
using
std::endl;
24
26
namespace
zypp
27
{
28
29
template
<>
30
sat::detail::CMap
* rwcowClone<sat::detail::CMap>(
const
sat::detail::CMap
* rhs )
31
{
32
sat::detail::CMap
* ret =
new
sat::detail::CMap
;
33
::map_init_clone( ret, const_cast<sat::detail::CMap *>(rhs) );
34
return
ret;
35
}
36
38
namespace
sat
39
{
40
41
constexpr Map::PoolSizeType
Map::poolSize
;
42
43
Map::Map
()
44
: _pimpl( new detail::
CMap
)
45
{ ::map_init(
_pimpl
.
get
(), 0 ); }
46
47
Map::Map
(
size_type
size_r )
48
: _pimpl( new detail::
CMap
)
49
{ ::map_init(
_pimpl
.
get
(), size_r ); }
50
51
Map::Map
(
PoolSizeType
)
52
: _pimpl( new detail::
CMap
)
53
{ ::map_init(
_pimpl
.
get
(),
Pool::instance
().
capacity
() ); }
54
55
Map::~Map
()
56
{ ::map_free(
_pimpl
.
get
() ); }
57
58
bool
Map::empty
()
const
59
{
return
(
_pimpl
->size == 0 ); }
60
61
Map::size_type
Map::size
()
const
62
{
return
_pimpl
->size << 3; }
63
64
void
Map::grow
(
size_type
size_r )
65
{ ::map_grow(
_pimpl
.
get
(), size_r ); }
66
67
void
Map::setAll
()
68
{
assignAll
(
true
); }
69
70
void
Map::clearAll
()
71
{
assignAll
(
false
); }
72
73
void
Map::assignAll
(
bool
val_r )
74
{
75
if
(
_pimpl
->size )
76
::memset(
_pimpl
->map, (val_r?-1:0),
_pimpl
->size );
77
}
78
79
#define M_RANGE_CKECK(IDX,LOC) if ( ((IDX) >> 3) >= size_type(_pimpl->size) ) throw std::out_of_range( "zypp::sat::Map::" LOC )
80
81
void
Map::set
(
size_type
idx_r )
82
{
83
M_RANGE_CKECK
( idx_r,
"set"
);
84
MAPSET(
_pimpl
, idx_r );
85
}
86
87
void
Map::clear
(
size_type
idx_r )
88
{
89
M_RANGE_CKECK
( idx_r,
"clear"
);
90
MAPCLR(
_pimpl
, idx_r );
91
}
92
93
void
Map::assign
(
size_type
idx_r,
bool
val_r )
94
{
95
M_RANGE_CKECK
( idx_r,
"assign"
);
96
if
( val_r )
97
{ MAPSET(
_pimpl
, idx_r ); }
98
else
99
{ MAPCLR(
_pimpl
, idx_r ); }
100
}
101
102
bool
Map::test
(
size_type
idx_r )
const
103
{
104
M_RANGE_CKECK
( idx_r,
"test"
);
105
return
MAPTST(
_pimpl
, idx_r );
106
}
107
108
std::string
Map::asString
(
const
char
on_r,
const
char
off_r )
const
109
{
110
if
(
empty
() )
111
return
std::string();
112
113
std::string ret(
size
(), off_r );
114
for_
( idx,
size_type
(0),
size
() )
115
{
116
if
(
test
( idx ) )
117
ret[idx] = on_r;
118
}
119
return
ret;
120
}
121
122
Map::operator
detail::CMap
*()
// COW: nonconst version can't be inlined
123
{
return
_pimpl.get(); }
// without exposing detail::CMap
124
125
bool
operator==
(
const
Map
& lhs,
const
Map
& rhs )
126
{
127
const
detail::CMap
* l = lhs;
128
const
detail::CMap
* r = rhs;
129
return
( l == r || ( l->size == r->size && ::memcmp( l->map, r->map, l->size ) == 0 ) );
130
}
131
133
}
// namespace sat
136
}
// namespace zypp
zypp
sat
Map.cc
Generated by
1.8.2