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