00001 /* Copyright (C) 2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #ifndef PROPERTIES_HPP 00018 #define PROPERTIES_HPP 00019 00020 #include <ndb_global.h> 00021 #include <BaseString.hpp> 00022 #include <UtilBuffer.hpp> 00023 00024 enum PropertiesType { 00025 PropertiesType_Uint32 = 0, 00026 PropertiesType_char = 1, 00027 PropertiesType_Properties = 2, 00028 PropertiesType_Uint64 = 3 00029 }; 00030 00038 struct Property { 00039 Property(const char* name, Uint32 val); 00040 Property(const char* name, Uint64 val); 00041 Property(const char* name, const char * value); 00042 Property(const char* name, const class Properties * value); 00043 ~Property(); 00044 private: 00045 friend class Properties; 00046 struct PropertyImpl * impl; 00047 }; 00048 00053 class Properties { 00054 public: 00055 static const char delimiter; 00056 static const char version[]; 00057 00058 Properties(bool case_insensitive= false); 00059 Properties(const Properties &); 00060 Properties(const Property *, int len); 00061 virtual ~Properties(); 00062 00071 void setCaseInsensitiveNames(bool value); 00072 bool getCaseInsensitiveNames() const; 00073 00077 void put(const Property *, int len); 00078 00079 bool put(const char * name, Uint32 value, bool replace = false); 00080 bool put64(const char * name, Uint64 value, bool replace = false); 00081 bool put(const char * name, const char * value, bool replace = false); 00082 bool put(const char * name, const Properties * value, bool replace = false); 00083 00089 bool put(const char *, Uint32 no, Uint32, bool replace = false); 00090 bool put64(const char *, Uint32 no, Uint64, bool replace = false); 00091 bool put(const char *, Uint32 no, const char *, bool replace = false); 00092 bool put(const char *, Uint32 no, const Properties *, bool replace = false); 00093 00094 00095 bool getTypeOf(const char * name, PropertiesType * type) const; 00096 00098 bool contains(const char * name) const; 00099 00100 bool get(const char * name, Uint32 * value) const; 00101 bool get(const char * name, Uint64 * value) const; 00102 bool get(const char * name, const char ** value) const; 00103 bool get(const char * name, BaseString & value) const; 00104 bool get(const char * name, const Properties ** value) const; 00105 00106 bool getCopy(const char * name, char ** value) const; 00107 bool getCopy(const char * name, Properties ** value) const; 00108 00113 bool getTypeOf(const char * name, Uint32 no, PropertiesType * type) const; 00114 bool contains(const char * name, Uint32 no) const; 00115 00116 bool get(const char * name, Uint32 no, Uint32 * value) const; 00117 bool get(const char * name, Uint32 no, Uint64 * value) const; 00118 bool get(const char * name, Uint32 no, const char ** value) const; 00119 bool get(const char * name, Uint32 no, const Properties ** value) const; 00120 00121 bool getCopy(const char * name, Uint32 no, char ** value) const; 00122 bool getCopy(const char * name, Uint32 no, Properties ** value) const; 00123 00124 void clear(); 00125 00126 void remove(const char * name); 00127 00128 void print(FILE * file = stdout, const char * prefix = 0) const; 00132 class Iterator { 00133 public: 00134 Iterator(const Properties* prop); 00135 00136 const char* first(); 00137 const char* next(); 00138 private: 00139 const Properties* m_prop; 00140 Uint32 m_iterator; 00141 }; 00142 friend class Properties::Iterator; 00143 00144 Uint32 getPackedSize() const; 00145 bool pack(Uint32 * buf) const; 00146 bool pack(UtilBuffer &buf) const; 00147 bool unpack(const Uint32 * buf, Uint32 bufLen); 00148 bool unpack(UtilBuffer &buf); 00149 00150 Uint32 getPropertiesErrno() const { return propErrno; } 00151 Uint32 getOSErrno() const { return osErrno; } 00152 private: 00153 Uint32 propErrno; 00154 Uint32 osErrno; 00155 00156 friend class PropertiesImpl; 00157 class PropertiesImpl * impl; 00158 class Properties * parent; 00159 00160 void setErrno(Uint32 pErr, Uint32 osErr = 0) const ; 00161 }; 00162 00170 extern const Uint32 E_PROPERTIES_OK; 00171 00175 extern const Uint32 E_PROPERTIES_INVALID_NAME; 00176 00180 extern const Uint32 E_PROPERTIES_NO_SUCH_ELEMENT; 00181 00185 extern const Uint32 E_PROPERTIES_INVALID_TYPE; 00186 00190 extern const Uint32 E_PROPERTIES_ELEMENT_ALREADY_EXISTS; 00191 00195 extern const Uint32 E_PROPERTIES_INVALID_VERSION_WHILE_UNPACKING; 00196 00203 extern const Uint32 E_PROPERTIES_INVALID_BUFFER_TO_SHORT; 00204 00210 extern const Uint32 E_PROPERTIES_ERROR_MALLOC_WHILE_PACKING; 00211 00217 extern const Uint32 E_PROPERTIES_ERROR_MALLOC_WHILE_UNPACKING; 00218 00223 extern const Uint32 E_PROPERTIES_INVALID_CHECKSUM; 00224 00229 extern const Uint32 E_PROPERTIES_BUFFER_TO_SMALL_WHILE_UNPACKING; 00230 00231 inline bool 00232 Properties::unpack(UtilBuffer &buf) { 00233 return unpack((const Uint32 *)buf.get_data(), buf.length()); 00234 } 00235 00236 inline bool 00237 Properties::pack(UtilBuffer &buf) const { 00238 Uint32 size = getPackedSize(); 00239 void *tmp_buf = buf.append(size); 00240 if(tmp_buf == 0) 00241 return false; 00242 bool ret = pack((Uint32 *)tmp_buf); 00243 if(ret == false) 00244 return false; 00245 return true; 00246 } 00247 00248 00249 00250 #endif
1.4.7

