You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.9 KiB

  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: objectregistry.h
  4. // Created: 3/2003
  5. // Author: Tad E. Smith
  6. //
  7. //
  8. // Copyright 2003-2013 Tad E. Smith
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. /** @file */
  22. #ifndef LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_
  23. #define LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_
  24. #include <log4cplus/config.hxx>
  25. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  26. #pragma once
  27. #endif
  28. #include <log4cplus/tstring.h>
  29. #include <log4cplus/thread/syncprims.h>
  30. #include <map>
  31. #include <memory>
  32. #include <vector>
  33. namespace log4cplus {
  34. namespace spi {
  35. /**
  36. * This is the base class used to implement the functionality required
  37. * by the ObjectRegistry template class.
  38. */
  39. class LOG4CPLUS_EXPORT ObjectRegistryBase {
  40. public:
  41. // public methods
  42. /**
  43. * Tests to see whether or not an object is bound in the
  44. * registry as <code>name</code>.
  45. */
  46. bool exists(const log4cplus::tstring& name) const;
  47. /**
  48. * Returns the names of all registered objects.
  49. */
  50. std::vector<log4cplus::tstring> getAllNames() const;
  51. protected:
  52. // Ctor and Dtor
  53. ObjectRegistryBase();
  54. virtual ~ObjectRegistryBase();
  55. // protected methods
  56. /**
  57. * Used to enter an object into the registry. (The registry now
  58. * owns <code>object</code>.)
  59. */
  60. bool putVal(const log4cplus::tstring& name, void* object);
  61. /**
  62. * Used to retrieve an object from the registry. (The registry
  63. * owns the returned pointer.)
  64. */
  65. void* getVal(const log4cplus::tstring& name) const;
  66. /**
  67. * Deletes <code>object</code>.
  68. */
  69. virtual void deleteObject(void *object) const = 0;
  70. /**
  71. * Deletes all objects from this registry.
  72. */
  73. virtual void clear();
  74. // Types
  75. typedef std::map<log4cplus::tstring, void*> ObjectMap;
  76. // Data
  77. thread::Mutex mutex;
  78. ObjectMap data;
  79. private:
  80. ObjectRegistryBase (ObjectRegistryBase const &);
  81. ObjectRegistryBase & operator = (ObjectRegistryBase const &);
  82. };
  83. }
  84. }
  85. #endif // LOG4CPLUS_SPI_OBJECT_REGISTRY_HEADER_