This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
registry.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_PLUG_REGISTRY_H
8#define PXR_BASE_PLUG_REGISTRY_H
9
10#include "pxr/pxr.h"
11#include "pxr/base/plug/api.h"
12
13#include "pxr/base/js/value.h"
15#include "pxr/base/tf/hash.h"
16#include "pxr/base/tf/hashset.h"
17#include "pxr/base/tf/refPtr.h"
19#include "pxr/base/tf/type.h"
21#include "pxr/base/tf/weakPtr.h"
22
23#include <mutex>
24#include <string>
25#include <vector>
26
27PXR_NAMESPACE_OPEN_SCOPE
28
30class Plug_RegistrationMetadata;
31
318
319class PlugRegistry : public TfWeakBase {
320 PlugRegistry(PlugRegistry const &) = delete;
321 PlugRegistry &operator=(PlugRegistry const &) = delete;
322public:
323 typedef PlugRegistry This;
324 typedef std::vector<TfType> TypeVector;
325
327 PLUG_API
329
332 PLUG_API
333 PlugPluginPtrVector RegisterPlugins(const std::string & pathToPlugInfo);
334
337 PLUG_API
338 PlugPluginPtrVector
339 RegisterPlugins(const std::vector<std::string> & pathsToPlugInfo);
340
349 PLUG_API
350 static TfType FindTypeByName(std::string const &typeName);
351
361 PLUG_API
362 static TfType
363 FindDerivedTypeByName(TfType base, std::string const &typeName);
364
374 template <class Base>
375 static TfType
376 FindDerivedTypeByName(std::string const &typeName) {
377 return FindDerivedTypeByName(TfType::Find<Base>(), typeName);
378 }
379
384 PLUG_API
385 static std::vector<TfType>
387
394 PLUG_API
395 static void
396 GetAllDerivedTypes(TfType base, std::set<TfType> *result);
397
404 template <class Base>
405 static void
406 GetAllDerivedTypes(std::set<TfType> *result) {
407 return GetAllDerivedTypes(TfType::Find<Base>(), result);
408 }
409
412 PLUG_API
413 PlugPluginPtr GetPluginForType(TfType t) const;
414
417 PLUG_API
418 PlugPluginPtrVector GetAllPlugins() const;
419
423 PLUG_API
424 PlugPluginPtr GetPluginWithName(const std::string& name) const;
425
428 PLUG_API
430 const std::string &key) const;
431
434 PLUG_API
436 const std::string &key) const;
437
438private:
439 // Private ctor and dtor since this is a constructed as a singleton.
440 PLUG_LOCAL
441 PlugRegistry();
442
443 // Registers all plug-ins discovered in any of \a pathsToPlugInfo
444 // but does not send a notice. The priority order of paths is honored if
445 // pathsAreOrdered.
446 PLUG_LOCAL
447 PlugPluginPtrVector
448 _RegisterPlugins(const std::vector<std::string>& pathsToPlugInfo,
449 bool pathsAreOrdered);
450
451 template <class ConcurrentVector>
452 PLUG_LOCAL
453 void _RegisterPlugin(const Plug_RegistrationMetadata&,
454 ConcurrentVector *newPlugins);
455 PLUG_LOCAL
456 bool _InsertRegisteredPluginPath(const std::string &path);
457
458 friend class TfSingleton< PlugRegistry >;
459 friend class PlugPlugin; // For _RegisterPlugins().
460
461private:
462 TfHashSet<std::string, TfHash> _registeredPluginPaths;
463
464 std::mutex _mutex;
465};
466
467PLUG_API_TEMPLATE_CLASS(TfSingleton<PlugRegistry>);
468
469PXR_NAMESPACE_CLOSE_SCOPE
470
471#endif // PXR_BASE_PLUG_REGISTRY_H
A discriminated union type for JSON values.
Definition: value.h:45
Defines an interface to registered plugins.
Definition: plugin.h:40
Defines an interface for registering plugins.
Definition: registry.h:319
static void GetAllDerivedTypes(std::set< TfType > *result)
Return the set of all types derived (directly or indirectly) from Base.
Definition: registry.h:406
PLUG_API PlugPluginPtrVector RegisterPlugins(const std::vector< std::string > &pathsToPlugInfo)
Registers all plug-ins discovered in any of pathsToPlugInfo.
PLUG_API PlugPluginPtr GetPluginForType(TfType t) const
Returns the plug-in for the given type, or a null pointer if there is no registered plug-in.
PLUG_API JsValue GetDataFromPluginMetaData(TfType type, const std::string &key) const
Looks for a JsValue associated with type and key and returns it, or a null JsValue if type or key are...
PLUG_API std::string GetStringFromPluginMetaData(TfType type, const std::string &key) const
Looks for a string associated with type and key and returns it, or an empty string if type or key are...
PLUG_API PlugPluginPtrVector GetAllPlugins() const
Returns all registered plug-ins.
static PLUG_API std::vector< TfType > GetDirectlyDerivedTypes(TfType base)
Return a vector of types derived directly from base.
static PLUG_API PlugRegistry & GetInstance()
Returns the singleton PlugRegistry instance.
static PLUG_API TfType FindDerivedTypeByName(TfType base, std::string const &typeName)
Retrieve the TfType that derives from base and has the given alias or type name typeName.
PLUG_API PlugPluginPtr GetPluginWithName(const std::string &name) const
Returns a plugin with the specified library name.
static PLUG_API TfType FindTypeByName(std::string const &typeName)
Retrieve the TfType corresponding to the given name.
static TfType FindDerivedTypeByName(std::string const &typeName)
Retrieve the TfType that derives from Base and has the given alias or type name typeName.
Definition: registry.h:376
PLUG_API PlugPluginPtrVector RegisterPlugins(const std::string &pathToPlugInfo)
Registers all plug-ins discovered at pathToPlugInfo.
static PLUG_API void GetAllDerivedTypes(TfType base, std::set< TfType > *result)
Return the set of all types derived (directly or indirectly) from base.
Manage a single instance of an object (see.
Definition: singleton.h:105
TfType represents a dynamic runtime type.
Definition: type.h:48
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
Standard pointer typedefs.
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
Definition: declarePtrs.h:45
Reference counting.
Manage a single instance of an object.
Pointer storage with deletion detection.