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  // Copy any settings from the given setting_list that we're missing.
109  void copyMissing(const PI_SettingList &setting_list);
110 
111  // Update the setting values from a given setting_list. If there
112  // is a match, the target setting is updated with the input setting
113  // value.
114  void updateSettings(const PI_SettingList &setting_list);
115 
116  // Clear the list or check if it's empty.
117  void clear();
118  bool isEmpty() const { return !mySettings.entries(); }
119 
120  // These methods convert the settings to and from ascii data.
121  void loadFromSettingString(const char *setting_string);
122  void generateSettingString(std::ostream &os) const;
123  void generateSettingString(UT_String &str) const;
124 
125  friend std::ostream &operator<<(std::ostream &os,
126  const PI_SettingList &setting_list)
127  {
128  setting_list.generateSettingString(os);
129  return os;
130  }
131 
132 private:
133  // Find a setting with a given name and type.
134  pi_Setting *findSetting(const char *setting_name,
135  pi_SettingType setting_type) const;
136 
137  // The setting parser needs to be a friend so it can call findSetting
138  // and append to mySettings.
139  friend class pi_SettingParser;
140 
141  // Data:
142 
143  UT_ValArray<pi_Setting *> mySettings;
144  bool mySortedFlag;
145 };
146 
147 #endif
#define PI_API
Definition: PI_API.h:10
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
fpreal64 fpreal
Definition: SYS_Types.h:277
LeafData & operator=(const LeafData &)=delete
void sort(I begin, I end, const Pred &pred)
Definition: pugixml.cpp:7334
pi_SettingType
bool isEmpty() const