1 #ifndef MARISA_AGENT_H_
2 #define MARISA_AGENT_H_
3 
4 #include "marisa/key.h"
5 #include "marisa/query.h"
6 
7 namespace marisa {
8 namespace grimoire {
9 namespace trie {
10 
11 class State;
12 
13 }  // namespace trie
14 }  // namespace grimoire
15 
16 class Agent {
17  public:
18   Agent();
19   ~Agent();
20 
query()21   const Query &query() const {
22     return query_;
23   }
key()24   const Key &key() const {
25     return key_;
26   }
27 
28   void set_query(const char *str);
29   void set_query(const char *ptr, std::size_t length);
30   void set_query(std::size_t key_id);
31 
state()32   const grimoire::trie::State &state() const {
33     return *state_;
34   }
state()35   grimoire::trie::State &state() {
36     return *state_;
37   }
38 
set_key(const char * str)39   void set_key(const char *str) {
40     MARISA_DEBUG_IF(str == NULL, MARISA_NULL_ERROR);
41     key_.set_str(str);
42   }
set_key(const char * ptr,std::size_t length)43   void set_key(const char *ptr, std::size_t length) {
44     MARISA_DEBUG_IF((ptr == NULL) && (length != 0), MARISA_NULL_ERROR);
45     MARISA_DEBUG_IF(length > MARISA_UINT32_MAX, MARISA_SIZE_ERROR);
46     key_.set_str(ptr, length);
47   }
set_key(std::size_t id)48   void set_key(std::size_t id) {
49     MARISA_DEBUG_IF(id > MARISA_UINT32_MAX, MARISA_SIZE_ERROR);
50     key_.set_id(id);
51   }
52 
has_state()53   bool has_state() const {
54     return state_.get() != NULL;
55   }
56   void init_state();
57 
58   void clear();
59   void swap(Agent &rhs);
60 
61  private:
62   Query query_;
63   Key key_;
64   scoped_ptr<grimoire::trie::State> state_;
65 
66   // Disallows copy and assignment.
67   Agent(const Agent &);
68   Agent &operator=(const Agent &);
69 };
70 
71 }  // namespace marisa
72 
73 #endif  // MARISA_AGENT_H_
74