HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PI_SettingList.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: PI_SettingList.h
7  *
8  * COMMENTS:
9  * This class maintains a list of settings that control how a PI
10  * behaves. Each setting is named. The corresponding value may
11  * be a bool, int, fpreal, UT_String, or UT_Vector[2/3/4]. The version
12  * of the overloaded getSetting()/appendSetting() method that you
13  * call determines the value type.
14  *
15  * There may only be one type of setting value per name. Appending
16  * a setting that has the same name as an existing setting is not
17  * allowed.
18  *
19  * If no setting with the given name exists, getSetting() will return
20  * the supplied default setting.
21  */
22 
23 #ifndef __PI_SettingList_h__
24 #define __PI_SettingList_h__
25 
26 #include "PI_API.h"
27 #include <iosfwd>
28 #include <UT/UT_ValArray.h>
29 #include <UT/UT_VectorTypes.h>
30 
31 class UT_String;
32 class pi_Setting;
33 
34 // This enumerated type in used internally, but must be declared in this
35 // header because some private methods take these values as arguments. A
36 // number of helper classes also use this type. It could go in the public
37 // part of the header, but it's too cumbersome to type
38 // PI_SettingList::PI_SETTING_FLOAT, so it's not in the header.
40 {
46 };
47 
49 {
50 public:
51  explicit PI_SettingList();
52  ~PI_SettingList();
53 
54  // These methods are called by a PI when it loads its settings.
55  void getSetting(const char *setting_name,
56  int &setting,
57  int default_value) const;
58  void getSetting(const char *setting_name,
59  bool &setting,
60  bool default_value) const;
61  void getSetting(const char *setting_name,
62  fpreal &setting,
63  fpreal default_value) const;
64  void getSetting(const char *setting_name,
65  UT_String &setting,
66  const char *default_value) const;
67  void getSetting(const char *setting_name,
68  UT_Vector2R &setting,
69  const UT_Vector2R &default_value) const;
70  void getSetting(const char *setting_name,
71  UT_Vector3R &setting,
72  const UT_Vector3R &default_value) const;
73  void getSetting(const char *setting_name,
74  UT_Vector4R &setting,
75  const UT_Vector4R &default_value) const;
76 
77  // These methods are called by a PI when it saves its settings.
78  void appendSetting(const char *setting_name,
79  int setting);
80  void appendSetting(const char *setting_name,
81  bool setting);
82  void appendSetting(const char *setting_name,
83  fpreal setting);
84  void appendSetting(const char *setting_name,
85  const char *setting);
86  void appendSetting(const char *setting_name,
87  const UT_Vector2R &setting);
88  void appendSetting(const char *setting_name,
89  const UT_Vector3R &setting);
90  void appendSetting(const char *setting_name,
91  const UT_Vector4R &setting);
92 
93  // This method is used to remove a specific setting from the list.
94  void removeSetting(const char *setting_name);
95 
96  // When a PI reads a setting it will be marked as read. This method
97  // will return a string containing all unread (ie. unrecognized) settings.
98  bool findUnreadSettings(UT_String &unread_settings) const;
99 
100  // The resource manager uses the == operator to see if settings differ from
101  // the default settings. Note that this operator is not const and does not
102  // take a reference to a const object because it may sort the two lists.
103  bool operator==(PI_SettingList &setting_list);
104  void sort();
105 
106  PI_SettingList &operator=(const PI_SettingList &setting_list);
107 
108  // Clear the list or check if it's empty.
109  void clear();
110  bool isEmpty() const { return !mySettings.entries(); }
111 
112  // These methods convert the settings to and from ascii data.
113  void loadFromSettingString(const char *setting_string);
114  void generateSettingString(std::ostream &os) const;
115  void generateSettingString(UT_String &str) const;
116 
117  friend std::ostream &operator<<(std::ostream &os,
118  const PI_SettingList &setting_list)
119  {
120  setting_list.generateSettingString(os);
121  return os;
122  }
123 
124 private:
125  // Find a setting with a given name and type.
126  pi_Setting *findSetting(const char *setting_name,
127  pi_SettingType setting_type) const;
128 
129  // The setting parser needs to be a friend so it can call findSetting
130  // and append to mySettings.
131  friend class pi_SettingParser;
132 
133  // Data:
134 
135  UT_ValArray<pi_Setting *> mySettings;
136  bool mySortedFlag;
137 };
138 
139 #endif
#define PI_API
Definition: PI_API.h:10
2D Vector class.
Definition: UT_Vector2.h:138
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
friend std::ostream & operator<<(std::ostream &os, const PI_SettingList &setting_list)
void generateSettingString(std::ostream &os) const
double fpreal
Definition: SYS_Types.h:270
pi_SettingType
bool isEmpty() const