aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/config/items/cfgitemi.h
blob: 7824abf5ffa9eac4cbd9468df8d86fce0596e769 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef _CFGITEMI_H
#define _CFGITEMI_H

#include "cfgitemx.h"

#include <bfc/named.h>
#include <bfc/ptrlist.h>
#include <bfc/depend.h>

#include <map>
#include <string>

class AttrCallback;
class Attribute;

// this is the one you inherit from/use
/**
  
  @short Configuration Item
  @ver 1.0
  @author Nullsoft
  @see Attribute
  @see _bool
  @see _int
  @see _float
  @see _string
*/
class CfgItemI : public CfgItemX, public DependentI, private NamedW
{
public:
  /**
    Optionally sets the name and the GUID of the
    configuration item if they are specified
    upon creation of the object.
    
    @param name Name of the configuration item.
    @param guid GUID of the configuration item.
  */
  CfgItemI(const wchar_t *name=NULL, GUID guid=INVALID_GUID);
  
  /**
    Does nothing.
  */
  virtual ~CfgItemI();

  /**
    Get the name of the configuration item.
    
    @ret Name of the configuration item.
  */
  const wchar_t *cfgitem_getName();
  
  /**
    Get the GUID of the configuration item.
    
    @ret GUID of the configuration item.
  */
  GUID cfgitem_getGuid();

  /**
    Sets the prefix to be prepended in the config file for all attributes
    of this item.

    @see cfgitem_getPrefix
    @param prefix The prefix.
  */
  void cfgitem_setPrefix(const wchar_t *prefix);
/**
  Gets the config prefix, if any was set.

  @see cfgitem_setPrefix
  @ret Pointer to the config prefix.
*/
  const wchar_t *cfgitem_getPrefix();
  
  /**
    Get the number of attributes registered
    to this configuration item.
    
    @ret Number of attributes.
  */
  int cfgitem_getNumAttributes();
  
  /**
    Enumerate the attributes registered
    with this configuration item.
    
    @ret 
  */
  const wchar_t *cfgitem_enumAttribute(int n);

  const wchar_t *cfgitem_getConfigXML();
  virtual void cfgitem_onCfgGroupCreate(ifc_window *cfggroup, const wchar_t *attrname) {}
  virtual void cfgitem_onCfgGroupDelete(ifc_window *cfggroup) {}

  virtual int cfgitem_getNumChildren();
  virtual CfgItem *cfgitem_enumChild(int n);
  virtual GUID cfgitem_getParentGuid();

  virtual void cfgitem_onRegister();
  virtual void cfgitem_onDeregister();

  int cfgitem_getAttributeType(const wchar_t *name);
  const wchar_t *cfgitem_getAttributeConfigGroup(const wchar_t *name);
  int cfgitem_getDataLen(const wchar_t *name);
  int cfgitem_getData(const wchar_t *name, wchar_t *data, int data_len);
  int cfgitem_setData(const wchar_t *name, const wchar_t *data);

  // override these to catch notifications from attribs, call down
  virtual int cfgitem_onAttribSetValue(Attribute *attr);

  virtual int cfgitem_usePrivateStorage() { return 0; } //override and return 1 to keep stuff out of system settings

protected:
  void cfgitem_setGUID(GUID guid);

public:
  int setName(const wchar_t *name);
  int registerAttribute(Attribute *attr, AttrCallback *acb=NULL);
  // does not call delete on the attribute
  int deregisterAttribute(Attribute *attr);
  void deregisterAll();

  void addCallback(Attribute *attr, AttrCallback *acb);

  int cfgitem_addAttribute(const wchar_t *name, const wchar_t *defval);
  int cfgitem_delAttribute(const wchar_t *name);

protected:
  
  // derived classes can override this to catch name changes
  virtual void cfgitem_onSetName() { }

  Attribute *getAttributeByName(const wchar_t *name);
 
  void addChildItem(CfgItemI *child);

  void setCfgXml(const wchar_t *groupname);

  void setParentGuid(GUID guid);

private:
  api_dependent *cfgitem_getDependencyPtr() { return this; };
  virtual void *dependent_getInterface(const GUID *classguid);

  // from Named
  virtual void onSetName() { cfgitem_onSetName(); }

  std::wstring prefix;
  PtrList<Attribute> attributes;
  std::multimap<Attribute*, AttrCallback*> callbacks;	//CUT
  PtrList<CfgItemI> children;
  std::wstring cfgxml;
  GUID myguid, parent_guid;
  PtrList<Attribute> newattribs;
};

#endif