All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
textParserContext.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef SDF_TEXTPARSERCONTEXT_H
25 #define SDF_TEXTPARSERCONTEXT_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/sdf/data.h"
29 #include "pxr/usd/sdf/layerOffset.h"
30 #include "pxr/usd/sdf/listOp.h"
31 #include "pxr/usd/sdf/parserValueContext.h"
32 #include "pxr/usd/sdf/path.h"
33 #include "pxr/usd/sdf/payload.h"
34 #include "pxr/usd/sdf/reference.h"
35 #include "pxr/usd/sdf/types.h"
36 
37 #include "pxr/base/vt/dictionary.h"
38 
39 #include "pxr/base/tf/token.h"
40 
41 #include <boost/optional.hpp>
42 
43 #include <string>
44 #include <vector>
45 
46 // Lexical scanner type.
47 typedef void *yyscan_t;
48 
49 PXR_NAMESPACE_OPEN_SCOPE
50 
51 // This class contains the global state while parsing a menva file.
52 // It contains the data structures that we use to create the scene description
53 // from the file.
54 
55 class Sdf_TextParserContext {
56 public:
57  // Constructor.
58  Sdf_TextParserContext();
59 
60  // Destructor.
61  ~Sdf_TextParserContext() {
62  }
63 
64  std::string magicIdentifierToken;
65  std::string versionString;
66  std::string fileContext;
67 
68  // State for layer refs, in general
69  std::string layerRefPath;
70  SdfLayerOffset layerRefOffset;
71 
72  // State for sublayers
73  std::vector<std::string> subLayerPaths;
74 
75  // State for sublayer offsets
76  std::vector<SdfLayerOffset> subLayerOffsets;
77 
78  // String list currently being built
79  std::vector<TfToken> nameVector;
80 
81  SdfTimeSampleMap timeSamples;
82  double timeSampleTime;
83 
84  SdfPath savedPath;
85 
86  // Whether the current relationship target being parsed is allowed to
87  // have data like relational attributes.
88  bool relParsingAllowTargetData;
89  // relationship target paths that will be saved in a list op
90  // (use a boost::optional to track whether we have seen an opinion at all.)
91  boost::optional<SdfPathVector> relParsingTargetPaths;
92  // relationship target paths that will be appended to the relationship's
93  // list of target children.
94  SdfPathVector relParsingNewTargetChildren;
95 
96  // helpers for connection path parsing
97  SdfPathVector connParsingTargetPaths;
98  bool connParsingAllowConnectionData;
99 
100  // helpers for inherit path parsing
101  SdfPathVector inheritParsingTargetPaths;
102 
103  // helpers for specializes path parsing
104  SdfPathVector specializesParsingTargetPaths;
105 
106  // helpers for reference parsing
107  SdfReferenceVector referenceParsingRefs;
108 
109  // helpers for payload parsing
110  SdfPayloadVector payloadParsingRefs;
111 
112  // helper for relocates parsing
113  SdfRelocatesMap relocatesParsingMap;
114 
115  // helpers for generic metadata
116  TfToken genericMetadataKey;
117  SdfListOpType listOpType;
118 
119  // The value parser context
120  Sdf_ParserValueContext values;
121 
122  // Last parsed value
123  VtValue currentValue;
124 
125  // Vector of dictionaries used to parse nested dictionaries.
126  // The first element in the vector contains the last parsed dictionary.
127  std::vector<VtDictionary> currentDictionaries;
128 
129  bool seenError;
130 
131  bool custom;
132  SdfSpecifier specifier;
133  SdfDataRefPtr data;
134  SdfPath path;
135  TfToken typeName;
136  VtValue variability;
137  VtValue assoc;
138 
139  // Should we only read metadata from the file?
140  bool metadataOnly;
141 
142  // Stack for the child names of all the prims currently being parsed
143  // For instance if we're currently parsing /A/B then this vector
144  // will contain three elements:
145  // names of the root prims
146  // names of A's children
147  // names of B's children.
148  std::vector<std::vector<TfToken> > nameChildrenStack;
149 
150  // Stack for the property names of all the objects currently being parsed
151  std::vector<std::vector<TfToken> > propertiesStack;
152 
153  // Stack of names of variant sets being built.
154  std::vector<std::string> currentVariantSetNames;
155 
156  // Stack of names of variants for the variant sets being built
157  std::vector<std::vector<std::string> > currentVariantNames;
158 
159  unsigned int menvaLineNo;
160 
161  // Used by flex for reentrant parsing
162  yyscan_t scanner;
163 };
164 
165 PXR_NAMESPACE_CLOSE_SCOPE
166 
167 #endif // SDF_TEXTPARSERCONTEXT_H
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
SdfSpecifier
An enum that identifies the possible specifiers for an SdfPrimSpec.
Definition: types.h:123
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition: types.h:277
Represents a time offset and scale between layers.
Definition: layerOffset.h:61
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
std::map< double, VtValue > SdfTimeSampleMap
A map from sample times to sample values.
Definition: types.h:280