00001 /*****************************************************************************
00002 * Author: Valient Gough <vgough@pobox.com>
00003 *
00004 *****************************************************************************
00005 * Copyright (c) 2000, Valient Gough
00006 *
00007 * This library is free software; you can distribute it and/or modify it under
00008 * the terms of the GNU Lesser General Public License (LGPL), as published by
00009 * the Free Software Foundation; either version 2.1 of the License, or (at your
00010 * option) any later version.
00011 *
00012 * This library is distributed in the hope that it will be useful, but WITHOUT
00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 * FITNESS FOR A PARTICULAR PURPOSE. See the LGPL in the file COPYING for more
00015 * details.
00016 *
00017 */
00018
00019
00020 #ifndef _VMap_incl_
00021 #define _VMap_incl_
00022
00023
00024 #include <string>
00025 #include <typeinfo>
00026
00027 #include <rel/TypeStream.h>
00028 #include <rel/SmartPtr.h>
00029 #include <rel/VMapIterator.h>
00030
00031 using namespace std;
00032
00033
00034 namespace rel
00035 {
00036
00037
00067 class VMap
00068 {
00069 public:
00070 typedef SmartPtr<VMap> Ptr;
00071
00079 virtual ~VMap();
00080
00089 enum ErrorCode
00090 {
00092 Success = 0,
00093
00095 TypeMismatch = 1,
00097 NotFound = 2,
00099 AlreadyExists = 3,
00100
00102 NotPermitted = 4,
00104 Unsupported = 5,
00106 ArgumentError = 6,
00107
00109 BackendError = 7
00110 };
00115 enum DirFlags
00116 {
00118 NoFlags = 0x00,
00120 FindOrCreate = 0x01
00121 };
00122
00138 virtual Ptr findDirectory(const string &name, int flags = NoFlags);
00168 virtual Ptr findDirectory(const TypeStream &path, int flags = NoFlags);
00169
00173 virtual Ptr createDirectory(const string &name);
00174 // create a [sub]directory using user specified coding (supports
00175 // multi-part)
00176 // path based convenience function
00177 virtual Ptr createDirectory(const TypeStream &path);
00178
00179 // ---------------------- find
00180 // DEFUALTS to NULL
00181 // throws VMap_unsupported if not implemented
00182 virtual OpaqueValue find(const string &name);
00183
00184 // find based on full path.
00185 // path based convenience function
00186 // This will interpret operations
00187 virtual OpaqueValue find(const TypeStream &path);
00188
00189 // ---------------------- iterate
00190 // throws VMap_unsupported if not implemented
00191 virtual VMapIterator begin();
00192 virtual VMapIterator end();
00193 virtual VMapIterator at(const string &name);
00194
00195
00196 // ---------------------- insert
00197 // returns Unsupported if not implemented
00198 virtual ErrorCode insert(const string &name, const OpaqueValue &value);
00199
00200 // path based convenience function
00201 // flags can be set to FindOrCreate in order to force creation of any
00202 // subdirectories leading up to the value to be inserted. If the
00203 // FindOrCreate bit is not set, then it will fail if it encounters a
00204 // non-existant directory in the path.
00205 virtual ErrorCode insert(const TypeStream &path,
00206 const OpaqueValue &value,
00207 int flags = FindOrCreate);
00208
00209 // ----------------------- assign
00210 // does not interpret operations
00211 // returns Unsupported if not implemented
00212 virtual ErrorCode assign(const string &name, const OpaqueValue &value);
00213
00214 // Assignment will follow operations which redirect to other
00215 // directories, but no other types.
00216 virtual ErrorCode assign(const TypeStream &path,
00217 const OpaqueValue &value);
00218
00219
00220 // ----------------------- remove
00221 // returns Unsupported if not implemented
00222 virtual ErrorCode erase(const string &name);
00223 virtual ErrorCode erase(const TypeStream &path);
00224
00226 // returns Unsupported if not implemented
00227 virtual ErrorCode clear();
00228
00229 protected:
00230 // iterator implementation functions
00231 // throws VMap_unsupported if not implemented
00232 virtual void advanceIterator(const OpaqueValue &) const;
00233 // throws VMap_unsupported if not implemented
00234 virtual bool equalIteratorData(const OpaqueValue &a,
00235 const OpaqueValue &b) const;
00236 // throws VMap_unsupported if not implemented
00237 virtual void assignIteratorData(const OpaqueValue &src,
00238 const OpaqueValue &dest) const;
00239 // throws VMap_unsupported if not implemented
00240 virtual void getKeyValue(const OpaqueValue &iteratorData,
00241 std::pair<std::string,OpaqueValue> *result);
00242
00243 friend VMapIterator;
00244 };
00245
00246 typedef VMap::Ptr VMapPtr;
00247
00248
00255 OpaqueValue findFirst (VMapPtr &map,
00256 const TypeStream &path, const string &key);
00263 OpaqueValue findDeepest(VMapPtr &map,
00264 const TypeStream &path, const string &key);
00265
00266
00267 // Specialization of smart pointer interpret from OpaqueValueDataImpl for
00268 // VMap types. This implements interpret to do a map lookup.
00269 template<>
00270 bool smartPtrInterpret<VMap>(VMap *value,
00271 const std::type_info &resultType,
00272 const OpaqueValue *args,
00273 OpaqueValue *output);
00274
00275
00276 } // namespace rel
00277
00278
00279
00283 rel::VMapPtr GlobalObjectMap();
00284
00285 void SetGlobalObjectMap(const rel::VMapPtr &globalMap);
00286
00287
00291 #define GOM GlobalObjectMap()
00292
00293
00294
00295
00296 #endif
00297
1.2.10 written by Dimitri van Heesch,
© 1997-2001