Loading...
Searching...
No Matches
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
422 PLUG_API
423 PlugPluginPtr DemandPluginForType(TfType t) const;
424
427 PLUG_API
428 PlugPluginPtrVector GetAllPlugins() const;
429
433 PLUG_API
434 PlugPluginPtr GetPluginWithName(const std::string& name) const;
435
438 PLUG_API
440 const std::string &key) const;
441
444 PLUG_API
446 const std::string &key) const;
447
448private:
449 // Private ctor and dtor since this is a constructed as a singleton.
450 PLUG_LOCAL
451 PlugRegistry();
452
453 // Registers all plug-ins discovered in any of \a pathsToPlugInfo
454 // but does not send a notice. The priority order of paths is honored if
455 // pathsAreOrdered.
456 PLUG_LOCAL
457 PlugPluginPtrVector
458 _RegisterPlugins(const std::vector<std::string>& pathsToPlugInfo,
459 bool pathsAreOrdered);
460
461 template <class ConcurrentVector>
462 PLUG_LOCAL
463 void _RegisterPlugin(const Plug_RegistrationMetadata&,
464 ConcurrentVector *newPlugins);
465 PLUG_LOCAL
466 bool _InsertRegisteredPluginPath(const std::string &path);
467
468 friend class TfSingleton< PlugRegistry >;
469 friend class PlugPlugin; // For _RegisterPlugins().
470
471private:
472 TfHashSet<std::string, TfHash> _registeredPluginPaths;
473
474 std::mutex _mutex;
475};
476
477PLUG_API_TEMPLATE_CLASS(TfSingleton<PlugRegistry>);
478
479PXR_NAMESPACE_CLOSE_SCOPE
480
481#endif // PXR_BASE_PLUG_REGISTRY_H
A discriminated union type for JSON values.
Definition: value.h:47
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 PlugPluginPtr DemandPluginForType(TfType t) const
Return the plug-in for the given type, or issue a fatal error with diagnostic information and termina...
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.