blob: 7f7f49f1bc700e460f85234520c7537e53757f44 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include <new>
#include "agent.h"
#include "grimoire/trie.h"
namespace marisa {
Agent::Agent() : query_(), key_(), state_() {}
Agent::~Agent() {}
void Agent::set_query(const char *str) {
MARISA_THROW_IF(str == NULL, MARISA_NULL_ERROR);
if (state_.get() != NULL) {
state_->reset();
}
query_.set_str(str);
}
void Agent::set_query(const char *ptr, std::size_t length) {
MARISA_THROW_IF((ptr == NULL) && (length != 0), MARISA_NULL_ERROR);
if (state_.get() != NULL) {
state_->reset();
}
query_.set_str(ptr, length);
}
void Agent::set_query(std::size_t key_id) {
if (state_.get() != NULL) {
state_->reset();
}
query_.set_id(key_id);
}
void Agent::init_state() {
MARISA_THROW_IF(state_.get() != NULL, MARISA_STATE_ERROR);
state_.reset(new (std::nothrow) grimoire::State);
MARISA_THROW_IF(state_.get() == NULL, MARISA_MEMORY_ERROR);
}
void Agent::clear() {
Agent().swap(*this);
}
void Agent::swap(Agent &rhs) {
query_.swap(rhs.query_);
key_.swap(rhs.key_);
state_.swap(rhs.state_);
}
} // namespace marisa
|