VTK  9.3.20240619
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
vtkURILoader Class Reference

Helper class for readers and importer that need to load more than one resource. More...

#include <vtkURILoader.h>

Inheritance diagram for vtkURILoader:
[legend]
Collaboration diagram for vtkURILoader:
[legend]

Public Types

typedef vtkObject Superclass
 

Public Member Functions

virtual vtkTypeBool IsA (const char *type)
 Return 1 if this class is the same type of (or a subclass of) the named class.
 
vtkURILoaderNewInstance () const
 
void PrintSelf (ostream &os, vtkIndent indent) override
 Methods invoked by print to print information about the object including superclasses.
 
vtkURIGetBaseURI () const
 Get base URI.
 
bool HasBaseURI () const
 Check if loader as a base URI.
 
bool SetBaseFileName (VTK_FILEPATH const std::string &filepath)
 Higher level way to set the base URI to an existing file.
 
bool SetBaseDirectory (VTK_FILEPATH const std::string &dirpath)
 Higher level way to set the base URI to an existing directory.
 
vtkSmartPointer< vtkURIResolve (const vtkURI *uri)
 Resolve URI from base URI.
 
vtkSmartPointer< vtkResourceStreamLoad (const std::string &uri)
 Load a resource referenced by an URI.
 
vtkSmartPointer< vtkResourceStreamLoad (const char *uri, std::size_t size)
 Load a resource referenced by an URI.
 
vtkSmartPointer< vtkResourceStreamLoad (const vtkURI *uri)
 Try to resolve given URI from base URI, using vtkURI::Resolve.
 
vtkSmartPointer< vtkResourceStreamLoadResolved (const vtkURI *uri)
 Load a resource from a full URI.
 
bool SetBaseURI (const std::string &uri)
 Set base URI to use.
 
bool SetBaseURI (vtkURI *uri)
 Set base URI to use.
 
- Public Member Functions inherited from vtkObject
 vtkBaseTypeMacro (vtkObject, vtkObjectBase)
 
virtual void DebugOn ()
 Turn debugging output on.
 
virtual void DebugOff ()
 Turn debugging output off.
 
bool GetDebug ()
 Get the value of the debug flag.
 
void SetDebug (bool debugFlag)
 Set the value of the debug flag.
 
virtual void Modified ()
 Update the modification time for this object.
 
virtual vtkMTimeType GetMTime ()
 Return this object's modified time.
 
void PrintSelf (ostream &os, vtkIndent indent) override
 Methods invoked by print to print information about the object including superclasses.
 
void RemoveObserver (unsigned long tag)
 
void RemoveObservers (unsigned long event)
 
void RemoveObservers (const char *event)
 
void RemoveAllObservers ()
 
vtkTypeBool HasObserver (unsigned long event)
 
vtkTypeBool HasObserver (const char *event)
 
vtkTypeBool InvokeEvent (unsigned long event)
 
vtkTypeBool InvokeEvent (const char *event)
 
std::string GetObjectDescription () const override
 The object description printed in messages and PrintSelf output.
 
unsigned long AddObserver (unsigned long event, vtkCommand *, float priority=0.0f)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
unsigned long AddObserver (const char *event, vtkCommand *, float priority=0.0f)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
vtkCommandGetCommand (unsigned long tag)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
void RemoveObserver (vtkCommand *)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
void RemoveObservers (unsigned long event, vtkCommand *)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
void RemoveObservers (const char *event, vtkCommand *)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
vtkTypeBool HasObserver (unsigned long event, vtkCommand *)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
vtkTypeBool HasObserver (const char *event, vtkCommand *)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(), float priority=0.0f)
 Overloads to AddObserver that allow developers to add class member functions as callbacks for events.
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 Overloads to AddObserver that allow developers to add class member functions as callbacks for events.
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, bool(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 Allow user to set the AbortFlagOn() with the return value of the callback method.
 
vtkTypeBool InvokeEvent (unsigned long event, void *callData)
 This method invokes an event and return whether the event was aborted or not.
 
vtkTypeBool InvokeEvent (const char *event, void *callData)
 This method invokes an event and return whether the event was aborted or not.
 
virtual void SetObjectName (const std::string &objectName)
 Set/get the name of this object for reporting purposes.
 
virtual std::string GetObjectName () const
 Set/get the name of this object for reporting purposes.
 
- Public Member Functions inherited from vtkObjectBase
const char * GetClassName () const
 Return the class name as a string.
 
virtual std::string GetObjectDescription () const
 The object description printed in messages and PrintSelf output.
 
virtual vtkTypeBool IsA (const char *name)
 Return 1 if this class is the same type of (or a subclass of) the named class.
 
virtual vtkIdType GetNumberOfGenerationsFromBase (const char *name)
 Given the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class).
 
virtual void Delete ()
 Delete a VTK object.
 
virtual void FastDelete ()
 Delete a reference to this object.
 
void InitializeObjectBase ()
 
void Print (ostream &os)
 Print an object to an ostream.
 
void Register (vtkObjectBase *o)
 Increase the reference count (mark as used by another object).
 
virtual void UnRegister (vtkObjectBase *o)
 Decrease the reference count (release by another object).
 
int GetReferenceCount ()
 Return the current reference count of this object.
 
void SetReferenceCount (int)
 Sets the reference count.
 
bool GetIsInMemkind () const
 A local state flag that remembers whether this object lives in the normal or extended memory space.
 
virtual void PrintHeader (ostream &os, vtkIndent indent)
 Methods invoked by print to print information about the object including superclasses.
 
virtual void PrintTrailer (ostream &os, vtkIndent indent)
 Methods invoked by print to print information about the object including superclasses.
 
virtual bool UsesGarbageCollector () const
 Indicate whether the class uses vtkGarbageCollector or not.
 

Static Public Member Functions

static vtkTypeBool IsTypeOf (const char *type)
 
static vtkURILoaderSafeDownCast (vtkObjectBase *o)
 
static vtkURILoaderNew ()
 
- Static Public Member Functions inherited from vtkObject
static vtkObjectNew ()
 Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
 
static void BreakOnError ()
 This method is called when vtkErrorMacro executes.
 
static void SetGlobalWarningDisplay (vtkTypeBool val)
 This is a global flag that controls whether any debug, warning or error messages are displayed.
 
static void GlobalWarningDisplayOn ()
 This is a global flag that controls whether any debug, warning or error messages are displayed.
 
static void GlobalWarningDisplayOff ()
 This is a global flag that controls whether any debug, warning or error messages are displayed.
 
static vtkTypeBool GetGlobalWarningDisplay ()
 This is a global flag that controls whether any debug, warning or error messages are displayed.
 
- Static Public Member Functions inherited from vtkObjectBase
static vtkTypeBool IsTypeOf (const char *name)
 Return 1 if this class type is the same type of (or a subclass of) the named class.
 
static vtkIdType GetNumberOfGenerationsFromBaseType (const char *name)
 Given a the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class).
 
static vtkObjectBaseNew ()
 Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
 
static void SetMemkindDirectory (const char *directoryname)
 The name of a directory, ideally mounted -o dax, to memory map an extended memory space within.
 
static bool GetUsingMemkind ()
 A global state flag that controls whether vtkObjects are constructed in the usual way (the default) or within the extended memory space.
 

Protected Member Functions

virtual vtkObjectBaseNewInstanceInternal () const
 
 vtkURILoader ()
 Constructor.
 
 ~vtkURILoader () override
 
 vtkURILoader (const vtkURILoader &)=delete
 
vtkURILoaderoperator= (const vtkURILoader &)=delete
 
virtual vtkSmartPointer< vtkResourceStreamDoLoad (const vtkURI &uri)
 Load a resource from a full URI.
 
vtkSmartPointer< vtkResourceStreamLoadFile (const vtkURI &uri)
 Load a resource from a file URI.
 
vtkSmartPointer< vtkResourceStreamLoadData (const vtkURI &uri)
 Load a resource from a data URI.
 
- Protected Member Functions inherited from vtkObject
 vtkObject ()
 
 ~vtkObject () override
 
void RegisterInternal (vtkObjectBase *, vtkTypeBool check) override
 
void UnRegisterInternal (vtkObjectBase *, vtkTypeBool check) override
 
void InternalGrabFocus (vtkCommand *mouseEvents, vtkCommand *keypressEvents=nullptr)
 These methods allow a command to exclusively grab all events.
 
void InternalReleaseFocus ()
 These methods allow a command to exclusively grab all events.
 
- Protected Member Functions inherited from vtkObjectBase
 vtkObjectBase ()
 
virtual ~vtkObjectBase ()
 
virtual void RegisterInternal (vtkObjectBase *, vtkTypeBool check)
 
virtual void UnRegisterInternal (vtkObjectBase *, vtkTypeBool check)
 
virtual void ReportReferences (vtkGarbageCollector *)
 
virtual void ObjectFinalize ()
 
 vtkObjectBase (const vtkObjectBase &)
 
void operator= (const vtkObjectBase &)
 

Additional Inherited Members

- Static Protected Member Functions inherited from vtkObjectBase
static vtkMallocingFunction GetCurrentMallocFunction ()
 
static vtkReallocingFunction GetCurrentReallocFunction ()
 
static vtkFreeingFunction GetCurrentFreeFunction ()
 
static vtkFreeingFunction GetAlternateFreeFunction ()
 
- Protected Attributes inherited from vtkObject
bool Debug
 
vtkTimeStamp MTime
 
vtkSubjectHelper * SubjectHelper
 
std::string ObjectName
 
- Protected Attributes inherited from vtkObjectBase
std::atomic< int32_t > ReferenceCount
 
vtkWeakPointerBase ** WeakPointers
 

Detailed Description

Helper class for readers and importer that need to load more than one resource.

Introduction

vtkURILoader is a class that will load URIs, giving vtkResourceStreams from resolved resource. URI logic (parsing, resolution) is implemented in vtkURI.

Some formats, such as GLTF, may refer to external resources through URIs. This URI loader can be used to solve this problem.

vtkURILoader provides "file" and "data" URIs loading. "file" URIs loading only supports localhost. More schemes may be supported in future versions.

Base URI

Base URI, specified in RFC3986#5, is a concept that enable URIs to refer to relative resources from a base resource. For example, you can have a file that needs to look for another file next to it. The best way to implement this, is to have the first file as the base URI, and the referenced file as a relative reference.

To set a local file as base URI, you should use SetBaseFileName, and for a local directory, you should use SetBaseDirectory. These functions generate a "file" URI from given path. For example, calling SetBaseFileName(".") will generate the following URI: "file:///<absolute-current-working-directory>/.". These functions should be used because they handle some platform specific details, such as adding a / at the beginning of the path on Windows, percent-encoding, resolving relative paths, "." and "..", checking that path exists and actual filesystem entry type is coherent.

If the loader has no base URI, it can only load full URIs. See vtkURI for more information.

Basic usage

Here is a basic example of vtkURILoader usage:

loader->SetBaseFileName("."); // Set current working directory as the base URI
// This Load call will parse the string to a vtkURI. In that case, the URI only has a path.
// Then it will be resolved from base URI. In that case, the current working directory:
// "file:///<cwd>/." + "example.txt" == "file:///<cwd>/example.txt"
// Then it will call the `DoLoad` function. This DoLoad function will check URI scheme,
// here "file", and call the right loading function. In that case LoadFile will be called.
// LoadFile will create a vtkFileResourceStream and open it on URI path.
auto stream = loader->Load("example.txt");
// stream is opened on ./example.txt... Or it is null, in case of error.
// When loading a full URI, base URI is ignored (see vtkURI::Resolve and RFC specs)
auto other = loader->Load("data:;base64,AAAA");
// other is a vtkMemoryResourceStream on the decoded base64 data. Here, 3 bytes, all equal to 0.
Allocate and hold a VTK object.
Definition vtkNew.h:160

Note that in previous example, loader->Load() actually returns a vtkResourceStream, the real type can be accessed through SafeDownCast.

Usage in readers

When implementing a reader, you should use vtkURILoader if the format can contain URIs. Here are the global guidelines of URI loader support in a reader:

Extension

vtkURILoader::DoLoad is responsible of actually loading a full URI. It is a virtual function, so it can be reimplemented to let the user support additional schemes. In case you want do support additional scheme, URI scheme and host should be case-insensitive as specified in RFC3986#6.2.2.1.

vtkURILoader::LoadFile and vtkURILoader::LoadData are the actual implementation of "file" and "data" URI loading.

Definition at line 99 of file vtkURILoader.h.

Member Typedef Documentation

◆ Superclass

Definition at line 104 of file vtkURILoader.h.

Constructor & Destructor Documentation

◆ vtkURILoader() [1/2]

vtkURILoader::vtkURILoader ( )
protected

Constructor.

Default constructed vtkURILoader has no base URI.

◆ ~vtkURILoader()

vtkURILoader::~vtkURILoader ( )
overrideprotected

◆ vtkURILoader() [2/2]

vtkURILoader::vtkURILoader ( const vtkURILoader )
protecteddelete

Member Function Documentation

◆ IsTypeOf()

static vtkTypeBool vtkURILoader::IsTypeOf ( const char *  type)
static

◆ IsA()

virtual vtkTypeBool vtkURILoader::IsA ( const char *  name)
virtual

Return 1 if this class is the same type of (or a subclass of) the named class.

Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.

Reimplemented from vtkObjectBase.

◆ SafeDownCast()

static vtkURILoader * vtkURILoader::SafeDownCast ( vtkObjectBase o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkURILoader::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkURILoader * vtkURILoader::NewInstance ( ) const

◆ PrintSelf()

void vtkURILoader::PrintSelf ( ostream &  os,
vtkIndent  indent 
)
overridevirtual

Methods invoked by print to print information about the object including superclasses.

Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from vtkObject.

◆ New()

static vtkURILoader * vtkURILoader::New ( )
static

◆ SetBaseURI() [1/2]

bool vtkURILoader::SetBaseURI ( const std::string &  uri)

Set base URI to use.

URI must be an absolute URI. It will be used by Resolve and Load(const vtkURI*) functions to resolve relative references.

It may be nullptr. HasBaseURI is a more explicit way to check that.

SetBaseURI(const std::string& uri) parses the URI from a string and then do the same as SetBaseURI(vtkURI* uri).

Base URI is manipulated as a non-const vtkURI because loader keep a owning reference on it.

Parameters
uriA string to parse, or an existing URI. Empty string is the same as nullptr. Existing URI Reference count will be increased.
Returns
true if uri is a suitable base URI (i.e. is absolute).

◆ SetBaseURI() [2/2]

bool vtkURILoader::SetBaseURI ( vtkURI uri)

Set base URI to use.

URI must be an absolute URI. It will be used by Resolve and Load(const vtkURI*) functions to resolve relative references.

It may be nullptr. HasBaseURI is a more explicit way to check that.

SetBaseURI(const std::string& uri) parses the URI from a string and then do the same as SetBaseURI(vtkURI* uri).

Base URI is manipulated as a non-const vtkURI because loader keep a owning reference on it.

Parameters
uriA string to parse, or an existing URI. Empty string is the same as nullptr. Existing URI Reference count will be increased.
Returns
true if uri is a suitable base URI (i.e. is absolute).

◆ GetBaseURI()

vtkURI * vtkURILoader::GetBaseURI ( ) const

Get base URI.

Returns
the pointer on base URI, may be nullptr.

◆ HasBaseURI()

bool vtkURILoader::HasBaseURI ( ) const
inline

Check if loader as a base URI.

Definition at line 140 of file vtkURILoader.h.

◆ SetBaseFileName()

bool vtkURILoader::SetBaseFileName ( VTK_FILEPATH const std::string &  filepath)

Higher level way to set the base URI to an existing file.

This generates a file URI on the absolute path of the specified filepath. filepath must refer to an existing file.

Parameters
filepathFile path to use as base URI. filepath may be relative, it will be automatically transformed into an absolute path.
Returns
true if filename can be resolved, false otherwise

◆ SetBaseDirectory()

bool vtkURILoader::SetBaseDirectory ( VTK_FILEPATH const std::string &  dirpath)

Higher level way to set the base URI to an existing directory.

This generates a file URI on the absolute path of the specified directory "." file. path must refer to an existing directory.

Parameters
dirpathFile path to use as base URI. dirpath may be relative, it will be automatically transformed into an absolute path.
Returns
true if path can be resolved, false otherwise

◆ Resolve()

vtkSmartPointer< vtkURI > vtkURILoader::Resolve ( const vtkURI uri)

Resolve URI from base URI.

Returns
vtkURI::Resolve(this->GetBaseURI(), uri);

◆ Load() [1/3]

vtkSmartPointer< vtkResourceStream > vtkURILoader::Load ( const std::string &  uri)
inline

Load a resource referenced by an URI.

Perform as if by calling this->Load(uri.data(), uri.size()).

Parameters
uriURI string representation, may be empty.
Returns
A vtkResourceStream on the loaded resource on success, nullptr otherwise.

Definition at line 180 of file vtkURILoader.h.

◆ Load() [2/3]

vtkSmartPointer< vtkResourceStream > vtkURILoader::Load ( const char *  uri,
std::size_t  size 
)

Load a resource referenced by an URI.

Try to parse an URI from given string using vtkURI::Parse. If parsing fails, returns nullptr immediately, otherwise, performs as if by calling Load(const vtkURI*) with parsed URI.

Parameters
uriAn URI string representation, may be nullptr if size is 0.
sizeSize of uri string, may be 0.
Returns
A vtkResourceStream on the loaded resource on success, nullptr otherwise.

◆ Load() [3/3]

vtkSmartPointer< vtkResourceStream > vtkURILoader::Load ( const vtkURI uri)

Try to resolve given URI from base URI, using vtkURI::Resolve.

If resolution fails, returns nullptr. Otherwise, performs as if by calling LoadResolved(const vtkURI*) with resolved URI.

Parameters
uriA vtkURI, must be a relative reference.
Returns
A vtkResourceStream on the loaded resource on success, nullptr otherwise.

◆ LoadResolved()

vtkSmartPointer< vtkResourceStream > vtkURILoader::LoadResolved ( const vtkURI uri)

Load a resource from a full URI.

Checks if URI is suitable for loading (i.e. is a full URI), then calls DoLoad(uri).

Parameters
uriA vtkURI, must be a full URI
Returns
A vtkResourceStream on the loaded resource on success, nullptr otherwise.

◆ operator=()

vtkURILoader & vtkURILoader::operator= ( const vtkURILoader )
protecteddelete

◆ DoLoad()

virtual vtkSmartPointer< vtkResourceStream > vtkURILoader::DoLoad ( const vtkURI uri)
protectedvirtual

Load a resource from a full URI.

Dispatch, depending on uri scheme:

  • LoadFile if scheme == "file"
  • LoadData if scheme == "data" If scheme is not one of these, returns nullptr and generates an error.

This function is virtual and may be reimplemented to support additional schemes or disable some schemes.

Parameters
uriA vtkURI, must be a full URI
Returns
A vtkResourceStream on the loaded resource on success, nullptr otherwise.

◆ LoadFile()

vtkSmartPointer< vtkResourceStream > vtkURILoader::LoadFile ( const vtkURI uri)
protected

Load a resource from a file URI.

Current implementation only supports localhost authority. Returned stream is a vtkFileResourceStream on URI path. Query and fragment are ignored.

Parameters
uriA vtkURI, must be a full file URI
Returns
A vtkResourceStream on the loaded resource on success, nullptr otherwise.

◆ LoadData()

vtkSmartPointer< vtkResourceStream > vtkURILoader::LoadData ( const vtkURI uri)
protected

Load a resource from a data URI.

Authority is ignored. Supports raw (percent-encoded) and base64-encoded data URI. If an error occurs during data decoding, returns nullptr. Query and fragment are ignored.

Returned stream is a vtkMemoryResourceStream on decoded data. The streams owns the data.

Parameters
uriA vtkURI, must be a full data URI
Returns
A vtkResourceStream on the loaded resource on success, nullptr otherwise.

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