home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / h / vd2 / system / VDNamespace.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  5.4 KB  |  158 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    System library component
  3. //    Copyright (C) 1998-2004 Avery Lee, All Rights Reserved.
  4. //
  5. //    Beginning with 1.6.0, the VirtualDub system library is licensed
  6. //    differently than the remainder of VirtualDub.  This particular file is
  7. //    thus licensed as follows (the "zlib" license):
  8. //
  9. //    This software is provided 'as-is', without any express or implied
  10. //    warranty.  In no event will the authors be held liable for any
  11. //    damages arising from the use of this software.
  12. //
  13. //    Permission is granted to anyone to use this software for any purpose,
  14. //    including commercial applications, and to alter it and redistribute it
  15. //    freely, subject to the following restrictions:
  16. //
  17. //    1.    The origin of this software must not be misrepresented; you must
  18. //        not claim that you wrote the original software. If you use this
  19. //        software in a product, an acknowledgment in the product
  20. //        documentation would be appreciated but is not required.
  21. //    2.    Altered source versions must be plainly marked as such, and must
  22. //        not be misrepresented as being the original software.
  23. //    3.    This notice may not be removed or altered from any source
  24. //        distribution.
  25. #ifndef f_SYSTEM_VDNAMESPACE_H
  26. #define f_SYSTEM_VDNAMESPACE_H
  27.  
  28. #include <vd2/system/list.h>
  29.  
  30. class VDNamespaceNode;
  31. class VDNamespaceGroup;
  32. class VDNamespaceItem;
  33. class VDNamespace;
  34. template <class T> class VDNamespace2;
  35.  
  36. ///////////////////////////////////////////////////////////////////////////
  37. //
  38. // Node: Any item in the namespace.
  39. //
  40. ///////////////////////////////////////////////////////////////////////////
  41.  
  42. class VDNamespaceNode {
  43. public:
  44.     const char *pszName;
  45.     VDNamespaceGroup *const pParent;
  46.  
  47.     VDNamespaceNode(const char *name, VDNamespaceGroup *parent) : pszName(name), pParent(parent) {    }
  48. };
  49.  
  50. ///////////////////////////////////////////////////////////////////////////
  51. //
  52. // Group: Holds items.
  53. //
  54. ///////////////////////////////////////////////////////////////////////////
  55.  
  56. class VDNamespaceGroup : public VDNamespaceNode, public ListNode2<VDNamespaceGroup> {
  57. public:
  58.     ListAlloc<VDNamespaceItem> listItems;
  59.     ListAlloc<VDNamespaceGroup> listGroups;
  60.  
  61.     const char *namedup(const char *s);
  62.  
  63.     VDNamespaceGroup(const char *_pszName, VDNamespaceGroup *parent);
  64.     ~VDNamespaceGroup();
  65. };
  66.  
  67. ///////////////////////////////////////////////////////////////////////////
  68. //
  69. // Item class
  70. //
  71. ///////////////////////////////////////////////////////////////////////////
  72.  
  73. class VDNamespaceItem : public VDNamespaceNode, public ListNode2<VDNamespaceItem> {
  74. public:
  75.     const void *object;
  76.  
  77.     VDNamespaceItem(const char *_pszName, VDNamespaceGroup *parent, const void *src);
  78.     ~VDNamespaceItem();
  79. };
  80.  
  81. ///////////////////////////////////////////////////////////////////////////
  82. //
  83. // Namespace class
  84. //
  85. ///////////////////////////////////////////////////////////////////////////
  86.  
  87. class VDNamespace {
  88. protected:
  89.     VDNamespaceGroup root;
  90.  
  91.     VDNamespaceGroup *_lookupGroup(const char *pszName, bool fCreate, bool fIsFilter);
  92.     VDNamespaceItem *_findItemByObject(const VDNamespaceGroup *pGroup, const void *pObj);
  93.     bool _getPathByItem(const VDNamespaceNode *pEntry, char *buf, int maxlen);
  94.  
  95. public:
  96.  
  97.     VDNamespace();
  98.     ~VDNamespace();
  99.  
  100.     typedef bool (*tGroupEnumerator)(VDNamespace *pThis, const char *pszName, const VDNamespaceGroup *pGroup, void *pvData);
  101.     typedef bool (*tItemEnumerator)(VDNamespace *pThis, const char *pszName, const void *pItem, void *pvData);
  102.  
  103.     void clear();
  104.     void add(const char *pszGroup, const char *pszName, const void *pDef);
  105.     const void *lookup(const char *pszName);
  106.  
  107.     bool enumerateGroups(const VDNamespaceGroup *pGroupRoot, tGroupEnumerator pEnum, void *pvData);
  108.     bool enumerateItems(const VDNamespaceGroup *pGroupRoot, tItemEnumerator pEnum, void *pvData);
  109.  
  110.     bool getPathByItem(const void *pObj, char *buf, int maxlen);
  111. };
  112.  
  113. ///////////////////////////////////////////////////////////////////////////
  114. //
  115. //    Templated Namespace class
  116. //
  117. ///////////////////////////////////////////////////////////////////////////
  118.  
  119. template <class T>
  120. class VDNamespace2 : public VDNamespace {
  121. public:
  122.     VDNamespace2() {}
  123.     ~VDNamespace2() {}
  124.  
  125.     typedef bool (*tGroupEnumerator)(VDNamespace2<T> *pThis, const char *pszName, const VDNamespaceGroup *pGroup, void *pvData);
  126.     typedef bool (*tItemEnumerator)(VDNamespace2<T> *pThis, const char *pszName, const T *pItem, void *pvData);
  127.  
  128.     void add(const char *pszGroup, const char *pszName, const T *pDef) {
  129.         VDNamespace::add(pszGroup, pszName, pDef);
  130.     }
  131.  
  132.     const T *lookup(const char *pszName) {
  133.         return static_cast<const T *>(VDNamespace::lookup(pszName));
  134.     }
  135.  
  136.     bool enumerateGroups(const VDNamespaceGroup *pGroupRoot, tGroupEnumerator pEnum, void *pvData) {
  137.         for(ListAlloc<VDNamespaceGroup>::fwit it = (pGroupRoot ? pGroupRoot : &root)->listGroups.begin(); it; ++it)
  138.             if (!pEnum(this, it->pszName, it, pvData))
  139.                 return false;
  140.  
  141.         return true;
  142.     }
  143.  
  144.     bool enumerateItems(const VDNamespaceGroup *pGroupRoot, tItemEnumerator pEnum, void *pvData) {
  145.         for(ListAlloc<VDNamespaceItem>::fwit it = (pGroupRoot ? pGroupRoot : &root)->listItems.begin(); it; ++it)
  146.             if (!pEnum(this, it->pszName, static_cast<const T *>(it->object), pvData))
  147.                 return false;
  148.  
  149.         return true;
  150.     }
  151.  
  152.     bool getPathByItem(const T *pObj, char *buf, int maxlen) {
  153.         return VDNamespace::getPathByItem(pObj, buf, maxlen);
  154.     }
  155. };
  156.  
  157. #endif
  158.