HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_OpNamespaceHierarchy.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: OP_OpNamespaceHierarchy.h ( OP Library, C++)
7  *
8  * COMMENTS: A class that manages the hierarchy (precedence order)
9  * of the operator type namespaces.
10  */
11 
12 #ifndef __OP_OpNamespaceHierarchy__
13 #define __OP_OpNamespaceHierarchy__
14 
15 #include "OP_API.h"
16 #include <UT/UT_ArrayStringMap.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_StringHolder.h>
19 #include <UT/UT_UniquePtr.h>
20 
21 class UT_StringArray;
22 class op_OpPrecedenceList;
23 
24 
25 /// Implements an operator name resolution mechanism for unquallified (or
26 /// not fully qualified) operator names (ie, finds a full operator name with a
27 /// namespace and version tags, given a partial operatorn name, like just the
28 /// core name, or core name with a namespace but no version, where several
29 /// candidates may exist).
31 {
32 public:
33  // Constructor and destructor.
36 
37  /// Builds the operator definition hierarchy.
38  ///
39  /// @param hierarchy The string enumerating the namespace hierarchy.
40  /// @parm table_name The name of the operator table for which the
41  /// hierarchy is build.
42  void buildHierarchy( const char *hierarchy,
43  const char *table_name );
44 
45  /// Updates the hierarchy when an operator has been added to the table.
46  void handleOperatorAdded( const char *op_name );
47 
48  /// Updates the hierarchy when an operator has been removed from the table.
49  void handleOperatorRemoved( const char *op_name );
50 
51  /// Resolves a given optype name to a preferred optype name, in case
52  /// the given name is ambiguous and has several operator definition
53  /// candidates. For fully qualified or unambiguous names the method
54  /// will return the given argument.
55  ///
56  /// @param op_name The operator type name to resolve.
57  /// @param network_scope_stack The array of subnet optype names (
58  /// with the table name) inside which the operator
59  /// node would be created. The first element in the
60  /// array is the immediate parent, the second is
61  /// the granparent subnet, etc).
62  ///
63  /// @return The preferred operator type name for the given name.
64  const char * findPreferredOpName( const char *op_name,
65  const UT_StringArray *network_scope_stack);
66 
67  /// Obtains a list of available operator names that have the same base
68  /// (core) name as the given operator.
69  /// If scope network name is not NULL, the list includes only operators
70  /// whose nodes can be created in one of these networks (since they
71  /// represent the stack of nested scopes). Otherwise all operators are
72  /// included.
73  /// The list is sorted according to the descending precedence order.
74  void getPrecedenceOrder( UT_StringArray &precedence_order,
75  const char *op_name,
76  const UT_StringArray *network_scope_stack);
77 private:
78  /// @{
79  /// Helper method to access the precedence list for an operator.
80  op_OpPrecedenceList * getPrecedenceList( const char *op_name );
81  op_OpPrecedenceList * getOrCreatePrecedenceList( const char *op_name );
82  /// @}
83 
84  void buildPreferenceOrder( const char *hierarchy,
85  const char *table_name );
86 
87  void appendPrefIfApplicable( const char * pref,
88  const char * table_name );
89 
90 
91 private:
92  /// Map from the core operator name to the list of operators ordered
93  /// in descending preference order.
95 
96  /// A preference order list (list of op_PrefEntry objects)
97  /// constructed from the HOUDINI_OPNAMESPACE_HIERARCHY envvar. This list
98  /// represents the user's wishes as to which operators should take
99  /// precedence over which other ones. When sorting real operators
100  /// according to their precedence, we use this list as a template
101  /// against which we test which op should appear first in that precedence
102  /// list.
103  class op_PrefEntry;
104  UT_Array<op_PrefEntry> myPrefOrderList;
105 
106  friend class op_OpPrefEntryComparator;
107 };
108 
109 // ===========================================================================
110 /// Class representing an entry in an preference list.
111 /// It is different from op_OpEntry because it does not represent an operator
112 /// from the op table, but rather a pattern against which operators are
113 /// compared (many operators may match that entry, but also the pattern may
114 /// be narrow enough that it matchs only one operator).
116 {
117 public:
118  op_PrefEntry(const UT_StringHolder &scope_pattern,
119  const UT_StringHolder &namespace_pattern,
120  const UT_StringHolder &core_name_pattern,
121  const UT_StringHolder &version_pattern);
122 
123  /// Returns true if the given op entry matches this preference entry.
124  bool matches(const UT_WorkBuffer &scope_opname,
125  const UT_WorkBuffer &namespace_name,
126  const UT_WorkBuffer &core_name,
127  const UT_WorkBuffer &version) const;
128 
129 private:
130  // patterns for matching the operator name components
131  UT_StringHolder myScopePattern;
132  UT_StringHolder myNamespacePattern;
133  UT_StringHolder myCoreNamePattern;
134  UT_StringHolder myVersionPattern;
135 };
136 
137 #endif
138 
bool matches(const UT_WorkBuffer &scope_opname, const UT_WorkBuffer &namespace_name, const UT_WorkBuffer &core_name, const UT_WorkBuffer &version) const
Returns true if the given op entry matches this preference entry.
op_PrefEntry(const UT_StringHolder &scope_pattern, const UT_StringHolder &namespace_pattern, const UT_StringHolder &core_name_pattern, const UT_StringHolder &version_pattern)
GT_API const UT_StringHolder version
#define OP_API
Definition: OP_API.h:10
WARNING: This class DOES NOT ALLOW EMPTY STRING as a key!