HIPO  4.3.0
High Performance Output data format for experimental physics
hipo::utils Class Reference

Utility functions for string manipulation, serialization, and HIPO file generation. More...

#include <utils.h>

Public Member Functions

 utils ()
 Default constructor. More...
 
 ~utils ()
 Destructor. More...
 

Static Public Member Functions

static void tokenize (const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
 Splits a string into tokens using the given delimiters. More...
 
static std::string substring (const std::string &str, const char *start_delim, const char *end_delim, int order)
 Extracts a substring between two delimiters. More...
 
static int findposition (const std::string &str, const char *delim, int order)
 Finds the position of the nth occurrence of a delimiter. More...
 
static std::string & ltrim (std::string &str, const std::string &chars="\t\n\v\f\r ")
 Trims leading whitespace characters from a string. More...
 
static std::string & rtrim (std::string &str, const std::string &chars="\t\n\v\f\r ")
 Trims trailing whitespace characters from a string. More...
 
static std::string & trim (std::string &str, const std::string &chars="\t\n\v\f\r ")
 Trims both leading and trailing whitespace from a string. More...
 
static void printLogo ()
 Prints the HIPO library logo to standard output. More...
 
static std::string getHeader ()
 Returns the HIPO header string for code generation. More...
 
static std::string getFileHeader ()
 Returns the file header template string. More...
 
static std::string getFileTrailer (const char *code)
 Returns the file trailer template string. More...
 
static std::string getSConstruct ()
 Returns the SCons build configuration string. More...
 
static void writeInt (char *buffer, int position, int value)
 Writes a 32-bit integer into a byte buffer at the given position. More...
 
static void writeLong (char *buffer, int position, long value)
 Writes a 64-bit long into a byte buffer at the given position. More...
 
static void writeByte (char *buffer, int position, uint8_t value)
 Writes a single byte into a byte buffer at the given position. More...
 

Detailed Description

Utility functions for string manipulation, serialization, and HIPO file generation.

Definition at line 36 of file utils.h.

Constructor & Destructor Documentation

◆ utils()

hipo::utils::utils ( )

Default constructor.

Definition at line 16 of file utils.cpp.

◆ ~utils()

hipo::utils::~utils ( )

Destructor.

Definition at line 17 of file utils.cpp.

Member Function Documentation

◆ findposition()

int hipo::utils::findposition ( const std::string &  str,
const char *  delim,
int  order 
)
static

Finds the position of the nth occurrence of a delimiter.

Parameters
strThe input string.
delimThe delimiter to search for.
orderThe occurrence index.
Returns
Position of the delimiter, or -1 if not found.

finds postion of the dalim in the string, while skipping "order" times.

Definition at line 41 of file utils.cpp.

◆ getFileHeader()

std::string hipo::utils::getFileHeader ( )
static

Returns the file header template string.

Definition at line 114 of file utils.cpp.

◆ getFileTrailer()

std::string hipo::utils::getFileTrailer ( const char *  code)
static

Returns the file trailer template string.

Parameters
codeThe code identifier to embed in the trailer.
Returns
The file trailer string.

Definition at line 130 of file utils.cpp.

◆ getHeader()

std::string hipo::utils::getHeader ( )
static

Returns the HIPO header string for code generation.

Definition at line 95 of file utils.cpp.

◆ getSConstruct()

std::string hipo::utils::getSConstruct ( )
static

Returns the SCons build configuration string.

Definition at line 148 of file utils.cpp.

◆ ltrim()

static std::string& hipo::utils::ltrim ( std::string &  str,
const std::string &  chars = "\t\n\v\f\r " 
)
inlinestatic

Trims leading whitespace characters from a string.

Parameters
strThe string to trim (modified in place).
charsCharacters to remove (default: whitespace).
Returns
Reference to the trimmed string.

Definition at line 83 of file utils.h.

◆ printLogo()

void hipo::utils::printLogo ( )
static

Prints the HIPO library logo to standard output.

Definition at line 85 of file utils.cpp.

◆ rtrim()

static std::string& hipo::utils::rtrim ( std::string &  str,
const std::string &  chars = "\t\n\v\f\r " 
)
inlinestatic

Trims trailing whitespace characters from a string.

Parameters
strThe string to trim (modified in place).
charsCharacters to remove (default: whitespace).
Returns
Reference to the trimmed string.

Definition at line 93 of file utils.h.

◆ substring()

std::string hipo::utils::substring ( const std::string &  str,
const char *  start_delim,
const char *  end_delim,
int  order 
)
static

Extracts a substring between two delimiters.

Parameters
strThe input string.
start_delimStarting delimiter.
end_delimEnding delimiter.
orderOccurrence index of the delimiter pair.
Returns
The extracted substring.

returns a substring from a string that is enclosed between start_delim and end_delim. order variable decides which enclosed string to return as and order of occurance. 0 - first one. 1 - second one.

Definition at line 60 of file utils.cpp.

◆ tokenize()

void hipo::utils::tokenize ( const std::string &  str,
std::vector< std::string > &  tokens,
const std::string &  delimiters = " " 
)
static

Splits a string into tokens using the given delimiters.

Parameters
strThe input string to tokenize.
tokensOutput vector of token strings.
delimitersCharacters used as delimiters (default: space).

Definition at line 19 of file utils.cpp.

◆ trim()

static std::string& hipo::utils::trim ( std::string &  str,
const std::string &  chars = "\t\n\v\f\r " 
)
inlinestatic

Trims both leading and trailing whitespace from a string.

Parameters
strThe string to trim (modified in place).
charsCharacters to remove (default: whitespace).
Returns
Reference to the trimmed string.

Definition at line 103 of file utils.h.

◆ writeByte()

void hipo::utils::writeByte ( char *  buffer,
int  position,
uint8_t  value 
)
static

Writes a single byte into a byte buffer at the given position.

Parameters
bufferTarget byte buffer.
positionByte offset to write at.
valueThe byte value to write.

Definition at line 80 of file utils.cpp.

◆ writeInt()

void hipo::utils::writeInt ( char *  buffer,
int  position,
int  value 
)
static

Writes a 32-bit integer into a byte buffer at the given position.

Parameters
bufferTarget byte buffer.
positionByte offset to write at.
valueThe integer value to write.

Definition at line 70 of file utils.cpp.

◆ writeLong()

void hipo::utils::writeLong ( char *  buffer,
int  position,
long  value 
)
static

Writes a 64-bit long into a byte buffer at the given position.

Parameters
bufferTarget byte buffer.
positionByte offset to write at.
valueThe long value to write.

Definition at line 75 of file utils.cpp.


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