0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableIdentifier.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_TableIdentifier_h
28 #define Hypertable_Lib_TableIdentifier_h
29 
30 #include <Common/Serializable.h>
31 
32 #include <cassert>
33 #include <cstdlib>
34 #include <string>
35 
36 namespace Hypertable {
37 
40 
42  class TableIdentifier : public Serializable {
43 
44  public:
45  static const char *METADATA_ID;
46  static const char *METADATA_NAME;
47  static const int METADATA_ID_LENGTH;
48  TableIdentifier() : id(0), generation(0) { return; }
49  explicit TableIdentifier(const char *s) : id(s), generation(0) {}
50  virtual ~TableIdentifier() { }
51 
52  bool operator==(const TableIdentifier &other) const;
53  bool operator!=(const TableIdentifier &other) const;
54  bool operator<(const TableIdentifier &other) const;
55 
56  bool is_metadata() const { return !strcmp(id, METADATA_ID); }
57  bool is_system() const { return !strncmp(id, "0/", 2); }
58  bool is_user() const { return strncmp(id, "0/", 2); }
59 
60  int32_t index() const {
61  assert(id);
62  const char *ptr = id + strlen(id);
63  while (ptr > id && isdigit(*(ptr-1)))
64  ptr--;
65  return atoi(ptr);
66  }
67 
68  const char *id;
69  int64_t generation;
70 
71  protected:
72 
75  uint8_t encoding_version() const override;
76 
80  size_t encoded_length_internal() const override;
81 
84  void encode_internal(uint8_t **bufp) const override;
85 
92  void decode_internal(uint8_t version, const uint8_t **bufp,
93  size_t *remainp) override;
94 
95  };
96 
99  public:
100  TableIdentifierManaged() { id = NULL; generation = 0; }
102  operator=(identifier);
103  }
105  operator=(identifier);
106  }
109  const TableIdentifier *otherp = &other;
110  return operator=(*otherp);
111  }
113  generation = identifier.generation;
114 
115  if (identifier.id) {
116  m_name = identifier.id;
117  id = m_name.c_str();
118  }
119  else
120  id = 0;
121  return *this;
122  }
123 
124  void set_id(const std::string &new_name) {
125  m_name = new_name;
126  id = m_name.c_str();
127  }
128 
129  void set_id(const char *new_name) {
130  m_name = new_name;
131  id = m_name.c_str();
132  }
133 
134  const std::string& get_id() const {
135  return m_name;
136  }
137 
138  private:
139 
146  void decode_internal(uint8_t version, const uint8_t **bufp,
147  size_t *remainp) override;
148 
149  std::string m_name;
150  };
151 
152  std::ostream &operator<<(std::ostream &os, const TableIdentifier &tid);
153 
155 }
156 
157 
158 #endif // Hypertable_Lib_TableIdentifier_h
static const char * METADATA_ID
const std::string & get_id() const
static const char * METADATA_NAME
size_t encoded_length_internal() const override
Returns internal serialized length.
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
TableIdentifierManaged(const TableIdentifier &identifier)
bool operator!=(const TableIdentifier &other) const
Wrapper for TableIdentifier providing member storage.
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
TableIdentifierManaged(const TableIdentifierManaged &identifier)
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Definition: Crontab.cc:301
TableIdentifierManaged & operator=(const TableIdentifier &identifier)
Declarations for Serializable.
Hypertable definitions
void set_id(const char *new_name)
void set_id(const std::string &new_name)
Mixin class that provides a standard serialization interface.
Definition: Serializable.h:65
static const int METADATA_ID_LENGTH
bool operator<(const TableIdentifier &other) const
uint8_t encoding_version() const override
Returns encoding version.
TableIdentifierManaged & operator=(const TableIdentifierManaged &other)
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
bool operator==(const TableIdentifier &other) const