1 #ifndef MARISA_ALPHA_PROGRESS_H_ 2 #define MARISA_ALPHA_PROGRESS_H_ 3 4 #include "base.h" 5 6 namespace marisa_alpha { 7 8 class Progress { 9 public: 10 explicit Progress(int flags); 11 12 bool is_valid() const; is_last()13 bool is_last() const { 14 return (trie_id_ + 1) >= num_tries(); 15 } 16 17 Progress &operator++() { 18 ++trie_id_; 19 return *this; 20 } 21 test_total_size(std::size_t total_size)22 void test_total_size(std::size_t total_size) { 23 MARISA_ALPHA_THROW_IF(total_size_ > (MARISA_ALPHA_UINT32_MAX - total_size), 24 MARISA_ALPHA_SIZE_ERROR); 25 total_size_ += total_size; 26 } 27 flags()28 int flags() const { 29 return flags_; 30 } trie_id()31 int trie_id() const { 32 return trie_id_; 33 } total_size()34 std::size_t total_size() const { 35 return total_size_; 36 } 37 num_tries()38 int num_tries() const { 39 return flags_ & MARISA_ALPHA_NUM_TRIES_MASK; 40 } trie()41 int trie() const { 42 return flags_ & MARISA_ALPHA_TRIE_MASK; 43 } tail()44 int tail() const { 45 return flags_ & MARISA_ALPHA_TAIL_MASK; 46 } order()47 int order() const { 48 return flags_ & MARISA_ALPHA_ORDER_MASK; 49 } 50 51 private: 52 int flags_; 53 int trie_id_; 54 std::size_t total_size_; 55 56 // Disallows copy and assignment. 57 Progress(const Progress &); 58 Progress &operator=(const Progress &); 59 }; 60 61 } // namespace marisa_alpha 62 63 #endif // MARISA_ALPHA_PROGRESS_H_ 64