HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
STY_Binding.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_Binding.h ( STY Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __STY_Binding__
12 #define __STY_Binding__
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_NonCopyable.h>
19 #include <UT/UT_IntrusivePtr.h>
20 
21 class UT_JSONValue;
22 class UT_JSONValueMap;
23 
24 // ===========================================================================
25 /// Defines a data binding for the script argument.
27  public UT_NonCopyable,
28  public UT_IntrusiveRefCounter<STY_Binding>
29 {
30 public:
31  /// Describes what kind of data the argument is bound to.
33  {
34  SOURCE_DEFAULT, // Default (first try fully matched subject,
35  // and if data not found, try pre-bindings).
36  SOURCE_PREBINDING, // Data taken from partial match subjects.
37  SOURCE_CONSTANT, // Constant value set right in the style sheet.
38  };
39 
40  /// Creates a binding definition for the given argument name and
41  /// the json value that describes the data source.
42  STY_Binding(const UT_StringHolder &arg_name,
43  const UT_JSONValue *json);
44  STY_Binding(const UT_StringHolder &arg_name,
45  const STY_ConstantHandle &const_value);
46  STY_Binding(DataSourceType data_source_type,
47  const UT_StringHolder &arg_name,
48  const UT_StringHolder &data_name,
49  const STY_ConstantHandle &const_value);
50  ~STY_Binding();
51 
52  /// Loads binding array from a given json value. The caller owns the
53  /// binding objects returned in the array.
54  static bool loadBindings(UT_Array<STY_BindingHandle> &bindings,
55  const UT_JSONValue *json);
56 
57  /// @{ Getters for binding definition items.
59  { return myDataSourceType; }
60  const UT_StringHolder &getArgName() const
61  { return myArgName; }
63  { return myDataName; }
66  { return myConstantDataSource; }
67  STY_ConstantHandle getConstantValue() const;
68  /// @}
69 
70  /// Save this binding as JSON to a style sheet.
71  void saveStyleSheet(UT_JSONValueMap *map) const;
72 
73 private:
74  void loadBindingFromMap(const UT_JSONValue *json);
75 
76  DataSourceType myDataSourceType;
77  UT_StringHolder myArgName;
78  UT_StringHolder myDataName;
79  STY_BindingDataSourceHandle myConstantDataSource;
80 };
81 
82 #endif
83 
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
DataSourceType getDataSourceType() const
Getters for binding definition items.
Definition: STY_Binding.h:58
Defines a data binding for the script argument.
Definition: STY_Binding.h:26
#define STY_API
Definition: STY_API.h:10
A reference counter base class for use with UT_IntrusivePtr.
UT_SharedPtr< const STY_Constant > STY_ConstantHandle
Definition: STY_Types.h:90
const UT_StringHolder & getArgName() const
Getters for binding definition items.
Definition: STY_Binding.h:60
const UT_StringHolder & getDataName() const
Getters for binding definition items.
Definition: STY_Binding.h:62
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
const STY_BindingDataSourceHandle & getConstantDataSource() const
Getters for binding definition items.
Definition: STY_Binding.h:65
DataSourceType
Describes what kind of data the argument is bound to.
Definition: STY_Binding.h:32