~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.h

  • Committer: Monty Taylor
  • Date: 2010-12-26 01:32:11 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101226013211-c1tx52h7evovmijg
fixed dict and eval.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "drizzled/definitions.h"
38
38
#include "drizzled/message/table.pb.h"
39
39
 
 
40
#include "drizzled/identifier.h"
 
41
 
40
42
#include <string.h>
41
43
 
42
44
#include <assert.h>
48
50
 
49
51
#include <boost/functional/hash.hpp>
50
52
 
51
 
#include "drizzled/visibility.h"
52
 
 
53
53
namespace drizzled {
 
54
 
54
55
class Table;
55
56
 
56
 
namespace identifier {
57
 
 
58
 
class DRIZZLED_API Table : public Schema
 
57
class TableIdentifier : public SchemaIdentifier
59
58
{
60
59
public:
61
60
  typedef message::Table::TableType Type;
62
 
  typedef std::vector <Table> vector;
63
 
  typedef const Table& const_reference;
64
 
  typedef Table& reference;
 
61
  typedef std::vector <TableIdentifier> vector;
 
62
  typedef const TableIdentifier& const_reference;
 
63
  typedef TableIdentifier& reference;
65
64
 
66
65
  class Key
67
66
  {
118
117
 
119
118
  Type type;
120
119
  std::string path;
121
 
  std::string key_path;
122
120
  std::string table_name;
123
121
  Key key;
124
122
  size_t hash_value;
131
129
  }
132
130
 
133
131
public:
134
 
 
135
 
  Table(const drizzled::Table &table);
 
132
  TableIdentifier(const Table &table);
136
133
                   
137
 
  Table(const identifier::Schema &schema,
138
 
        const std::string &table_name_arg,
139
 
        Type tmp_arg= message::Table::STANDARD) :
140
 
    Schema(schema),
141
 
    type(tmp_arg),
142
 
    table_name(table_name_arg)
143
 
  { 
144
 
    init();
145
 
  }
146
 
 
147
 
  Table( const std::string &db_arg,
148
 
                   const std::string &table_name_arg,
149
 
                   Type tmp_arg= message::Table::STANDARD) :
150
 
    Schema(db_arg),
151
 
    type(tmp_arg),
152
 
    table_name(table_name_arg)
153
 
  { 
154
 
    init();
155
 
  }
156
 
 
157
 
  Table( const std::string &schema_name_arg,
 
134
  TableIdentifier( const SchemaIdentifier &schema,
 
135
                   const std::string &table_name_arg,
 
136
                   Type tmp_arg= message::Table::STANDARD) :
 
137
    SchemaIdentifier(schema),
 
138
    type(tmp_arg),
 
139
    table_name(table_name_arg)
 
140
  { 
 
141
    init();
 
142
  }
 
143
 
 
144
  TableIdentifier( const std::string &db_arg,
 
145
                   const std::string &table_name_arg,
 
146
                   Type tmp_arg= message::Table::STANDARD) :
 
147
    SchemaIdentifier(db_arg),
 
148
    type(tmp_arg),
 
149
    table_name(table_name_arg)
 
150
  { 
 
151
    init();
 
152
  }
 
153
 
 
154
  TableIdentifier( const std::string &schema_name_arg,
158
155
                   const std::string &table_name_arg,
159
156
                   const std::string &path_arg ) :
160
 
    Schema(schema_name_arg),
 
157
    SchemaIdentifier(schema_name_arg),
161
158
    type(message::Table::TEMPORARY),
162
159
    path(path_arg),
163
160
    table_name(table_name_arg)
165
162
    init();
166
163
  }
167
164
 
168
 
  using Schema::compare;
 
165
  using SchemaIdentifier::compare;
169
166
 
170
167
  bool isTmp() const
171
168
  {
172
169
    if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL)
173
170
      return true;
174
 
 
175
171
    return false;
176
172
  }
177
173
 
204
200
  virtual void getSQLPath(std::string &sql_path) const;
205
201
 
206
202
  virtual const std::string &getPath() const;
207
 
  const std::string &getKeyPath() const;
208
203
 
209
204
  void setPath(const std::string &new_path)
210
205
  {
218
213
 
219
214
  void copyToTableMessage(message::Table &message) const;
220
215
 
221
 
  friend bool operator<(Table::const_reference left, Table::const_reference right)
 
216
  friend bool operator<(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
222
217
  {
223
218
    if (left.getKey() < right.getKey())
224
219
    {
228
223
    return false;
229
224
  }
230
225
 
231
 
  friend bool operator==(Table::const_reference left, Table::const_reference right)
 
226
  friend std::ostream& operator<<(std::ostream& output, TableIdentifier::const_reference identifier)
 
227
  {
 
228
    const char *type_str;
 
229
 
 
230
    output << "TableIdentifier:(";
 
231
    output <<  identifier.getSchemaName();
 
232
    output << ", ";
 
233
    output << identifier.getTableName();
 
234
    output << ", ";
 
235
 
 
236
    switch (identifier.type) {
 
237
    case message::Table::STANDARD:
 
238
      type_str= "standard";
 
239
      break;
 
240
    case message::Table::INTERNAL:
 
241
      type_str= "internal";
 
242
      break;
 
243
    case message::Table::TEMPORARY:
 
244
      type_str= "temporary";
 
245
      break;
 
246
    case message::Table::FUNCTION:
 
247
      type_str= "function";
 
248
      break;
 
249
    }
 
250
 
 
251
    output << type_str;
 
252
    output << ", ";
 
253
    output << identifier.path;
 
254
    output << ", ";
 
255
    output << identifier.getHashValue();
 
256
    output << ")";
 
257
 
 
258
    return output;  // for multiple << operators.
 
259
  }
 
260
 
 
261
  friend bool operator==(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
232
262
  {
233
263
    if (left.getHashValue() == right.getHashValue())
234
264
    {
258
288
  }
259
289
};
260
290
 
261
 
std::ostream& operator<<(std::ostream& output, Table::const_reference identifier);
262
 
std::size_t hash_value(Table const& b);
263
 
std::size_t hash_value(Table::Key const& b);
 
291
std::size_t hash_value(TableIdentifier const& b);
 
292
std::size_t hash_value(TableIdentifier::Key const& b);
264
293
 
265
 
} /* namespace identifier */
266
294
} /* namespace drizzled */
267
295
 
268
296
#endif /* DRIZZLED_IDENTIFIER_TABLE_H */