Sha256: c3b800892783a65ed697974edc76ec5e6d996a0db4998ca254e0ba3a9c0208f2

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

#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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
melisa-0.2.5 ext/marisa-0.2.4/lib/marisa/agent.cc
melisa-0.2.4 ext/marisa-0.2.4/lib/marisa/agent.cc
melisa-0.2.3 ext/marisa-0.2.4/lib/marisa/agent.cc
melisa-0.2.2 ext/marisa-0.2.4/lib/marisa/agent.cc
melisa-0.2.1 ext/marisa-0.2.4/lib/marisa/agent.cc
melisa-0.2.0 ext/marisa-0.2.4/lib/marisa/agent.cc