ifw-core  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Enumerations | Functions | Variables
ctd::file Namespace Reference

Classes

class  ParameterFile
 Class to handle a set of parameters. More...
 
class  Yaml
 Class implementing the handling of Yaml files in the ICS environment. More...
 

Enumerations

enum  RootType {
  SYSROOT = 1, INTROOT = 2, DATAROOT = 4, CFGPATH = 8,
  ROOTS_ALL = (SYSROOT | INTROOT | DATAROOT | CFGPATH), CFG_INT_ROOT = (CFGPATH | INTROOT)
}
 Types of ELT deployment environment roots. More...
 
enum  ResourceType {
  RES_CONFIG = 1, RES_AUDIO = 2, RES_IMAGE = 4, RES_MODEL = 8,
  RES_DICTIONARY = 16, RES_DATA = 32, RES_ALL
}
 

Functions

std::string RootVarTypeNbToString (const RootType type)
 Convert root type from number to string representation. More...
 
RootType RootVarTypeStringToNb (const std::string &type)
 Convert root type from string to number representation. More...
 
std::string ResDirNbToString (const ResourceType type)
 Convert resource type from number to string representation. More...
 
ResourceType ResDirStringToNb (const std::string &type)
 Convert resource type from string to number representation. More...
 
std::string CheckAddExtension (const std::string &filename, const std::string &extension)
 Check if filename has the specified extension (no initiating dot). If not, add it. More...
 
void RemoveFile (const std::string &filename)
 Remove the referenced file, if it exists. More...
 
std::string CreateIfwFilename (const std::string &filename, const RootType root, const ResourceType resource, const std::string &extension="")
 Create a resource path in the IFW deployment environment. More...
 
std::string ResolvePath (const std::string &filename)
 Resolve the filename if it contains env. variables, "~" and relative paths. More...
 
std::string FindFile (const std::string &filename, RootType roots=RootType::ROOTS_ALL, int32_t resources=RES_ALL, const bool exception=true)
 Locate file in the locations defined by the ELT ICS deployment environment. More...
 
std::string LoadFile (const std::string &filename, std::string *complete_filename=nullptr, RootType roots=RootType::ROOTS_ALL, ResourceType resources=RES_ALL)
 Load a file and return the content. More...
 
void SaveFile (const std::string &filename, const std::string &buffer, const bool overwrite=true)
 Save the contents inthe buffer into the given filename. More...
 

Variables

const std::string SYSROOT_STR = "SYSROOT"
 
const std::string INTROOT_STR = "INTROOT"
 
const std::string DATAROOT_STR = "DATAROOT"
 
const std::string CFGPATH_STR = "CFGPATH"
 
const std::string RES_DIR = "resource"
 
const std::string RES_CONFIG_STR = "config"
 
const std::string RES_AUDIO_STR = "audio"
 
const std::string RES_IMAGE_STR = "image"
 
const std::string RES_MODEL_STR = "model"
 
const std::string RES_DICTIONARY_STR = "dictionary"
 
const std::string RES_DATA_STR = "data"
 

Enumeration Type Documentation

Types of resources found in the ELT deployment roots. // TODO: Change to "enum class ResourceType {".

Enumerator
RES_CONFIG 
RES_AUDIO 
RES_IMAGE 
RES_MODEL 
RES_DICTIONARY 
RES_DATA 
RES_ALL 

Types of ELT deployment environment roots.

Enumerator
SYSROOT 
INTROOT 
DATAROOT 
CFGPATH 
ROOTS_ALL 
CFG_INT_ROOT 

Function Documentation

std::string ctd::file::CheckAddExtension ( const std::string &  filename,
const std::string &  extension 
)

Check if filename has the specified extension (no initiating dot). If not, add it.

std::string ctd::file::CreateIfwFilename ( const std::string &  filename,
const RootType  root,
const ResourceType  resource,
const std::string &  extension 
)

Create a resource path in the IFW deployment environment.

Todo:
: Implement a more generic solution for handling absolute or relative paths.
std::string ctd::file::FindFile ( const std::string &  filename,
RootType  roots = RootType::ROOTS_ALL,
int32_t  resources = RES_ALL,
const bool  exception = true 
)

Locate file in the locations defined by the ELT ICS deployment environment.

Parameters
[in]filenameFilename to find.
[out]completeFilenameComplete name of file located.
[in]rootsSpecifies in which root or roots to look.
[in]resourcesSpecify the type of resource or resources.
[in]exceptionIf true, throw exception if no matching file found.
Returns
Complete path of file found or "" if no file was found.

Deprecated: Use rad::FindFile() instead.

The function is used to resolve the input filename and to check the location.

Typically it is known which type of resource file is concerned, so that only one type is given.

If several roots are specified, the order in which files are checked for are:

  • DATAROOT
  • CFGPATH
  • INTROOT
  • SYSROOT

If a configuration resource file type is in question, the function should be called like e.g.:

std::string completeName; ctd::file::File::FindFile("myProj/myPkg/myMod/myConfiguration.cfg", completeName, (CFGROOT & INTROOT), RES_CONFIG);

The input filename name shall be given with the namespace of the context, i.e., the module in which it lives and under which directory it will be installed in the appropriate root.

The function does not attempt to add an extension to the input name, which consequently must be given.

See Also
ctd::file::File::RootTypes
ctd::file::File::ResourceTypes
std::string ctd::file::LoadFile ( const std::string &  filename,
std::string *  complete_filename = nullptr,
RootType  roots = RootType::ROOTS_ALL,
ResourceType  resources = RES_ALL 
)

Load a file and return the content.

Parameters
filenameName of the file. The file may be searched for in the ICS file locations.
rootsThe ICS deployment root directories to check for the file (if applicable).
resourcesType of resource locations to check for the file (if applicable).
Returns
Content of file, if found.

If the complete path of the file is given, the parameters "RootTypes" and "ResourceTypes" have no effect.

void ctd::file::RemoveFile ( const std::string &  filename)

Remove the referenced file, if it exists.

std::string ctd::file::ResDirNbToString ( ResourceType  type)

Convert resource type from number to string representation.

ResourceType ctd::file::ResDirStringToNb ( const std::string &  type)

Convert resource type from string to number representation.

std::string ctd::file::ResolvePath ( const std::string &  filename)

Resolve the filename if it contains env. variables, "~" and relative paths.

std::string ctd::file::RootVarTypeNbToString ( RootType  type)

Convert root type from number to string representation.

RootType ctd::file::RootVarTypeStringToNb ( const std::string &  type)

Convert root type from string to number representation.

void ctd::file::SaveFile ( const std::string &  filename,
const std::string &  buffer,
const bool  overwrite = true 
)

Save the contents inthe buffer into the given filename.

Parameters
filenameName of file. Will be resolve, if necessary.
bufferBuffer to write into the file.
overwriteOverwrite (replace) file if already existing.

Variable Documentation

const std::string ctd::file::CFGPATH_STR = "CFGPATH"
const std::string ctd::file::DATAROOT_STR = "DATAROOT"
const std::string ctd::file::INTROOT_STR = "INTROOT"
const std::string ctd::file::RES_AUDIO_STR = "audio"
const std::string ctd::file::RES_CONFIG_STR = "config"
const std::string ctd::file::RES_DATA_STR = "data"
const std::string ctd::file::RES_DICTIONARY_STR = "dictionary"
const std::string ctd::file::RES_DIR = "resource"
const std::string ctd::file::RES_IMAGE_STR = "image"
const std::string ctd::file::RES_MODEL_STR = "model"
const std::string ctd::file::SYSROOT_STR = "SYSROOT"