Granada  1.54.0
Structured layer on top of C++ REST SDK for building server applications in C++. Granada implements sessions, server side plug-in framework, C++ OAuth 2.0 server, data storage access, server script running, server browsing.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Classes | Functions
granada::util::file Namespace Reference

Classes

class  PropertyFile
 

Functions

static const std::string GetExtension (const std::string &filename)
 
static std::string ContentAsString (const std::string &file_path)
 
static web::json::value ContentAsJSON (const std::string &file_path)
 
static const std::string Replace (const std::string &file_path, const std::deque< std::pair< std::string, std::string >> &values, const std::string &open, const std::string &close)
 
static const std::string Replace (const std::string &file_path, const std::unordered_map< std::string, std::string > &values, const std::string &open, const std::string &close)
 
static const std::string Replace (const std::string &file_path, const std::deque< std::pair< std::string, std::string >> &values)
 
static const std::string Replace (const std::string &file_path, const std::unordered_map< std::string, std::string > &values)
 

Detailed Description

Collection of functions and classes related to file information or manipulation.

Function Documentation

static web::json::value granada::util::file::ContentAsJSON ( const std::string &  file_path)
inlinestatic

Returns the content of the file with given path in form of JSON value.

Parameters
file_pathPath of the file.
Returns
Content of the file (JSON object or JSON array).
static std::string granada::util::file::ContentAsString ( const std::string &  file_path)
inlinestatic

Returns the content of the file with given path in form of string.

Parameters
file_pathPath of the file.
Returns
Content of the file (string).
static const std::string granada::util::file::GetExtension ( const std::string &  filename)
static

Return the extension of a file based on the given filename or path.

Parameters
filenameFile name or path from which to extract the extension.
Returns
Extension of the file.
static const std::string granada::util::file::Replace ( const std::string &  file_path,
const std::deque< std::pair< std::string, std::string >> &  values,
const std::string &  open,
const std::string &  close 
)
static

Replace a deque of key tags in a file by a value. Example: file: hello {{username}} !!! {{date}} Replace map: username => "John Doe" date => "Tuesday, May 17, 2016" Open: {{ , Close: }} Result: hello John Doe !!! Tuesday, May 17, 2016

Parameters
file_pathPath of the file containing the tags to replace.
valuesDeque with the key-values pairs containing the values to replace in the file.
openBefore tag mark.
closeAfter tag mark.
Returns
Content of the file with values replaced.
static const std::string granada::util::file::Replace ( const std::string &  file_path,
const std::unordered_map< std::string, std::string > &  values,
const std::string &  open,
const std::string &  close 
)
static

Replace a map of key tags in a file by a value. Example: file: hello {{username}} !!! {{date}} Replace map: username => "John Doe" date => "Tuesday, May 17, 2016" Open: {{ , Close: }} Result: hello John Doe !!! Tuesday, May 17, 2016

Parameters
file_pathPath of the file containing the tags to replace.
valuesMap with the key-values pairs containing the values to replace in the file.
openBefore tag mark.
closeAfter tag mark.
Returns
Content of the file with values replaced.
static const std::string granada::util::file::Replace ( const std::string &  file_path,
const std::deque< std::pair< std::string, std::string >> &  values 
)
inlinestatic

Same as Replace: Replace a deque of key tags in a file by a value but use default before and after tag marks: "{{" and "}}".

Parameters
file_pathPath of the file containing the tags to replace.
valuesDeque with the key-values pairs containing the values to replace in the file.
Returns
Content of the file with values replaced.
static const std::string granada::util::file::Replace ( const std::string &  file_path,
const std::unordered_map< std::string, std::string > &  values 
)
inlinestatic

Same as Replace: Replace a map of key tags in a file by a value but use default before and after tag marks: "{{" and "}}".

Parameters
file_pathPath of the file containing the tags to replace.
valuesMap with the key-values pairs containing the values to replace in the file.
Returns
Content of the file with values replaced.