Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::processes::ResourceRegistry< Type > Class Template Reference

A resource registry for a specific resource type. More...

#include <resource.h>

Inheritance diagram for MaxOS::processes::ResourceRegistry< Type >:
MaxOS::processes::BaseResourceRegistry

Public Member Functions

 ResourceRegistry (resource_type_t type)
 Constructor for ResourceRegistry of a specific type.
 
Resourcecreate_resource (const string &name, size_t flags) override
 Create a new resource of the specific type.
 
- Public Member Functions inherited from MaxOS::processes::BaseResourceRegistry
 BaseResourceRegistry (resource_type_t type)
 Constructs a new BaseResourceRegistry object and registers it globally.
 
 ~BaseResourceRegistry ()
 Destructor for BaseResourceRegistry, removes it from the global list.
 
resource_type_t type ()
 Gets the type of resources this registry handles.
 
virtual Resourceget_resource (const string &name)
 Gets a resource from the registry by name.
 
virtual bool register_resource (Resource *resource)
 Registers a resource in the registry.
 
virtual void close_resource (Resource *resource, size_t flags)
 Close the resource provided, if it exists in this registry.
 

Additional Inherited Members

- Protected Attributes inherited from MaxOS::processes::BaseResourceRegistry
common::Map< string, Resource * > m_resources
 The map of resource names to resource instances.
 
common::Map< string, uint64_t > m_resource_uses
 The map of resource names to how many processes are using them.
 
resource_type_t m_type
 The resource type that this registry manages.
 

Detailed Description

template<class Type>
class MaxOS::processes::ResourceRegistry< Type >

A resource registry for a specific resource type.

Template Parameters
TypeThe resource type that this registry manages

Definition at line 81 of file resource.h.

Constructor & Destructor Documentation

◆ ResourceRegistry()

template<class Type >
MaxOS::processes::ResourceRegistry< Type >::ResourceRegistry ( resource_type_t  type)
explicit

Constructor for ResourceRegistry of a specific type.

Template Parameters
TypeThe resource type that this registry manages
Parameters
typeThe resource type enum value

Definition at line 114 of file resource.h.

resource_type_t type()
Gets the type of resources this registry handles.
Definition resource.cpp:117
BaseResourceRegistry(resource_type_t type)
Constructs a new BaseResourceRegistry object and registers it globally.
Definition resource.cpp:98

Member Function Documentation

◆ create_resource()

template<class Type >
Resource * MaxOS::processes::ResourceRegistry< Type >::create_resource ( const string name,
size_t  flags 
)
inlineoverridevirtual

Create a new resource of the specific type.

Parameters
nameThe name of the resource
flagsThe flags to open the resource with
Returns
The created resource, or nullptr on failure

Reimplemented from MaxOS::processes::BaseResourceRegistry.

Definition at line 94 of file resource.h.

94 {
95
96 auto resource = new Type(name, flags, type());
97
98 // Creation failed
99 if(!register_resource(resource)) {
100 delete resource;
101 return nullptr;
102 }
103
104 return resource;
105 }
virtual bool register_resource(Resource *resource)
Registers a resource in the registry.
Definition resource.cpp:146

References MaxOS::processes::BaseResourceRegistry::register_resource(), and MaxOS::processes::BaseResourceRegistry::type().


The documentation for this class was generated from the following file: