0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RangeSpec.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #ifndef Hypertable_Lib_RangeSpec_h
28 #define Hypertable_Lib_RangeSpec_h
29 
30 #include <Common/Serializable.h>
31 
32 #include <string>
33 
34 namespace Hypertable {
35 
38 
40  class RangeSpec : public Serializable {
41  public:
42  enum Type {
43  ROOT=0,
45  SYSTEM=2,
46  USER=3,
48  };
49  static std::string type_str(int type);
50  RangeSpec() : start_row(0), end_row(0) { return; }
51  RangeSpec(const char *start, const char *end)
52  : start_row(start), end_row(end) {}
53  RangeSpec(const uint8_t **bufp, size_t *remainp) { decode(bufp, remainp); }
54  virtual ~RangeSpec() { }
55  bool operator==(const RangeSpec &other) const;
56  bool operator!=(const RangeSpec &other) const;
57  bool operator<(const RangeSpec &other) const;
58 
59  const char *start_row;
60  const char *end_row;
61 
62  protected:
63 
66  uint8_t encoding_version() const override;
67 
71  size_t encoded_length_internal() const override;
72 
75  void encode_internal(uint8_t **bufp) const override;
76 
83  void decode_internal(uint8_t version, const uint8_t **bufp,
84  size_t *remainp) override;
85 
86  };
87 
89  class RangeSpecManaged : public RangeSpec {
90  public:
92  RangeSpecManaged(const RangeSpecManaged &range) { operator=(range); }
93  RangeSpecManaged(const RangeSpec &range) { operator=(range); }
94  virtual ~RangeSpecManaged() { }
95 
97  const RangeSpec *otherp = &other;
98  return operator=(*otherp);
99  }
101  if (range.start_row)
102  set_start_row(range.start_row);
103  else
104  start_row = 0;
105 
106  if (range.end_row)
107  set_end_row(range.end_row);
108  else
109  end_row = 0;
110  return *this;
111  }
112  void set_start_row(const std::string &s) {
113  m_start = s;
114  start_row = m_start.c_str();
115  }
116  void set_end_row(const std::string &e) {
117  m_end = e;
118  end_row = m_end.c_str();
119  }
120 
121  private:
122 
129  void decode_internal(uint8_t version, const uint8_t **bufp,
130  size_t *remainp) override;
131 
132  std::string m_start;
133  std::string m_end;
134  };
135 
136  std::ostream &operator<<(std::ostream &os, const RangeSpec &range);
137 
139 }
140 
141 
142 #endif // Hypertable_Lib_RangeSpec_h
RangeSpecManaged & operator=(const RangeSpecManaged &other)
Definition: RangeSpec.h:96
Range specification.
Definition: RangeSpec.h:40
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
Definition: RangeSpec.cc:159
bool operator<(const RangeSpec &other) const
Definition: RangeSpec.cc:85
RangeSpecManaged & operator=(const RangeSpec &range)
Definition: RangeSpec.h:100
void set_start_row(const std::string &s)
Definition: RangeSpec.h:112
const char * end_row
Definition: RangeSpec.h:60
size_t encoded_length_internal() const override
Returns internal serialized length.
Definition: RangeSpec.cc:127
bool operator!=(const RangeSpec &other) const
Definition: RangeSpec.cc:81
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Definition: Crontab.cc:301
virtual ~RangeSpec()
Definition: RangeSpec.h:54
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
Definition: Serializable.cc:70
Declarations for Serializable.
Hypertable definitions
const char * start_row
Definition: RangeSpec.h:59
Mixin class that provides a standard serialization interface.
Definition: Serializable.h:65
RangeSpec(const char *start, const char *end)
Definition: RangeSpec.h:51
RangeSpecManaged(const RangeSpecManaged &range)
Definition: RangeSpec.h:92
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
Definition: RangeSpec.cc:147
static std::string type_str(int type)
Definition: RangeSpec.cc:41
void set_end_row(const std::string &e)
Definition: RangeSpec.h:116
RangeSpecManaged(const RangeSpec &range)
Definition: RangeSpec.h:93
bool operator==(const RangeSpec &other) const
Definition: RangeSpec.cc:57
Wrapper for RangeSpec providing member storage.
Definition: RangeSpec.h:89
uint8_t encoding_version() const override
Returns encoding version.
Definition: RangeSpec.cc:123
RangeSpec(const uint8_t **bufp, size_t *remainp)
Definition: RangeSpec.h:53
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
Definition: RangeSpec.cc:152