HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
STY_Target.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_Target.h ( STY Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __STY_Target__
12 #define __STY_Target__
13 
14 #include "STY_API.h"
15 #include "STY_Types.h"
16 #include "STY_TargetType.h"
17 #include <UT/UT_Array.h>
18 #include <UT/UT_UniquePtr.h>
19 #include <UT/UT_NonCopyable.h>
20 #include <UT/UT_IntrusivePtr.h>
21 
22 class UT_JSONValue;
23 class UT_JSONValueMap;
24 
25 /// The style target represents an abstract description of a style subject
26 /// to which the overrides should be applied. When a style sheet entry is
27 /// tested whether its overrides should be applied to a style subject,
28 /// it asks the given style subject to test its target for a match.
29 /// Thus, it is up to the style subject to interpret the target's requirement
30 /// data and decide if it satisfies them or not.
31 ///
32 /// The style target is purposely generic, because if it were specific then
33 /// each usecase of the targets would need to implement own specific target
34 /// meeting its needs, and it's hard to write own custom target class because
35 /// it needs to load from JSON into our style sheet class. In the future,
36 /// we may provide style target factory registration that uses targetType
37 /// to choose specific implementation class, but now there is no such mechanism.
38 ///
39 /// The style subject, on the other hand, is easy to subclass from, and thus
40 /// it is style subject's responsibility to perform the matching and processing
41 /// of style targets.
43  public UT_NonCopyable,
44  public UT_IntrusiveRefCounter<STY_Target>
45 {
46 public:
47  /// Constructor of a target based on JSON encoding.
48  /// The 'is_selftarget' flag is true for targets that refer to the subjects
49  /// that provided the style sheet definition (it's false for most cases).
50  STY_Target(const UT_JSONValue *json,
51  bool is_selftarget);
52  /// Construct from requirements and a subtarget.
54  const STY_TargetType &type,
55  const STY_TargetHandle &sub_target,
56  const STY_ConstantMap &requirements,
57  const UT_Array<STY_BindingHandle> *pre_bind);
58  ~STY_Target();
59 
60  /// Returns true if this target is a completely default target
61  /// specification (equivalent to no target specification at all in JSON).
62  /// This means a self target with no conditions, no bindings, and no
63  /// sub-target.
64  bool isEquivalentToNoTarget() const;
65 
66  /// Returns the label given to this target.
67  const UT_StringHolder &getLabel() const
68  { return myLabel; }
69 
70  /// Returns the target type. It's a basic constraint that many style
71  /// subjects test before proceeding with further tests.
72  const STY_TargetType &getType() const
73  { return myType; }
74 
75  /// Returns the target requirements in the form of key-value dictionary.
76  /// Subjects query data in this dictionary to retrieve the values they
77  /// deem to necessary to match.
79  { return myTargetRequirements; }
80 
81  /// Convenience getter for requirement string. Returns NULL if the
82  /// key is not in the requirements. See the STY_REQUIREMENT constants
83  /// defined in STY_Types.h for the most common cases.
84  const char *getRequirement(const UT_StringHolder &key) const;
85 
86  /// Returns an array of pre-binding, which contain names of the data
87  /// that should be retrieved from the subject that match this target.
88  /// The data (source) is usually stored in a match closure object,
89  /// and is used for input arguments of override scripts.
92  { return myPreBindings.get(); }
93 
94  /// Returns this target's sub-target than needs to be matched by subsequent
95  /// styling subject. Usually, styling subjects are arranged in a hiearchy
96  /// (eg, crowd geometry object > agent primitive > agent's shape), and
97  /// it is useful for the style target to mimic this hierarchy so that
98  /// each subject in the hierarchy has a corresponding target, with its
99  /// own set of requirements.
101  { return mySubTargetHandle; }
102 
103  /// Creates a JSON value map for saving to a style sheet.
104  void saveStyleSheet(UT_JSONValueMap *map,
105  const STY_TargetMatchClosureHandle &closure) const;
106 
107 private:
108  void loadStyleTarget(const UT_JSONValue *json);
109  bool loadStyleTargetPart(const UT_StringHolder &key,
110  const UT_JSONValue *value);
111 
112  /// A user-defined label for the target.
113  UT_StringHolder myLabel;
114 
115  /// Target type indended to serve for the basic identification of target.
116  STY_TargetType myType;
117 
118  /// Target's requirements specifications.
119  STY_ConstantMap myTargetRequirements;
120 
121  /// Target's pre-bindings for override script's input arguments.
122  /// These are the names of the data that should be retrieved from subjects
123  /// matching this target (usually a component of a compound target ).
125 
126  /// The next target that needs to be matched by the next styling subject.
127  STY_TargetHandle mySubTargetHandle;
128 };
129 
130 #endif
131 
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
#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
const UT_StringHolder & getLabel() const
Returns the label given to this target.
Definition: STY_Target.h:67
const UT_Array< STY_BindingHandle > * getPreBindings() const
Definition: STY_Target.h:91
const STY_TargetHandle & getSubTarget() const
Definition: STY_Target.h:100
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
Definition: core.h:1131
const STY_TargetType & getType() const
Definition: STY_Target.h:72
const STY_ConstantMap & getTargetRequirements() const
Definition: STY_Target.h:78
type
Definition: core.h:1059