All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
testPlugBase.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 TEST_PLUGBASE_H
25 #define TEST_PLUGBASE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/plug/api.h"
29 #include "pxr/base/tf/refBase.h"
30 #include "pxr/base/tf/stringUtils.h"
31 #include "pxr/base/tf/type.h"
32 #include "pxr/base/tf/weakBase.h"
33 
34 #include <string>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 template <int M>
39 class _TestPlugBase : public TfRefBase, public TfWeakBase {
40  public:
41  typedef _TestPlugBase This;
42  typedef TfRefPtr<This> RefPtr;
43  typedef TfWeakPtr<This> Ptr;
44  constexpr static int N = M;
45 
46  virtual ~_TestPlugBase() {}
47 
48  virtual std::string GetTypeName() {
49  return TfType::Find(this).GetTypeName();
50  }
51 
52  static RefPtr New() {
53  return TfCreateRefPtr(new This());
54  }
55 
56  PLUG_API
57  static RefPtr Manufacture(const std::string & subclass);
58 
59  protected:
60  _TestPlugBase() {}
61 };
62 
63 template <int N>
64 class _TestPlugFactoryBase : public TfType::FactoryBase {
65 public:
66  virtual TfRefPtr<_TestPlugBase<N> > New() const = 0;
67 };
68 
69 template <typename T>
70 class _TestPlugFactory : public _TestPlugFactoryBase<T::N> {
71 public:
72  virtual TfRefPtr<_TestPlugBase<T::N> > New() const
73  {
74  return T::New();
75  }
76 };
77 
78 typedef _TestPlugBase<1> _TestPlugBase1;
79 typedef _TestPlugBase<2> _TestPlugBase2;
80 typedef _TestPlugBase<3> _TestPlugBase3;
81 typedef _TestPlugBase<4> _TestPlugBase4;
82 
83 PXR_NAMESPACE_CLOSE_SCOPE
84 
85 #endif // TEST_PLUGBASE_H
TF_API const std::string & GetTypeName() const
Return the machine-independent name for this type.
static TfType const & Find()
Retrieve the TfType corresponding to type T.
Definition: type.h:155
Pointer storage with deletion detection.
Definition: hash.h:44
Base class of all factory types.
Definition: type.h:79
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:72
Reference-counted smart pointer utility class.
Definition: hash.h:45
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:142