cfgitemi.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef _CFGITEMI_H
  2. #define _CFGITEMI_H
  3. #include "cfgitemx.h"
  4. #include <bfc/named.h>
  5. #include <bfc/ptrlist.h>
  6. #include <bfc/depend.h>
  7. #include <map>
  8. #include <string>
  9. class AttrCallback;
  10. class Attribute;
  11. // this is the one you inherit from/use
  12. /**
  13. @short Configuration Item
  14. @ver 1.0
  15. @author Nullsoft
  16. @see Attribute
  17. @see _bool
  18. @see _int
  19. @see _float
  20. @see _string
  21. */
  22. class CfgItemI : public CfgItemX, public DependentI, private NamedW
  23. {
  24. public:
  25. /**
  26. Optionally sets the name and the GUID of the
  27. configuration item if they are specified
  28. upon creation of the object.
  29. @param name Name of the configuration item.
  30. @param guid GUID of the configuration item.
  31. */
  32. CfgItemI(const wchar_t *name=NULL, GUID guid=INVALID_GUID);
  33. /**
  34. Does nothing.
  35. */
  36. virtual ~CfgItemI();
  37. /**
  38. Get the name of the configuration item.
  39. @ret Name of the configuration item.
  40. */
  41. const wchar_t *cfgitem_getName();
  42. /**
  43. Get the GUID of the configuration item.
  44. @ret GUID of the configuration item.
  45. */
  46. GUID cfgitem_getGuid();
  47. /**
  48. Sets the prefix to be prepended in the config file for all attributes
  49. of this item.
  50. @see cfgitem_getPrefix
  51. @param prefix The prefix.
  52. */
  53. void cfgitem_setPrefix(const wchar_t *prefix);
  54. /**
  55. Gets the config prefix, if any was set.
  56. @see cfgitem_setPrefix
  57. @ret Pointer to the config prefix.
  58. */
  59. const wchar_t *cfgitem_getPrefix();
  60. /**
  61. Get the number of attributes registered
  62. to this configuration item.
  63. @ret Number of attributes.
  64. */
  65. int cfgitem_getNumAttributes();
  66. /**
  67. Enumerate the attributes registered
  68. with this configuration item.
  69. @ret
  70. */
  71. const wchar_t *cfgitem_enumAttribute(int n);
  72. const wchar_t *cfgitem_getConfigXML();
  73. virtual void cfgitem_onCfgGroupCreate(ifc_window *cfggroup, const wchar_t *attrname) {}
  74. virtual void cfgitem_onCfgGroupDelete(ifc_window *cfggroup) {}
  75. virtual int cfgitem_getNumChildren();
  76. virtual CfgItem *cfgitem_enumChild(int n);
  77. virtual GUID cfgitem_getParentGuid();
  78. virtual void cfgitem_onRegister();
  79. virtual void cfgitem_onDeregister();
  80. int cfgitem_getAttributeType(const wchar_t *name);
  81. const wchar_t *cfgitem_getAttributeConfigGroup(const wchar_t *name);
  82. int cfgitem_getDataLen(const wchar_t *name);
  83. int cfgitem_getData(const wchar_t *name, wchar_t *data, int data_len);
  84. int cfgitem_setData(const wchar_t *name, const wchar_t *data);
  85. // override these to catch notifications from attribs, call down
  86. virtual int cfgitem_onAttribSetValue(Attribute *attr);
  87. virtual int cfgitem_usePrivateStorage() { return 0; } //override and return 1 to keep stuff out of system settings
  88. protected:
  89. void cfgitem_setGUID(GUID guid);
  90. public:
  91. int setName(const wchar_t *name);
  92. int registerAttribute(Attribute *attr, AttrCallback *acb=NULL);
  93. // does not call delete on the attribute
  94. int deregisterAttribute(Attribute *attr);
  95. void deregisterAll();
  96. void addCallback(Attribute *attr, AttrCallback *acb);
  97. int cfgitem_addAttribute(const wchar_t *name, const wchar_t *defval);
  98. int cfgitem_delAttribute(const wchar_t *name);
  99. protected:
  100. // derived classes can override this to catch name changes
  101. virtual void cfgitem_onSetName() { }
  102. Attribute *getAttributeByName(const wchar_t *name);
  103. void addChildItem(CfgItemI *child);
  104. void setCfgXml(const wchar_t *groupname);
  105. void setParentGuid(GUID guid);
  106. private:
  107. api_dependent *cfgitem_getDependencyPtr() { return this; };
  108. virtual void *dependent_getInterface(const GUID *classguid);
  109. // from Named
  110. virtual void onSetName() { cfgitem_onSetName(); }
  111. std::wstring prefix;
  112. PtrList<Attribute> attributes;
  113. std::multimap<Attribute*, AttrCallback*> callbacks; //CUT
  114. PtrList<CfgItemI> children;
  115. std::wstring cfgxml;
  116. GUID myguid, parent_guid;
  117. PtrList<Attribute> newattribs;
  118. };
  119. #endif