hgl 0.5.25
A compiler/interpreter suite for developing images
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
HGL::Common::URI Class Reference

Class to access files locally and remote. More...

#include "uri.h"

Inherits std::istream.

Public Types

typedef std::set< std::string > PROTOCOLS
 Set of supported protocols.
 

Public Member Functions

 URI (const char *const uri) throw (HGL::Exception::IOException)
 Constructor More...
 
 URI (const char *const uri, const char *const mode) throw (HGL::Exception::IOException)
 Constructor More...
 
std::string getProtocol () const
 Gets the protocol. More...
 
__off_t getSize () const throw (HGL::Exception::IOException)
 Gets the size in bytes of the file. More...
 
std::string getURI () const
 Gets the URI. More...
 
bool isStdin () const
 Checks if this URI is attached to standard input. More...
 
 operator FILE * () const throw (HGL::Exception::IOException)
 Gets the FILE file descriptor of the file. More...
 
void operator>> (std::string &s) const throw (HGL::Exception::IOException)
 Reads the entire file into a std::string. More...
 
 throw (HGL::Exception::IOException)
 Constructor More...
 

Static Public Member Functions

static const PROTOCOLS getProtocols ()
 Gets a set of all supported protocols. More...
 
static bool isRemote (const std::string &uri)
 Checks if the URI is a remote URI. More...
 
static void prefetch (const std::string &uri, const char *const mode)
 Tries to prefetch a remote URL in background. More...
 
static void pushSearchPath (const std::string &searchPath, bool front=false)
 Pushes a path to the directories to prepend if the file is not found. More...
 

Static Public Attributes

static URI STDIN
 an URI which points to stdin
 

Detailed Description

Class to access files locally and remote.

This class handles the access of local files as well as remote files and from the standard input.

Since version 0.5.18 it implements std::istream and therefore can be used as input stream as well.

Author
Heiko Schäfer heiko.nosp@m.@hgl.nosp@m..rang.nosp@m.un.d.nosp@m.e

Constructor & Destructor Documentation

URI::URI ( const char *const  uri)
throw (HGL::Exception::IOException
)

Constructor

Creates an URI with open mode "r"

Parameters
uriURI to open
URI::URI ( const char *const  uri,
const char *const  mode 
)
throw (HGL::Exception::IOException
)

Constructor

Parameters
uriURI to open
modeopen mode, i.e. "r" or "rb"

Member Function Documentation

std::string URI::getProtocol ( ) const

Gets the protocol.

Returns
the protocol

Referenced by getURI().

const URI::PROTOCOLS URI::getProtocols ( )
static

Gets a set of all supported protocols.

Returns
a set of all supported protocols
__off_t URI::getSize ( ) const
throw (HGL::Exception::IOException
)

Gets the size in bytes of the file.

Returns
the size in bytes

References getURI().

std::string URI::getURI ( ) const

Gets the URI.

Returns
the URI

References getProtocol(), and isRemote().

Referenced by getSize().

bool URI::isRemote ( const std::string &  uri)
static

Checks if the URI is a remote URI.

Parameters
urithe uri to check
Returns
true, if the URI is remote, false otherwise

Referenced by getURI().

bool URI::isStdin ( ) const

Checks if this URI is attached to standard input.

Returns
true if attached to standard input, false otherwise
Since
0.5.18
URI::operator FILE * ( ) const
throw (HGL::Exception::IOException
)

Gets the FILE file descriptor of the file.

Returns
the FILE file descriptor
void URI::operator>> ( std::string &  s) const
throw (HGL::Exception::IOException
)

Reads the entire file into a std::string.

Parameters
sthe std::string to read the entire file in
void URI::prefetch ( const std::string &  uri,
const char *const  mode 
)
static

Tries to prefetch a remote URL in background.

If the file could be prefetches successfully, subsequent access to it won't be downloaded again, but the locally downloaded copy is accessed.

Parameters
urithe URI to prefetch
modeopen mode, i.e. "r" or "rb"
void URI::pushSearchPath ( const std::string &  searchPath,
bool  front = false 
)
static

Pushes a path to the directories to prepend if the file is not found.

Note
this works only for relative paths
Parameters
searchPaththe path to push to the serach patch list
frontif true, the path gets prepended as first search element
HGL::Common::URI::throw ( HGL::Exception::IOException  )

Constructor

Parameters
uriURI to open
modeopen mode, i.e. "r" or "rb"