Lucene++ - a full-featured, c++ search engine
API Documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
include
lucene++
Map.h
Go to the documentation of this file.
1
2
// Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3
// Distributable under the terms of either the Apache License (Version 2.0)
4
// or the GNU Lesser General Public License.
6
7
#ifndef MAP_H
8
#define MAP_H
9
10
#include <map>
11
#include "
LuceneSync.h
"
12
13
namespace
Lucene
{
14
16
template
<
class
KEY,
class
VALUE,
class
LESS = std::less<KEY> >
17
class
Map
:
public
LuceneSync
{
18
public
:
19
typedef
Map<KEY, VALUE, LESS>
this_type
;
20
typedef
std::pair<KEY, VALUE>
key_value
;
21
typedef
std::map<KEY, VALUE, LESS>
map_type
;
22
typedef
typename
map_type::iterator
iterator
;
23
typedef
typename
map_type::const_iterator
const_iterator
;
24
typedef
KEY
key_type
;
25
typedef
VALUE
value_type
;
26
27
virtual
~Map
() {
28
}
29
30
protected
:
31
boost::shared_ptr<map_type>
mapContainer
;
32
33
public
:
34
static
this_type
newInstance
() {
35
this_type
instance;
36
instance.
mapContainer
=
Lucene::newInstance<map_type>
();
37
return
instance;
38
}
39
40
void
reset
() {
41
mapContainer
.reset();
42
}
43
44
int32_t
size
()
const
{
45
return
(int32_t)
mapContainer
->size();
46
}
47
48
bool
empty
()
const
{
49
return
mapContainer
->empty();
50
}
51
52
void
clear
() {
53
mapContainer
->clear();
54
}
55
56
iterator
begin
() {
57
return
mapContainer
->begin();
58
}
59
60
iterator
end
() {
61
return
mapContainer
->end();
62
}
63
64
const_iterator
begin
()
const
{
65
return
mapContainer
->begin();
66
}
67
68
const_iterator
end
()
const
{
69
return
mapContainer
->end();
70
}
71
72
operator
bool()
const
{
73
return
mapContainer
.get() != NULL;
74
}
75
76
bool
operator!
()
const
{
77
return
!
mapContainer
;
78
}
79
80
map_type
&
operator=
(
const
map_type
& other) {
81
mapContainer
= other.mapContainer;
82
return
*
this
;
83
}
84
85
void
put
(
const
KEY& key,
const
VALUE& value) {
86
(*mapContainer)[key] = value;
87
}
88
89
template
<
class
ITER>
90
void
putAll
(ITER first, ITER last) {
91
for
(
iterator
current = first; current != last; ++current) {
92
(*mapContainer)[current->first] = current->second;
93
}
94
}
95
96
template
<
class
ITER>
97
void
remove
(ITER pos) {
98
mapContainer
->erase(pos);
99
}
100
101
template
<
class
ITER>
102
ITER
remove
(ITER first, ITER last) {
103
return
mapContainer
->erase(first, last);
104
}
105
106
bool
remove
(
const
KEY& key) {
107
return
(
mapContainer
->erase(key) > 0);
108
}
109
110
iterator
find
(
const
KEY& key) {
111
return
mapContainer
->find(key);
112
}
113
114
VALUE
get
(
const
KEY& key)
const
{
115
iterator
findValue =
mapContainer
->find(key);
116
return
findValue ==
mapContainer
->end() ? VALUE() : findValue->second;
117
}
118
119
bool
contains
(
const
KEY& key)
const
{
120
return
(
mapContainer
->find(key) !=
mapContainer
->end());
121
}
122
123
VALUE&
operator[]
(
const
KEY& key) {
124
return
(*
mapContainer
)[key];
125
}
126
};
127
128
}
129
130
#endif
LuceneSync.h
Lucene::LuceneSync
Base class for all Lucene synchronised classes.
Definition
LuceneSync.h:15
Lucene::Map
Utility template class to handle maps that can be safely copied and shared.
Definition
Map.h:17
Lucene::Map::get
VALUE get(const KEY &key) const
Definition
Map.h:114
Lucene::Map< int64_t, localDataPtr >::this_type
Map< int64_t, localDataPtr, std::less< int64_t > > this_type
Definition
Map.h:19
Lucene::Map::operator[]
VALUE & operator[](const KEY &key)
Definition
Map.h:123
Lucene::Map::putAll
void putAll(ITER first, ITER last)
Definition
Map.h:90
Lucene::Map::size
int32_t size() const
Definition
Map.h:44
Lucene::Map::remove
void remove(ITER pos)
Definition
Map.h:97
Lucene::Map::remove
ITER remove(ITER first, ITER last)
Definition
Map.h:102
Lucene::Map::contains
bool contains(const KEY &key) const
Definition
Map.h:119
Lucene::Map::begin
const_iterator begin() const
Definition
Map.h:64
Lucene::Map< int64_t, localDataPtr >::map_type
std::map< int64_t, localDataPtr, std::less< int64_t > > map_type
Definition
Map.h:21
Lucene::Map::end
iterator end()
Definition
Map.h:60
Lucene::Map< int64_t, localDataPtr >::key_type
int64_t key_type
Definition
Map.h:24
Lucene::Map::put
void put(const KEY &key, const VALUE &value)
Definition
Map.h:85
Lucene::Map::remove
bool remove(const KEY &key)
Definition
Map.h:106
Lucene::Map< int64_t, localDataPtr >::mapContainer
boost::shared_ptr< map_type > mapContainer
Definition
Map.h:31
Lucene::Map< int64_t, localDataPtr >::const_iterator
map_type::const_iterator const_iterator
Definition
Map.h:23
Lucene::Map::reset
void reset()
Definition
Map.h:40
Lucene::Map::~Map
virtual ~Map()
Definition
Map.h:27
Lucene::Map::end
const_iterator end() const
Definition
Map.h:68
Lucene::Map::begin
iterator begin()
Definition
Map.h:56
Lucene::Map::newInstance
static this_type newInstance()
Definition
Map.h:34
Lucene::Map< int64_t, localDataPtr >::value_type
localDataPtr value_type
Definition
Map.h:25
Lucene::Map::operator!
bool operator!() const
Definition
Map.h:76
Lucene::Map::clear
void clear()
Definition
Map.h:52
Lucene::Map::operator=
map_type & operator=(const map_type &other)
Definition
Map.h:80
Lucene::Map::empty
bool empty() const
Definition
Map.h:48
Lucene::Map< int64_t, localDataPtr >::iterator
map_type::iterator iterator
Definition
Map.h:22
Lucene::Map::find
iterator find(const KEY &key)
Definition
Map.h:110
Lucene::Map< int64_t, localDataPtr >::key_value
std::pair< int64_t, localDataPtr > key_value
Definition
Map.h:20
Lucene
Definition
AbstractAllTermDocs.h:12
Lucene::newInstance
boost::shared_ptr< T > newInstance()
Definition
LuceneFactory.h:16
clucene.sourceforge.net