HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_CvexCode.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __HUSD_CvexCode__
19 #define __HUSD_CvexCode__
20 
21 #include "HUSD_API.h"
22 #include <UT/UT_StringHolder.h>
23 
24 /// Abstracts the CVEX source code (either command or vexpression), along
25 /// with some aspects of it, such as return type and export parameter mask
26 /// for expressions.
28 {
29 public:
30  /// Creates the cvex code object given the string and its meaning.
31  HUSD_CvexCode( const UT_StringRef &cmd_or_vexpr, bool is_cmd = true );
32 
33  /// Returns the source string (either a command or vexpression).
34  const UT_StringHolder & getSource() const
35  { return mySource; }
36 
37  /// Returns true if the source is a command, or false if it's a vexpression.
38  bool isCommand() const
39  { return myIsCommand; }
40 
41  // Lists return types.
42  enum class ReturnType
43  {
44  NONE, // void type (usually all output parameters are used)
45  BOOLEAN, // true/false for selection of entities
46  STRING, // for keyword value
47  };
48 
49  /// @{ Sets the return type for the code.
50  /// Cvex scripts that select (match) primitives or faces return a boolean.
51  /// Cvex scripts that partition with keyword, usually return a string.
52  /// Cvex scripts that partition with all outupt values, or run on all
53  /// attributes (ie, are not used for selection or partitionin),
54  /// usually return void (which is a default value).
56  { myReturnType = type; }
58  { return myReturnType; }
59  /// @}
60 
61  /// @{ Sets the export variables (useful for Vexpressions)
63  { myExportsPattern = pattern; }
65  { return myExportsPattern; }
66 
67 private:
68  UT_StringHolder mySource; // command or expression source code
69  bool myIsCommand; // true if source is a command line
70  ReturnType myReturnType; // return type of the vexpression
71  UT_StringHolder myExportsPattern; // VEX export variables
72 };
73 
74 #endif
75 
ReturnType getReturnType() const
Definition: HUSD_CvexCode.h:57
#define HUSD_API
Definition: HUSD_API.h:32
void setReturnType(ReturnType type)
Definition: HUSD_CvexCode.h:55
const UT_StringHolder & getExportsPattern() const
Sets the export variables (useful for Vexpressions)
Definition: HUSD_CvexCode.h:64
GLushort pattern
Definition: glad.h:2583
MX_GENSHADER_API const TypeDesc * STRING
MX_GENSHADER_API const TypeDesc * BOOLEAN
bool isCommand() const
Returns true if the source is a command, or false if it's a vexpression.
Definition: HUSD_CvexCode.h:38
type
Definition: core.h:1059
const UT_StringHolder & getSource() const
Returns the source string (either a command or vexpression).
Definition: HUSD_CvexCode.h:34
void setExportsPattern(const UT_StringRef &pattern)
Sets the export variables (useful for Vexpressions)
Definition: HUSD_CvexCode.h:62