Skip to content

Commit d16eff0

Browse files
schmidkajstone-lucasfilm
authored andcommitted
Fix potential name conflict in type aliases (AcademySoftwareFoundation#127)
* Add forward declarations for classes used in type aliases. Without these a client could define e.g. a Material class before including MaterialXCore/Material.h, which would cause the type alias using MaterialPtr = shared_ptr<class Material>; to be interpreted as aliasing a ptr to the client's Material, rather than interpreted as aliasing a forward declaration of MaterialX::Material. * Remove `class` keyword from type aliases.
1 parent 1b23aef commit d16eff0

File tree

13 files changed

+153
-90
lines changed

13 files changed

+153
-90
lines changed

source/MaterialXCore/Definition.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,31 @@ extern const string GEOMETRIC_NODE_CATEGORY;
2525
extern const string ADJUSTMENT_NODE_CATEGORY;
2626
extern const string CONDITIONAL_NODE_CATEGORY;
2727

28+
class NodeDef;
29+
class Implementation;
30+
class TypeDef;
31+
class Member;
32+
class ShaderRef;
33+
2834
/// A shared pointer to a NodeDef
29-
using NodeDefPtr = shared_ptr<class NodeDef>;
35+
using NodeDefPtr = shared_ptr<NodeDef>;
3036
/// A shared pointer to a const NodeDef
31-
using ConstNodeDefPtr = shared_ptr<const class NodeDef>;
37+
using ConstNodeDefPtr = shared_ptr<const NodeDef>;
3238

3339
/// A shared pointer to an Implementation
34-
using ImplementationPtr = shared_ptr<class Implementation>;
40+
using ImplementationPtr = shared_ptr<Implementation>;
3541
/// A shared pointer to a const Implementation
36-
using ConstImplementationPtr = shared_ptr<const class Implementation>;
42+
using ConstImplementationPtr = shared_ptr<const Implementation>;
3743

3844
/// A shared pointer to a TypeDef
39-
using TypeDefPtr = shared_ptr<class TypeDef>;
45+
using TypeDefPtr = shared_ptr<TypeDef>;
4046
/// A shared pointer to a const TypeDef
41-
using ConstTypeDefPtr = shared_ptr<const class TypeDef>;
47+
using ConstTypeDefPtr = shared_ptr<const TypeDef>;
4248

4349
/// A shared pointer to a Member
44-
using MemberPtr = shared_ptr<class Member>;
50+
using MemberPtr = shared_ptr<Member>;
4551
/// A shared pointer to a const Member
46-
using ConstMemberPtr = shared_ptr<const class Member>;
52+
using ConstMemberPtr = shared_ptr<const Member>;
4753

4854
/// @class NodeDef
4955
/// A node definition element within a Document.
@@ -59,7 +65,7 @@ class NodeDef : public InterfaceElement
5965
}
6066
virtual ~NodeDef() { }
6167

62-
using ShaderRefPtr = shared_ptr<class ShaderRef>;
68+
using ShaderRefPtr = shared_ptr<ShaderRef>;
6369

6470
/// @name Node String
6571
/// @{

source/MaterialXCore/Document.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
namespace MaterialX
1919
{
2020

21+
class Document;
22+
2123
/// A shared pointer to a Document
22-
using DocumentPtr = shared_ptr<class Document>;
24+
using DocumentPtr = shared_ptr<Document>;
2325
/// A shared pointer to a const Document
24-
using ConstDocumentPtr = shared_ptr<const class Document>;
26+
using ConstDocumentPtr = shared_ptr<const Document>;
2527

2628
/// @class Document
2729
/// A MaterialX document, which represents the top-level element in the

source/MaterialXCore/Element.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,30 @@
1818
namespace MaterialX
1919
{
2020

21+
class Element;
22+
class TypedElement;
23+
class ValueElement;
24+
class StringResolver;
25+
class Document;
26+
class Material;
27+
2128
/// A shared pointer to an Element
22-
using ElementPtr = shared_ptr<class Element>;
29+
using ElementPtr = shared_ptr<Element>;
2330
/// A shared pointer to a const Element
24-
using ConstElementPtr = shared_ptr<const class Element>;
31+
using ConstElementPtr = shared_ptr<const Element>;
2532

2633
/// A shared pointer to a TypedElement
27-
using TypedElementPtr = shared_ptr<class TypedElement>;
34+
using TypedElementPtr = shared_ptr<TypedElement>;
2835
/// A shared pointer to a const TypedElement
29-
using ConstTypedElementPtr = shared_ptr<const class TypedElement>;
36+
using ConstTypedElementPtr = shared_ptr<const TypedElement>;
3037

3138
/// A shared pointer to a ValueElement
32-
using ValueElementPtr = shared_ptr<class ValueElement>;
39+
using ValueElementPtr = shared_ptr<ValueElement>;
3340
/// A shared pointer to a const ValueElement
34-
using ConstValueElementPtr = shared_ptr<const class ValueElement>;
41+
using ConstValueElementPtr = shared_ptr<const ValueElement>;
3542

3643
/// A shared pointer to a StringResolver
37-
using StringResolverPtr = shared_ptr<class StringResolver>;
44+
using StringResolverPtr = shared_ptr<StringResolver>;
3845

3946
/// A hash map from strings to elements
4047
using ElementMap = std::unordered_map<string, ElementPtr>;
@@ -61,9 +68,9 @@ class Element : public std::enable_shared_from_this<Element>
6168
virtual ~Element() { }
6269

6370
protected:
64-
using DocumentPtr = shared_ptr<class Document>;
65-
using ConstDocumentPtr = shared_ptr<const class Document>;
66-
using ConstMaterialPtr = shared_ptr<const class Material>;
71+
using DocumentPtr = shared_ptr<Document>;
72+
using ConstDocumentPtr = shared_ptr<const Document>;
73+
using ConstMaterialPtr = shared_ptr<const Material>;
6774

6875
template <class T> friend class ElementRegistry;
6976

source/MaterialXCore/Geom.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,42 @@ extern const string UNIVERSAL_GEOM_NAME;
2020
extern const string UDIM_TOKEN;
2121
extern const string UV_TILE_TOKEN;
2222

23+
class GeomElement;
24+
class GeomAttr;
25+
class GeomInfo;
26+
class Collection;
27+
class CollectionAdd;
28+
class CollectionRemove;
29+
2330
/// A shared pointer to a GeomElement
24-
using GeomElementPtr = shared_ptr<class GeomElement>;
31+
using GeomElementPtr = shared_ptr<GeomElement>;
2532
/// A shared pointer to a const GeomElement
26-
using ConstGeomElementPtr = shared_ptr<const class GeomElement>;
33+
using ConstGeomElementPtr = shared_ptr<const GeomElement>;
2734

2835
/// A shared pointer to a GeomAttr
29-
using GeomAttrPtr = shared_ptr<class GeomAttr>;
36+
using GeomAttrPtr = shared_ptr<GeomAttr>;
3037
/// A shared pointer to a const GeomAttr
31-
using ConstGeomAttrPtr = shared_ptr<const class GeomAttr>;
38+
using ConstGeomAttrPtr = shared_ptr<const GeomAttr>;
3239

3340
/// A shared pointer to a GeomInfo
34-
using GeomInfoPtr = shared_ptr<class GeomInfo>;
41+
using GeomInfoPtr = shared_ptr<GeomInfo>;
3542
/// A shared pointer to a const GeomInfo
36-
using ConstGeomInfoPtr = shared_ptr<const class GeomInfo>;
43+
using ConstGeomInfoPtr = shared_ptr<const GeomInfo>;
3744

3845
/// A shared pointer to a Collection
39-
using CollectionPtr = shared_ptr<class Collection>;
46+
using CollectionPtr = shared_ptr<Collection>;
4047
/// A shared pointer to a const Collection
41-
using ConstCollectionPtr = shared_ptr<const class Collection>;
48+
using ConstCollectionPtr = shared_ptr<const Collection>;
4249

4350
/// A shared pointer to a CollectionAdd
44-
using CollectionAddPtr = shared_ptr<class CollectionAdd>;
51+
using CollectionAddPtr = shared_ptr<CollectionAdd>;
4552
/// A shared pointer to a const CollectionAdd
46-
using ConstCollectionAddPtr = shared_ptr<const class CollectionAdd>;
53+
using ConstCollectionAddPtr = shared_ptr<const CollectionAdd>;
4754

4855
/// A shared pointer to a CollectionRemove
49-
using CollectionRemovePtr = shared_ptr<class CollectionRemove>;
56+
using CollectionRemovePtr = shared_ptr<CollectionRemove>;
5057
/// A shared pointer to a const CollectionRemove
51-
using ConstCollectionRemovePtr = shared_ptr<const class CollectionRemove>;
58+
using ConstCollectionRemovePtr = shared_ptr<const CollectionRemove>;
5259

5360
/// @class GeomElement
5461
/// The base class for geometric elements, which support bindings to geometries

source/MaterialXCore/Interface.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,38 @@
1616
namespace MaterialX
1717
{
1818

19+
class Parameter;
20+
class PortElement;
21+
class Input;
22+
class Output;
23+
class InterfaceElement;
24+
class Node;
25+
class NodeDef;
26+
1927
/// A shared pointer to a Parameter
20-
using ParameterPtr = shared_ptr<class Parameter>;
28+
using ParameterPtr = shared_ptr<Parameter>;
2129
/// A shared pointer to a const Parameter
22-
using ConstParameterPtr = shared_ptr<const class Parameter>;
30+
using ConstParameterPtr = shared_ptr<const Parameter>;
2331

2432
/// A shared pointer to a PortElement
25-
using PortElementPtr = shared_ptr<class PortElement>;
33+
using PortElementPtr = shared_ptr<PortElement>;
2634
/// A shared pointer to a const PortElement
27-
using ConstPortElementPtr = shared_ptr<const class PortElement>;
35+
using ConstPortElementPtr = shared_ptr<const PortElement>;
2836

2937
/// A shared pointer to an Input
30-
using InputPtr = shared_ptr<class Input>;
38+
using InputPtr = shared_ptr<Input>;
3139
/// A shared pointer to a const Input
32-
using ConstInputPtr = shared_ptr<const class Input>;
40+
using ConstInputPtr = shared_ptr<const Input>;
3341

3442
/// A shared pointer to an Output
35-
using OutputPtr = shared_ptr<class Output>;
43+
using OutputPtr = shared_ptr<Output>;
3644
/// A shared pointer to a const Output
37-
using ConstOutputPtr = shared_ptr<const class Output>;
45+
using ConstOutputPtr = shared_ptr<const Output>;
3846

3947
/// A shared pointer to an InterfaceElement
40-
using InterfaceElementPtr = shared_ptr<class InterfaceElement>;
48+
using InterfaceElementPtr = shared_ptr<InterfaceElement>;
4149
/// A shared pointer to a const InterfaceElement
42-
using ConstInterfaceElementPtr = shared_ptr<const class InterfaceElement>;
50+
using ConstInterfaceElementPtr = shared_ptr<const InterfaceElement>;
4351

4452
/// @class Parameter
4553
/// A parameter element within a Node or NodeDef.
@@ -90,7 +98,7 @@ class PortElement : public ValueElement
9098
virtual ~PortElement() { }
9199

92100
protected:
93-
using NodePtr = shared_ptr<class Node>;
101+
using NodePtr = shared_ptr<Node>;
94102

95103
public:
96104
/// @name Node Name
@@ -284,7 +292,7 @@ class InterfaceElement : public TypedElement
284292
virtual ~InterfaceElement() { }
285293

286294
protected:
287-
using NodeDefPtr = shared_ptr<class NodeDef>;
295+
using NodeDefPtr = shared_ptr<NodeDef>;
288296

289297
public:
290298
/// @name Parameters

source/MaterialXCore/Look.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,30 @@
1717
namespace MaterialX
1818
{
1919

20+
class Look;
21+
class LookInherit;
22+
class MaterialAssign;
23+
class Visibility;
24+
2025
/// A shared pointer to a Look
21-
using LookPtr = shared_ptr<class Look>;
26+
using LookPtr = shared_ptr<Look>;
2227
/// A shared pointer to a const Look
23-
using ConstLookPtr = shared_ptr<const class Look>;
28+
using ConstLookPtr = shared_ptr<const Look>;
2429

2530
/// A shared pointer to a LookInherit
26-
using LookInheritPtr = shared_ptr<class LookInherit>;
31+
using LookInheritPtr = shared_ptr<LookInherit>;
2732
/// A shared pointer to a const LookInherit
28-
using ConstLookInheritPtr = shared_ptr<const class LookInherit>;
33+
using ConstLookInheritPtr = shared_ptr<const LookInherit>;
2934

3035
/// A shared pointer to a MaterialAssign
31-
using MaterialAssignPtr = shared_ptr<class MaterialAssign>;
36+
using MaterialAssignPtr = shared_ptr<MaterialAssign>;
3237
/// A shared pointer to a const MaterialAssign
33-
using ConstMaterialAssignPtr = shared_ptr<const class MaterialAssign>;
38+
using ConstMaterialAssignPtr = shared_ptr<const MaterialAssign>;
3439

3540
/// A shared pointer to a Visibility
36-
using VisibilityPtr = shared_ptr<class Visibility>;
41+
using VisibilityPtr = shared_ptr<Visibility>;
3742
/// A shared pointer to a const Visibility
38-
using ConstVisibilityPtr = shared_ptr<const class Visibility>;
43+
using ConstVisibilityPtr = shared_ptr<const Visibility>;
3944

4045
/// @class Look
4146
/// A look element within a Document.

source/MaterialXCore/Material.h

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,44 @@
1717
namespace MaterialX
1818
{
1919

20+
class Material;
21+
class ShaderRef;
22+
class BindParam;
23+
class BindInput;
24+
class Override;
25+
class MaterialInherit;
26+
class MaterialAssign;
27+
class Collection;
28+
2029
/// A shared pointer to a Material
21-
using MaterialPtr = shared_ptr<class Material>;
30+
using MaterialPtr = shared_ptr<Material>;
2231
/// A shared pointer to a const Material
23-
using ConstMaterialPtr = shared_ptr<const class Material>;
32+
using ConstMaterialPtr = shared_ptr<const Material>;
2433

2534
/// A shared pointer to a ShaderRef
26-
using ShaderRefPtr = shared_ptr<class ShaderRef>;
35+
using ShaderRefPtr = shared_ptr<ShaderRef>;
2736
/// A shared pointer to a const ShaderRef
28-
using ConstShaderRefPtr = shared_ptr<const class ShaderRef>;
37+
using ConstShaderRefPtr = shared_ptr<const ShaderRef>;
2938

3039
/// A shared pointer to a BindParam
31-
using BindParamPtr = shared_ptr<class BindParam>;
40+
using BindParamPtr = shared_ptr<BindParam>;
3241
/// A shared pointer to a const BindParam
33-
using ConstBindParamPtr = shared_ptr<const class BindParam>;
42+
using ConstBindParamPtr = shared_ptr<const BindParam>;
3443

3544
/// A shared pointer to a BindInput
36-
using BindInputPtr = shared_ptr<class BindInput>;
45+
using BindInputPtr = shared_ptr<BindInput>;
3746
/// A shared pointer to a const BindInput
38-
using ConstBindInputPtr = shared_ptr<const class BindInput>;
47+
using ConstBindInputPtr = shared_ptr<const BindInput>;
3948

4049
/// A shared pointer to an Override
41-
using OverridePtr = shared_ptr<class Override>;
50+
using OverridePtr = shared_ptr<Override>;
4251
/// A shared pointer to a const Override
43-
using ConstOverridePtr = shared_ptr<const class Override>;
52+
using ConstOverridePtr = shared_ptr<const Override>;
4453

4554
/// A shared pointer to a MaterialInherit
46-
using MaterialInheritPtr = shared_ptr<class MaterialInherit>;
55+
using MaterialInheritPtr = shared_ptr<MaterialInherit>;
4756
/// A shared pointer to a const MaterialInherit
48-
using ConstMaterialInheritPtr = shared_ptr<const class MaterialInherit>;
57+
using ConstMaterialInheritPtr = shared_ptr<const MaterialInherit>;
4958

5059
/// @class Material
5160
/// A material element within a Document.
@@ -62,8 +71,8 @@ class Material : public Element
6271
virtual ~Material() { }
6372

6473
protected:
65-
using MaterialAssignPtr = shared_ptr<class MaterialAssign>;
66-
using CollectionPtr = shared_ptr<class Collection>;
74+
using MaterialAssignPtr = shared_ptr<MaterialAssign>;
75+
using CollectionPtr = shared_ptr<Collection>;
6776

6877
public:
6978
/// @name ShaderRef Elements

source/MaterialXCore/Node.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616
namespace MaterialX
1717
{
1818

19+
class Node;
20+
class NodeGraph;
21+
1922
/// A shared pointer to a Node
20-
using NodePtr = shared_ptr<class Node>;
23+
using NodePtr = shared_ptr<Node>;
2124
/// A shared pointer to a const Node
22-
using ConstNodePtr = shared_ptr<const class Node>;
25+
using ConstNodePtr = shared_ptr<const Node>;
2326

2427
/// A shared pointer to a NodeGraph
25-
using NodeGraphPtr = shared_ptr<class NodeGraph>;
28+
using NodeGraphPtr = shared_ptr<NodeGraph>;
2629
/// A shared pointer to a const NodeGraph
27-
using ConstNodeGraphPtr = shared_ptr<const class NodeGraph>;
30+
using ConstNodeGraphPtr = shared_ptr<const NodeGraph>;
2831

2932
/// @class Node
3033
/// A node element within a NodeGraph.

source/MaterialXCore/Observer.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414
namespace MaterialX
1515
{
1616

17+
class Observer;
18+
class ObservedDocument;
19+
1720
/// A shared pointer to an Observer
18-
using ObserverPtr = shared_ptr<class Observer>;
21+
using ObserverPtr = shared_ptr<Observer>;
1922
/// A shared pointer to a const Observer
20-
using ConstObserverPtr = shared_ptr<const class Observer>;
23+
using ConstObserverPtr = shared_ptr<const Observer>;
2124

2225
/// A shared pointer to an ObservedDocument
23-
using ObservedDocumentPtr = shared_ptr<class ObservedDocument>;
26+
using ObservedDocumentPtr = shared_ptr<ObservedDocument>;
2427
/// A shared pointer to a const ObservedDocument
25-
using ConstObservedDocumentPtr = shared_ptr<const class ObservedDocument>;
28+
using ConstObservedDocumentPtr = shared_ptr<const ObservedDocument>;
2629

2730
/// @class Observer
2831
/// An observer of a MaterialX Document.

0 commit comments

Comments
 (0)