Medical Imaging Interaction Toolkit  2018.4.99-b7f3afaa
Medical Imaging Interaction Toolkit
us::ModuleResource Class Reference

#include <usModuleResource.h>

Public Member Functions

 ModuleResource ()
 
 ModuleResource (const ModuleResource &resource)
 
 ~ModuleResource ()
 
ModuleResourceoperator= (const ModuleResource &resource)
 
bool operator< (const ModuleResource &resource) const
 
bool operator== (const ModuleResource &resource) const
 
bool operator!= (const ModuleResource &resource) const
 
bool IsValid () const
 
 operator bool_type () const
 
std::string GetName () const
 
std::string GetPath () const
 
std::string GetResourcePath () const
 
std::string GetBaseName () const
 
std::string GetCompleteBaseName () const
 
std::string GetSuffix () const
 
std::string GetCompleteSuffix () const
 
bool IsDir () const
 
bool IsFile () const
 
std::vector< std::string > GetChildren () const
 
std::vector< ModuleResourceGetChildResources () const
 
int GetSize () const
 
time_t GetLastModified () const
 

Detailed Description

Represents a resource (text file, image, etc.) embedded in a CppMicroServices module.

A ModuleResource object provides information about a resource (external file) which was embedded into this module's shared library. ModuleResource objects can be obtained be calling Module::GetResource or Module::FindResources.

Example code for retreiving a resource object and reading its contents:

// Get this module's Module object
ModuleResource resource = module->GetResource("config.properties");
if (resource.IsValid())
{
// Create a ModuleResourceStream object
ModuleResourceStream resourceStream(resource);
// Read the contents line by line
std::string line;
while (std::getline(resourceStream, line))
{
// Process the content
std::cout << line << std::endl;
}
}
else
{
// Error handling
}

ModuleResource objects have value semantics and copies are very inexpensive.

See also
ModuleResourceStream
The Resources System

Definition at line 55 of file usModuleResource.h.

Constructor & Destructor Documentation

◆ ModuleResource() [1/2]

us::ModuleResource::ModuleResource ( )

Creates in invalid ModuleResource object.

Definition at line 102 of file usModuleResource.cpp.

Referenced by GetChildResources(), and ModuleResource().

◆ ModuleResource() [2/2]

us::ModuleResource::ModuleResource ( const ModuleResource resource)

Copy constructor.

Parameters
resourceThe object to be copied.

Definition at line 107 of file usModuleResource.cpp.

References ModuleResource(), and ModuleResourceContainer.

◆ ~ModuleResource()

us::ModuleResource::~ModuleResource ( )

Definition at line 130 of file usModuleResource.cpp.

Member Function Documentation

◆ GetBaseName()

std::string us::ModuleResource::GetBaseName ( ) const

Returns the base name of the resource without the path.

Example:

ModuleResource resource = module->GetResource("/data/archive.tar.gz");
std::string base = resource.GetBaseName(); // base = "archive"
Returns
The resource base name.
See also
GetName(), GetSuffix(), GetCompleteSuffix() and GetCompleteBaseName()

Definition at line 189 of file usModuleResource.cpp.

◆ GetChildren()

std::vector< std::string > us::ModuleResource::GetChildren ( ) const

Returns a list of resource names which are children of this object.

The returned names are relative to the path of this ModuleResource object and may contain file as well as directory entries.

Returns
A list of child resource names.

Definition at line 221 of file usModuleResource.cpp.

References IsDir(), and IsValid().

◆ GetChildResources()

std::vector< ModuleResource > us::ModuleResource::GetChildResources ( ) const

Returns a list of resource objects which are children of this object.

The return ModuleResource objects may contain files as well as directory resources.

Returns
A list of child resource objects.

Definition at line 233 of file usModuleResource.cpp.

References GetResourcePath(), IsDir(), IsValid(), and ModuleResource().

◆ GetCompleteBaseName()

std::string us::ModuleResource::GetCompleteBaseName ( ) const

Returns the complete base name of the resource without the path.

Example:

ModuleResource resource = module->GetResource("/data/archive.tar.gz");
std::string base = resource.GetCompleteBaseName(); // base = "archive.tar"
Returns
The resource's complete base name.
See also
GetName(), GetSuffix(), GetCompleteSuffix(), and GetBaseName()

Definition at line 194 of file usModuleResource.cpp.

◆ GetCompleteSuffix()

std::string us::ModuleResource::GetCompleteSuffix ( ) const

Returns the complete suffix of the resource.

The suffix consists of all characters in the resource name after (but not including) the first '.'.

Example:

ModuleResource resource = module->GetResource("/data/archive.tar.gz");
std::string suffix = resource.GetCompleteSuffix(); // suffix = "tar.gz"
Returns
The resource name suffix.
See also
GetName(), GetSuffix(), GetBaseName(), and GetCompleteBaseName()

Definition at line 205 of file usModuleResource.cpp.

◆ GetLastModified()

time_t us::ModuleResource::GetLastModified ( ) const

Returns the last modified time of this resource in seconds from the epoch.

Returns
Last modified time of this resource.

Definition at line 258 of file usModuleResource.cpp.

References GetResourcePath(), IsValid(), and US_HASH_FUNCTION().

◆ GetName()

std::string us::ModuleResource::GetName ( ) const

Returns the name of the resource, excluding the path.

Example:

ModuleResource resource = module->GetResource("/data/archive.tar.gz");
std::string name = resource.GetName(); // name = "archive.tar.gz"
Returns
The resource name.
See also
GetPath(), GetResourcePath()

Definition at line 174 of file usModuleResource.cpp.

Referenced by mitk::AbstractToFDeviceFactory::GetCameraIntrinsics(), and mitk::OclFilter::LoadSourceFiles().

◆ GetPath()

std::string us::ModuleResource::GetPath ( ) const

Returns the resource's path, without the file name.

Example:

ModuleResource resource = module->GetResource("/data/archive.tar.gz");
std::string path = resource.GetPath(); // path = "/data/"

The path with always begin and end with a forward slash.

Returns
The resource path without the name.
See also
GetResourcePath(), GetName() and IsDir()

Definition at line 179 of file usModuleResource.cpp.

◆ GetResourcePath()

std::string us::ModuleResource::GetResourcePath ( ) const

Returns the resource path including the file name.

Returns
The resource path including the file name.
See also
GetPath(), GetName() and IsDir()

Definition at line 184 of file usModuleResource.cpp.

Referenced by mitk::TrackingVolumeGenerator::GenerateData(), GetChildResources(), GetLastModified(), mitk::IOUtil::Load(), operator<(), and operator==().

◆ GetSize()

int us::ModuleResource::GetSize ( ) const

Returns the size of the resource data for this ModuleResource object.

Returns
The resource data size.

Definition at line 253 of file usModuleResource.cpp.

◆ GetSuffix()

std::string us::ModuleResource::GetSuffix ( ) const

Returns the suffix of the resource.

The suffix consists of all characters in the resource name after (but not including) the last '.'.

Example:

ModuleResource resource = module->GetResource("/data/archive.tar.gz");
std::string suffix = resource.GetSuffix(); // suffix = "gz"
Returns
The resource name suffix.
See also
GetName(), GetCompleteSuffix(), GetBaseName() and GetCompleteBaseName()

Definition at line 199 of file usModuleResource.cpp.

Referenced by QmitkToolSelectionBox::RecreateButtons().

◆ IsDir()

bool us::ModuleResource::IsDir ( ) const

Returns true if this ModuleResource object points to a directory and thus may have child resources.

Returns
true if this object points to a directory, false otherwise.

Definition at line 211 of file usModuleResource.cpp.

Referenced by GetChildren(), and GetChildResources().

◆ IsFile()

bool us::ModuleResource::IsFile ( ) const

Returns true if this ModuleResource object points to a file resource.

Returns
true if this object points to an embedded file, false otherwise.

Definition at line 216 of file usModuleResource.cpp.

Referenced by mitk::CustomTagParser::GetRevisionAppropriateJSONString(), mitk::GalilMotor::LoadResorceFile(), and mitk::QuantelLaser::LoadResorceFile().

◆ IsValid()

◆ operator bool_type()

us::ModuleResource::operator bool_type ( ) const

Boolean conversion operator using IsValid().

Definition at line 169 of file usModuleResource.cpp.

References IsValid().

◆ operator!=()

bool us::ModuleResource::operator!= ( const ModuleResource resource) const

Inequality operator for ModuleResource objects.

Parameters
resourceThe object for testing inequality.
Returns
The result of !(*this == resource).

Definition at line 159 of file usModuleResource.cpp.

◆ operator<()

bool us::ModuleResource::operator< ( const ModuleResource resource) const

A less then operator using the full resource path as returned by GetResourcePath() to define the ordering.

Parameters
resourceThe object to which this ModuleResource object is compared to.
Returns
true if this ModuleResource object is less then resource, false otherwise.

Definition at line 148 of file usModuleResource.cpp.

References GetResourcePath().

◆ operator=()

ModuleResource & us::ModuleResource::operator= ( const ModuleResource resource)

Assignment operator.

Parameters
resourceThe ModuleResource object which is assigned to this instance.
Returns
A reference to this ModuleResource instance.

Definition at line 136 of file usModuleResource.cpp.

◆ operator==()

bool us::ModuleResource::operator== ( const ModuleResource resource) const

Equality operator for ModuleResource objects.

Parameters
resourceThe object for testing equality.
Returns
true if this ModuleResource object is equal to resource, i.e. they are coming from the same module (shared or static) and have an equal resource path, false otherwise.

Definition at line 153 of file usModuleResource.cpp.

References GetResourcePath().


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