HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_PresetInfo.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: PRM_PresetInfo.h ( OP Library, C++)
7  *
8  * COMMENTS: PresetInfo for an Operator type.
9  */
10 
11 #ifndef __PRM_PresetInfo__
12 #define __PRM_PresetInfo__
13 
14 #include "PRM_API.h"
15 #include <UT/UT_String.h>
16 #include <UT/UT_ValArray.h>
17 
18 #include <iosfwd>
19 #include <utility>
20 
21 class PRM_ParmList;
22 class UT_IStream;
24 
25 typedef std::pair<UT_String, UT_String> UT_StringPair;
27 
28 #define PRM_DEFAULT_PRESET "Permanent Defaults"
29 
31 public:
32  /// Subdir is the name of the sub directory where the preset file can be
33  /// found. Since presets can be also loaded from HDAs, subdir is synonymous
34  /// with the operator table name (eg "Object"), except it can contain
35  /// version which the constructor strips off (eg, "Object12.5.100",
36  /// used for operator state parm dialogs.
37  /// File is the preset file name, which is the same as the operator
38  /// type it applies to (eg "myhda" or "ns::hda::1.0), the file name
39  /// will be groomed to ensure it is a valid file name (eg, "myhda" or
40  /// "ns-hda-1.0". By providing the unaltered optype name, it is possible
41  /// to locate presets inside the HDA sections, which otherwise would be
42  /// more difficult for namespaced optypes.
43  PRM_PresetInfo(const char *subdir, const char *file);
44  virtual ~PRM_PresetInfo();
45 
46  void setIndexFile(const char *subdir);
47  void setNeedsRefresh();
48 
49  int getNumPresets();
50  const UT_String &getPresetName(int i);
51  const UT_String &getPresetPath(int i);
52  const UT_String &getPresetFile();
53  const UT_String &getPresetSection();
54  int getDefaultPreset();
55  int getPresetIndex(const char *presetname);
56 
57  bool deletePresetFromDir(const char *name,
58  const char *dir = 0);
59  bool savePresetToDir(PRM_ParmList *parmlist,
60  const char *name,
61  const char *dir);
62  bool loadPresetFile(PRM_ParmList *parmlist,
63  const char *filename);
64  bool savePresetFile(PRM_ParmList *parmlist,
65  const char *filename);
66 
67  // Should probably wrap these in an UT_ErrorManager::Scope so that they
68  // will not fail because some other non-related error still exists
69  // in the current UT_ErrorManager. We've had interesting problems
70  // like that before.
71  bool savePreset(PRM_ParmList *parmlist, std::ostream &os);
72  bool loadPreset(PRM_ParmList *parmlist, UT_IStream &is);
73 
74  // This function makes sure the file name ends with ".preset".
75  static void makeValidPresetFileName(UT_String &filename);
76 
77  static const UT_StringArray &getValidSaveDirs();
78 
79  // Handle loading of basic contents (channels, values)
80  static bool loadPresetContents(PRM_ParmList *parmlist,
81  const char *token, UT_IStream &is);
82 
83 private:
84  void clear();
85  void findAllPresets();
86  void refreshIfRequired();
87 
88  static int comparePresets(UT_StringPair * const *p1,
89  UT_StringPair * const *p2);
90 
91  UT_String mySubdir;
92  UT_String myIndexFile;
93  UT_String myPresetFile;
94  UT_String myPresetSection;
95  UT_StringPairList myPresets;
96  bool myNeedsRefresh;
97 };
98 
99 #endif
GT_API const UT_StringHolder filename
GLuint const GLchar * name
Definition: glcorearb.h:786
std::pair< UT_String, UT_String > UT_StringPair
UT_ValArray< UT_StringPair * > UT_StringPairList
#define PRM_API
Definition: PRM_API.h:10