HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_OptionTable.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GR_OptionTable.h ( GR Library, C++)
7  *
8  * COMMENTS:
9  * This class holds the table of all available option types as well as
10  * the instances of all currently active options.
11  */
12 
13 #ifndef __GR_OptionTable__
14 #define __GR_OptionTable__
15 
16 #include "GR_API.h"
17 #include <UT/UT_SymbolTable.h>
18 #include <UT/UT_ValArray.h>
19 #include <UT/UT_Notifier.h>
20 
21 class GR_OptionTemplate;
22 class GR_UserOption;
23 
25 {
26 public:
28  {
31  OPTION_CHANGED
32  };
33 
35  int id )
36  : myEventType(type), myOption(option), myOptionId(id) {}
37 
41 };
42 
44 {
45 public:
47  virtual ~GR_OptionTable();
48 
49  // The responsibility to delete a template resides with this method.
50  void addTemplate(GR_OptionTemplate *tplate);
51 
52  // Query the templates currently present in the table.
53  int getNumTemplates() const;
54  GR_OptionTemplate *getTemplate(int i) const;
55 
56  // Query the options currently instantiated.
57  int getNumOptions() const { return myOptions.entries(); }
58  const GR_UserOption *getOption(int i) const { return myOptions(i); }
59 
60  GR_UserOption *createOption(const char *type, const char *name,
61  const char *label = NULL);
62  bool destroyOption(const char *name);
63  int destroyOptionsByPattern(const char *pattern);
64  bool renameOption(const char *old_name,
65  const char *new_name, bool notify);
66  void optionChanged(const char *name);
67 
68  GR_UserOption *getOption(const char *name);
69  int getOptionId(const char *name) const;
70  GR_UserOption *getOptionById(int unique_id)
71  {
72  if( unique_id >= 0 && unique_id <
73  myOptionsByID.entries() )
74  return myOptionsByID(unique_id);
75  return 0;
76  }
77  void getOptionsByPattern(const char *pattern,
79 
80  /// Returns a notifier that distributes events when options are added,
81  /// removed or changed.
83  &getEventNotifier() { return myEventNotifier; }
84 
85  // Method to override the default definition file name. In order for the
86  // default definitions to be loaded from this file, this must be called
87  // before the first instance of this class is created.
88  static void overrideDefinitionFile(const char *filename);
89 
90  void saveDefaultOptionDefinitions();
91  void loadDefaultOptionDefinitions();
92 
93  /// Return true if the save/load was successful, and false otherwise.
94  bool saveOptions(std::ostream &os, int indent = 0) const;
95  bool loadOptions(UT_IStream &is);
96 
97 private:
98  void addFactoryTemplates();
99 
100 protected:
103 
106 
107  // A table to allow fast lookup of options by the unique id.
109 
110  // Object that notifies about option changes. The int argument
111  // means absolutely nothing.
113 };
114 
116 
117 #endif
118 
GT_API const UT_StringHolder filename
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
UT_SymbolMap< exint > myOptionsLUT
UT_ValArray< GR_UserOption * > myOptionsByID
GR_OptionTableEvent(GR_OptionTableEventType type, GR_UserOption *option, int id)
GR_UserOption * getOptionById(int unique_id)
#define GR_API
Definition: GR_API.h:10
const GR_UserOption * getOption(int i) const
GLuint const GLchar * name
Definition: glcorearb.h:786
GLushort pattern
Definition: glad.h:2583
GR_API GR_OptionTable * GRgetOptionTable()
UT_NotifierImpl< GR_OptionTableEvent & > & getEventNotifier()
UT_ValArray< GR_OptionTemplate * > myTemplates
GR_OptionTableEventType myEventType
UT_ValArray< GR_UserOption * > myOptions
UT_SymbolMap< GR_OptionTemplate * > myTemplateLUT
type
Definition: core.h:1059
GR_UserOption * myOption
int getNumOptions() const
UT_NotifierImpl< GR_OptionTableEvent & > myEventNotifier