1 /*
2  Copyright (c) 2011, Oracle and/or its affiliates. All rights
3  reserved.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License, version 2.0,
7  as published by the Free Software Foundation.
8 
9  This program is also distributed with certain software (including
10  but not limited to OpenSSL) that is licensed under separate terms,
11  as designated in a particular file or component or in included license
12  documentation.  The authors of MySQL hereby grant you an additional
13  permission to link the program and your derivative works with the
14  separately licensed software that they have included with MySQL.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  GNU General Public License, version 2.0, for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24  02110-1301  USA
25  */
26 #ifndef NDBMEMCACHE_TABLESPEC_H
27 #define NDBMEMCACHE_TABLESPEC_H
28 
29 #ifndef __cplusplus
30 #error "This file is for C++ only"
31 #endif
32 
33 #include "ndbmemcache_config.h"
34 
35 /** @class TableSpec
36  *  @brief In-memory representation of a containers record from the configuration.
37  */
38 class TableSpec {
39 
40   public:
41   /* Public Constructors */
42   TableSpec(int nkeys, int nvals);
43   TableSpec(const char *db, const char *tab, int nkeys, int nvals);
44   TableSpec(const char *sqltabname, const char *keycols, const char *valcols);
45   TableSpec(const TableSpec &);
46 
47   /* Other Public Methods */
48   ~TableSpec();
49   void setTable(const char *db, const char *table);
50   void setKeyColumns(const char *col1, ...);
51   void setValueColumns(const char *col1, ...);
52   bool isValid() const;
53 
54   /* Public instance variables */
55   int nkeycols;
56   int nvaluecols;
57   const char *schema_name;
58   const char *table_name;
59   const char *math_column;
60   const char *flags_column;
61   const char *cas_column;
62   const char *exp_column;
63   Uint32 static_flags;
64   const char ** const key_columns;
65   const char ** const value_columns;
66   TableSpec * external_table;
67 
68   private:
69   /* private instance variables */
70   struct {
71     unsigned none         : 1;
72     unsigned schema_name  : 1;
73     unsigned table_name   : 1;
74     unsigned first_key    : 1;
75     unsigned all_key_cols : 1;
76     unsigned first_val    : 1;
77     unsigned all_val_cols : 1;
78     unsigned special_cols : 1;
79   } must_free;
80 
81   /* private instance methods */
82   void initialize_flags(void);
83 
84   /* private class methods */
85   static int build_column_list(const char ** const &array, const char *list);
86 };
87 
88 
89 /* Inline functions */
90 
TableSpec(int nkeys,int nvals)91 inline TableSpec::TableSpec(int nkeys, int nvals) :
92                             nkeycols(nkeys),
93                             nvaluecols(nvals),
94                             schema_name(0), table_name(0),
95                             math_column(0), flags_column(0),
96                             cas_column(0), exp_column(0), static_flags(0),
97                             key_columns(new const char *[nkeys]),
98                             value_columns(new const char *[nvals]),
99                             external_table(0) {
100   must_free.none = 1;
101 }
102 
TableSpec(const char * db,const char * tab,int nkeys,int nvals)103 inline TableSpec::TableSpec(const char *db, const char *tab,
104                             int nkeys, int nvals) :
105                             nkeycols(nkeys), nvaluecols(nvals),
106                             schema_name(db), table_name(tab),
107                             math_column(0), flags_column(0),
108                             cas_column(0), exp_column(0), static_flags(0),
109                             key_columns(new const char *[nkeys]),
110                             value_columns(new const char *[nvals]),
111                             external_table(0) {
112   must_free.none = 1;
113 }
114 
setTable(const char * db,const char * table)115 inline void TableSpec::setTable(const char *db, const char *table) {
116   schema_name = db;
117   table_name = table;
118   must_free.schema_name = 1;
119   must_free.table_name  = 1;
120 }
121 
isValid()122 inline bool TableSpec::isValid() const {
123   return (schema_name && table_name && nkeycols);
124 }
125 
126 #endif
127 
128 
129