Codemesh Runtime v3 C++ API Reference  3.9.205
Public Member Functions | Static Public Attributes | List of all members
xmog::util::file Class Reference

Utility wrapper for file objects. More...

#include <xmog_util_file.h>

Public Member Functions

 file (const char *name_)
 
 file (const std::string &name_)
 
 file (const file &parent_, const char *const name_)
 
 operator const std::string & () const
 Convert the file instance to a string representing its file name.
 
bool operator== (const std::string &name) const
 
const char * name () const
 Return the file's name.
 
const char * key_name () const
 Return the file's name.
 
file nested (const char *sub) const
 Return the file object representing a nested file, relative to this file.
 
bool exists () const
 Return true if this instance represents an existing file.
 
off_t size () const
 Return the number of bytes in the file.
 
bool is_dir () const
 Return true if this instance represents a directory.
 
bool is_file () const
 Return true if this instance represents a regular file.
 
size_t list (::std::vector< file > &container, const char *filter=NULL, file_spec fs=fileAndDir, bool bRecurse=false, const char *terms[]=noTerminators) const
 Accumulate a list of nested files in accordance with the specified criteria. More...
 
std::string path (const char *filter, file_spec fs=onlyFile) const
 Accumulate a path of nested files in accordance with the specified criteria. More...
 
int read (char **pdata, jint *length)
 Reads the specified file and returns the contents and length in the variables provided. More...
 
int write (const char *text)
 Writes the specified text to the file. More...
 
int mkdir (int mode=0777)
 Creates a directory for the given name. More...
 
void del ()
 Deletes the file.
 

Static Public Attributes

static const char * noTerminators []
 

Detailed Description

Utility wrapper for file objects.

Constructor & Destructor Documentation

◆ file() [1/3]

xmog::util::file::file ( const char *  name_)

Create a new file instance representing a file of the given name. The physical file does not need to exist and will not be created by this call.

Parameters
name_the name of the file.

◆ file() [2/3]

xmog::util::file::file ( const std::string &  name_)

Create a new file instance representing a file of the given name. The physical file does not need to exist and will not be created by this call.

Parameters
name_the name of the file.

◆ file() [3/3]

xmog::util::file::file ( const file parent_,
const char *const  name_ 
)

Create a new file instance based on a file and a name. The physical file does not need to exist and will not be created by this call.

Parameters
parent_the file's parent directory.
name_the name of the file in the parent directory.

Member Function Documentation

◆ list()

size_t xmog::util::file::list ( ::std::vector< file > &  container,
const char *  filter = NULL,
file_spec  fs = fileAndDir,
bool  bRecurse = false,
const char *  terms[] = noTerminators 
) const

Accumulate a list of nested files in accordance with the specified criteria.

Parameters
containerthe container into which the nested files are accumulated.
filtera simple filename filter that may include one asterisk and multiple questionmarks. An asterisk matches one or more characters, a questionmark matches one character.
fsfile type filter. By default, we accumulate both files and directories.
bRecursetrue if we go deep into nested directories.

◆ mkdir()

int xmog::util::file::mkdir ( int  mode = 0777)

Creates a directory for the given name.

Returns
0 on success.

◆ operator==()

bool xmog::util::file::operator== ( const std::string &  name) const
inline

Return true if the file names match. The comparison is case sensitive even on case-insensitive platforms.

◆ path()

std::string xmog::util::file::path ( const char *  filter,
file_spec  fs = onlyFile 
) const

Accumulate a path of nested files in accordance with the specified criteria.

Parameters
filtera simple filename filter that may include one asterisk and multiple questionmarks. An asterisk matches one or more characters, a questionmark matches one character.
fsfile type filter. By default, we accumulate only files.

◆ read()

int xmog::util::file::read ( char **  pdata,
jint *  length 
)

Reads the specified file and returns the contents and length in the variables provided.

Parameters
pdatapointer to variable that will hold read file data on successful return.
lengthpointer to variable that will hold number of read characters on successful return.
Returns
0 on success.

◆ write()

int xmog::util::file::write ( const char *  text)

Writes the specified text to the file.

Parameters
textthe text to write.
Returns
0 on success.

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

Copyright (c) 1999-2020 by Codemesh, Inc., ALL RIGHTS RESERVED.