HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
STY_OverrideScript.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: STY_OverrideScript.h ( STY Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __STY_OverrideScript__
12 #define __STY_OverrideScript__
13 
14 #include "STY_API.h"
15 #include "STY_Types.h"
16 #include <UT/UT_Array.h>
17 #include <UT/UT_StringHolder.h>
18 #include <UT/UT_UniquePtr.h>
19 #include <UT/UT_NonCopyable.h>
20 #include <UT/UT_IntrusivePtr.h>
21 
22 class STY_LoadContext;
23 class STY_ScriptCVEX;
25 class UT_JSONValue;
26 class UT_JSONValueMap;
27 class UT_StringArray;
28 
29 // ===========================================================================
30 /// Defines a helper interface for resolving CVEX command references.
31 /// Simply creating one of these objects registers it with the STY library
32 /// and it will subsequently be given an opportunity to resolve any override
33 /// script commands.
35 {
36 public:
38  virtual ~STY_ScriptNodeResolver();
39 
40  virtual bool resolveScriptNode(const char *node_path,
41  UT_StringHolder &command) const = 0;
42 };
43 
44 // ===========================================================================
45 /// Defines a script that computes an override value.
47  public UT_NonCopyable,
48  public UT_IntrusiveRefCounter<STY_OverrideScript>
49 {
50 public:
52  {
58  CODE_INLINE
59  };
60 
61  /// Creates an override script object and loads it from the given json.
62  /// If load context is not NULL, the script can resolve any references the
63  /// script may have (if it has no references, the context is not needed).
64  STY_OverrideScript(const UT_JSONValue *json,
65  const STY_LoadContext *load_context);
67  const CodeSourceType code_source,
68  const UT_StringHolder &code,
69  const UT_StringHolder &return_variable,
70  const UT_Array<STY_BindingHandle> *bindings);
72 
73  /// Obtains override values for multiple closures in one call. The data
74  /// can come back as either STY_Constant or UT_JSONValues.
75  bool createOverrideValues(
76  UT_Array<STY_ConstantHandle> *opt_values,
77  UT_JSONValue *json_values,
78  const STY_TargetMatchClosureHandle *closures,
79  int num_closures) const;
80 
81  /// Appends data names that this script is interested in for its input
82  /// argument binding.
83  void appendBindingDataNames(UT_StringArray &names) const;
84 
85  /// Save this override set as JSON to a style sheet.
86  void saveStyleSheet(UT_JSONValueMap *map,
87  bool allow_shared_scripts) const;
88 
89  /// Access the attributes that define the script.
90  CodeSourceType getCodeSource(bool from_import) const;
91  const UT_StringHolder &getCode(bool from_import) const;
92  const UT_StringHolder &getReturnVariable(bool from_import) const;
93  const UT_Array<STY_BindingHandle> *getBindings(bool from_import) const;
94 
95  /// Convert CodeSourceType to/from a string equivalent.
96  static const UT_StringHolder&codeSourceToStr(CodeSourceType code_source);
97  static CodeSourceType codeSourceFromStr(const UT_StringHolder &str);
98 
99 private:
100  /// Suffix for script function name to make sure it is unique.
101  const char *getMangleSuffix() const;
102 
103  // Helper methods for running the script.
104  void declareInputBindings(STY_ScriptCVEX &cvex,
105  const STY_TargetMatchClosureHandle *closure) const;
106  void bindInputData(STY_ScriptCVEX &cvex,
107  const STY_TargetMatchClosureHandle *closure) const;
108 
109  void saveStyleSheet(UT_JSONValueMap *map,
110  const UT_Array<STY_BindingHandle> *bindings,
111  const CodeSourceType code_source,
112  const UT_StringHolder &code,
113  const UT_StringHolder &return_variable,
114  bool allow_shared_scripts) const;
115 
116  CodeSourceType myCodeSource;
117  UT_StringHolder myCode;
118  UT_StringHolder myReturnVariable;
120  UT_UniquePtr<UT_Array<STY_BindingHandle> > myAutomaticBindings;
121  STY_OverrideScriptHandle myImportedScript;
122  UT_StringHolder myMangleSuffix;
123 };
124 
125 #endif
126 
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
#define STY_API
Definition: STY_API.h:10
A reference counter base class for use with UT_IntrusivePtr.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
Defines a script that computes an override value.
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99