Lucene++ - a full-featured, c++ search engine
API Documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
include
lucene++
Array.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 ARRAY_H
8
#define ARRAY_H
9
10
#include <cstring>
11
#include "Lucene.h"
12
13
namespace
Lucene
{
14
15
template
<
typename
TYPE>
16
class
ArrayData
{
17
public
:
18
ArrayData
(int32_t size_) {
19
data
= NULL;
20
resize
(size_);
21
}
22
23
~ArrayData
() {
24
resize
(0);
25
}
26
27
public
:
28
TYPE*
data
;
29
int32_t
size
;
30
31
public
:
32
void
resize
(int32_t size_) {
33
if
(size_ == 0) {
34
FreeMemory
(
data
);
35
data
= NULL;
36
}
else
if
(
data
== NULL) {
37
data
= (TYPE*)
AllocMemory
(size_ *
sizeof
(TYPE));
38
}
else
{
39
data
= (TYPE*)
ReallocMemory
(
data
, size_ *
sizeof
(TYPE));
40
}
41
this->size = size_;
42
}
43
};
44
46
template
<
typename
TYPE>
47
class
Array
{
48
public
:
49
typedef
Array<TYPE>
this_type
;
50
typedef
ArrayData<TYPE>
array_type
;
51
52
Array
() {
53
array
= NULL;
54
}
55
56
protected
:
57
boost::shared_ptr<array_type>
container
;
58
array_type
*
array
;
59
60
public
:
61
static
this_type
newInstance
(int32_t
size
) {
62
this_type
instance;
63
instance.
container
=
Lucene::newInstance<array_type>
(
size
);
64
instance.
array
= instance.
container
.get();
65
return
instance;
66
}
67
68
void
reset
() {
69
resize
(0);
70
}
71
72
void
resize
(int32_t
size
) {
73
if
(
size
== 0) {
74
container
.reset();
75
}
else
if
(!
container
) {
76
container
=
Lucene::newInstance<array_type>
(
size
);
77
}
else
{
78
container
->resize(
size
);
79
}
80
array
=
container
.get();
81
}
82
83
TYPE*
get
()
const
{
84
return
array
->data;
85
}
86
87
int32_t
size
()
const
{
88
return
array
->size;
89
}
90
91
bool
equals
(
const
this_type
& other)
const
{
92
if
(
array
->size != other.
array
->
size
) {
93
return
false
;
94
}
95
return
(std::memcmp(
array
->data, other.
array
->
data
,
array
->size) == 0);
96
}
97
98
int32_t
hashCode
()
const
{
99
return
(int32_t)(int64_t)
array
;
100
}
101
102
TYPE&
operator[]
(int32_t i)
const
{
103
return
array
->data[i];
104
}
105
106
operator
bool ()
const
{
107
return
container
.get() != NULL;
108
}
109
110
bool
operator!
()
const
{
111
return
!
container
;
112
}
113
114
bool
operator==
(
const
Array<TYPE>
& other) {
115
return
(
container
== other.
container
);
116
}
117
118
bool
operator!=
(
const
Array<TYPE>
& other) {
119
return
(
container
!= other.
container
);
120
}
121
};
122
123
template
<
class
TYPE>
124
inline
std::size_t
hash_value
(
const
Array<TYPE>
& value) {
125
return
(std::size_t)value.
hashCode
();
126
}
127
128
template
<
class
TYPE>
129
inline
bool
operator==
(
const
Array<TYPE>
& value1,
const
Array<TYPE>
& value2) {
130
return
(value1.
hashCode
() == value2.
hashCode
());
131
}
132
133
}
134
135
#endif
Lucene::ArrayData
Definition
Array.h:16
Lucene::ArrayData::ArrayData
ArrayData(int32_t size_)
Definition
Array.h:18
Lucene::ArrayData::resize
void resize(int32_t size_)
Definition
Array.h:32
Lucene::ArrayData::~ArrayData
~ArrayData()
Definition
Array.h:23
Lucene::ArrayData::size
int32_t size
Definition
Array.h:29
Lucene::ArrayData::data
TYPE * data
Definition
Array.h:28
Lucene::Array
Utility template class to handle sharable arrays of simple data types.
Definition
Array.h:47
Lucene::Array::operator!
bool operator!() const
Definition
Array.h:110
Lucene::Array::operator!=
bool operator!=(const Array< TYPE > &other)
Definition
Array.h:118
Lucene::Array::array_type
ArrayData< TYPE > array_type
Definition
Array.h:50
Lucene::Array::reset
void reset()
Definition
Array.h:68
Lucene::Array::operator[]
TYPE & operator[](int32_t i) const
Definition
Array.h:102
Lucene::Array::Array
Array()
Definition
Array.h:52
Lucene::Array::resize
void resize(int32_t size)
Definition
Array.h:72
Lucene::Array::operator==
bool operator==(const Array< TYPE > &other)
Definition
Array.h:114
Lucene::Array::equals
bool equals(const this_type &other) const
Definition
Array.h:91
Lucene::Array::size
int32_t size() const
Definition
Array.h:87
Lucene::Array::newInstance
static this_type newInstance(int32_t size)
Definition
Array.h:61
Lucene::Array::array
array_type * array
Definition
Array.h:58
Lucene::Array::this_type
Array< TYPE > this_type
Definition
Array.h:49
Lucene::Array::container
boost::shared_ptr< array_type > container
Definition
Array.h:57
Lucene::Array::hashCode
int32_t hashCode() const
Definition
Array.h:98
Lucene::Array::get
TYPE * get() const
Definition
Array.h:83
Lucene
Definition
AbstractAllTermDocs.h:12
Lucene::AllocMemory
LPPAPI void * AllocMemory(size_t size)
Allocate block of memory.
Lucene::hash_value
std::size_t hash_value(const Array< TYPE > &value)
Definition
Array.h:124
Lucene::newInstance
boost::shared_ptr< T > newInstance()
Definition
LuceneFactory.h:16
Lucene::ReallocMemory
LPPAPI void * ReallocMemory(void *memory, size_t size)
Reallocate a given block of memory.
Lucene::FreeMemory
LPPAPI void FreeMemory(void *memory)
Release a given block of memory.
Lucene::operator==
bool operator==(const Array< TYPE > &value1, const Array< TYPE > &value2)
Definition
Array.h:129
clucene.sourceforge.net