10#ifndef LUPI_hpp_included
11#define LUPI_hpp_included 1
28#define LUPI_XML_verionEncoding "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
31#define LUPI_PATH_MAX ( 4 * 4096 )
34#if defined (GIDIP_HAVE_COMPILER_FLOATING_POINT_EXCEPTIONS)
35void LUPI_FPE_enable(
char const *a_file,
int a_line );
36void LUPI_FPE_disable_and_clear(
char const *a_file,
int a_line );
37void LUPI_FPE_test(
char const *a_file,
int a_line );
43#define LUPI_FILE_SEPARATOR "\\"
45#define LUPI_FILE_SEPARATOR "/"
48#define GNDS_formatVersion_1_10Chars "1.10"
49#define GNDS_formatVersion_2_0Chars "2.0"
50#define GNDS_formatVersion_2_0_LLNL_4Chars "2.0.LLNL_4"
51#define GNDS_formatVersion_2_1Chars "2.1"
53void deprecatedFunction( std::string
const &a_functionName, std::string
const &a_replacementName, std::string
const &a_asOf );
74 std::string
const &
format( )
const {
return( m_format ); }
75 int major( )
const {
return( m_major ); }
76 int minor( )
const {
return( m_minor ); }
77 std::string
const &
patch( )
const {
return( m_patch ); }
79 bool setFormat( std::string
const &a_formatVersion );
91 explicit Exception( std::string
const &a_message );
118 std::string
constructMessage( std::string a_prefix,
int a_reports = 1,
bool a_clear =
false );
119 std::string
constructFullMessage( std::string
const &a_prefix,
int a_reports = 1,
bool a_clear =
false );
135 std::string m_codeName;
136 std::string m_descriptor;
137 std::vector<ArgumentBase *> m_arguments;
142 ArgumentParser( std::string
const &a_codeName, std::string
const &a_descriptor =
"" );
145 std::string
const &
codeName( )
const {
return( m_codeName ); }
146 std::string
const &
descriptor( )
const {
return( m_descriptor ); }
147 template<
typename T> T *
add( std::string
const &a_name, std::string
const &a_descriptor,
int a_minimumNeeded = 1,
int a_maximumNeeded = 1 );
149 int a_minimumNeeded = -2,
int a_maximumNeeded = -2 );
150 void addAlias( std::string
const &a_name, std::string
const &a_alias );
152 bool hasName( std::string
const &a_name )
const ;
154 void parse(
int a_argc,
char **a_argv,
bool a_printArguments =
true );
155 template<
typename T> T *
get( std::size_t a_name );
157 void usage( )
const ;
158 virtual void printStatus( std::string a_indent )
const ;
172template<
typename T> T *
ArgumentParser::add( std::string
const &a_name, std::string
const &a_descriptor,
int a_minimumNeeded,
int a_maximumNeeded ) {
174 T *argument =
new T( a_name, a_descriptor, a_minimumNeeded, a_maximumNeeded );
190 std::vector<std::string> m_names;
191 std::string m_descriptor;
194 std::size_t m_counts;
195 std::vector<std::string> m_values;
197 void addAlias( std::string
const &a_name );
198 virtual std::string printStatus2( )
const ;
199 virtual void printStatus3( std::string
const &a_indent )
const ;
204 ArgumentBase(
ArgumentType a_argumentType, std::string
const &a_name, std::string
const &a_descriptor,
int a_minimumNeeded,
int a_maximumNeeded );
208 std::string
const &
name( )
const {
return( m_names[0] ); }
209 std::vector<std::string>
const &
names( ) {
return( m_names ); }
210 bool hasName( std::string
const &a_name )
const ;
211 std::string
const &
descriptor( )
const {
return( m_descriptor ); }
214 std::size_t
counts( )
const {
return( m_counts ); }
216 virtual std::string
const &
value( std::size_t a_index = 0 )
const ;
217 std::vector<std::string>
const &
values( )
const {
return( m_values ); }
220 virtual int parse(
ArgumentParser const &a_argumentParser,
int a_index,
int a_argc,
char **a_argv );
221 std::string
usage(
bool a_requiredOption )
const ;
237 OptionBoolean(
ArgumentType a_argumentType, std::string
const &a_name, std::string
const &a_descriptor,
bool a_default );
253 OptionTrue( std::string
const &a_name, std::string
const &a_descriptor =
"",
int a_minimumNeeded = 0,
int a_maximumNeeded = -1 );
266 OptionFalse( std::string
const &a_name, std::string
const &a_descriptor =
"",
int a_minimumNeeded = 0,
int a_maximumNeeded = -1 );
279 OptionCounter( std::string
const &a_name, std::string
const &a_descriptor =
"",
int a_minimumNeeded = 0,
int a_maximumNeeded = -1 );
294 OptionStore( std::string
const &a_name, std::string
const &a_descriptor =
"",
int a_minimumNeeded = 0,
int a_maximumNeeded = -1 );
297 std::string
const &
value( std::size_t a_index = 0 )
const ;
299 void printStatus3( std::string
const &a_indent )
const ;
311 OptionAppend( std::string
const &a_name, std::string
const &a_descriptor =
"",
int a_minimumNeeded = 0,
int a_maximumNeeded = -1 );
315 void printStatus3( std::string
const &a_indent )
const ;
327 Positional( std::string
const &a_name, std::string
const &a_descriptor =
"",
int a_minimumNeeded = 1,
int a_maximumNeeded = 1 );
332 void printStatus3( std::string
const &a_indent )
const ;
343#define LUPI_DeltaTime_toStringFormatIncremental "incremental: CPU %8.3fs, wall %8.3fs"
344#define LUPI_DeltaTime_toStringFormatTotal "total: CPU %8.3fs, wall %8.3fs"
351 double m_CPU_timeIncremental;
352 double m_wallTimeIncremental;
356 DeltaTime(
double a_CPU_time,
double a_wallTime,
double a_CPU_timeIncremental,
double a_wallTimeIncremental );
378 struct timeval m_wallTime;
379 clock_t m_CPU_timeIncremental;
380 struct timeval m_wallTimeIncremental;
395std::string
realPath( std::string
const &a_path );
396std::string
_basename( std::string
const &a_path );
398std::string
_dirname( std::string
const &a_path );
399bool exists( std::string
const &a_path );
415 FileStat( std::string
const &a_path );
417 std::string
const &
path( )
const {
return( m_path ); }
418 struct stat const &
statRef( )
const {
return( m_stat ); }
421 bool isDirectory( )
const {
return( ( m_stat.st_mode & S_IFMT ) == S_IFDIR ); }
422 bool isRegularFile( )
const {
return( ( m_stat.st_mode & S_IFMT ) == S_IFREG ); }
431std::string
stripString( std::string
const &a_string,
bool a_left =
true,
bool a_right =
true );
432std::vector<std::string>
splitString( std::string
const &a_string,
char a_delimiter,
bool a_strip =
false );
433std::vector<std::string>
splitString( std::string
const &a_string, std::string
const &a_delimiter,
bool a_strip =
false );
434std::string
joinStrings( std::string
const &a_sep, std::vector<std::string> a_strings );
435std::string
replaceString( std::string
const &a_string, std::string
const &a_old, std::string
const &a_new,
bool a_all );
437bool stringToInt( std::string
const &a_string,
int &a_value );
438bool stringToSize_t( std::string
const &a_string, std::size_t &a_value );
441std::string
doubleToString3(
char const *a_format,
double a_value,
bool a_reduceBits =
false );
442std::string
doubleToShortestString(
double a_value,
int a_significantDigits = 15,
int a_favorEFormBy = 0 );
444void printCommand( std::string
const &a_indent,
int a_argc,
char **a_argv );
#define LUPI_DeltaTime_toStringFormatTotal
#define LUPI_DeltaTime_toStringFormatIncremental
virtual bool requiresAValue() const
ArgumentType argumentType() const
std::vector< std::string > const & names()
std::vector< std::string > const & values() const
virtual bool isOptionalArgument() const
bool hasName(std::string const &a_name) const
std::string const & descriptor() const
virtual std::string const & value(std::size_t a_index=0) const
std::size_t counts() const
ArgumentBase(ArgumentType a_argumentType, std::string const &a_name, std::string const &a_descriptor, int a_minimumNeeded, int a_maximumNeeded)
virtual int parse(ArgumentParser const &a_argumentParser, int a_index, int a_argc, char **a_argv)
std::string const & name() const
void printStatus(std::string a_indent) const
int maximumNeeded() const
std::string usage(bool a_requiredOption) const
int minimumNeeded() const
virtual ~ArgumentBase()=0
virtual void printStatus(std::string a_indent) const
std::string const & codeName() const
T * add(std::string const &a_name, std::string const &a_descriptor, int a_minimumNeeded=1, int a_maximumNeeded=1)
T * get(std::size_t a_name)
ArgumentParser(std::string const &a_codeName, std::string const &a_descriptor="")
bool hasName(std::string const &a_name) const
void parse(int a_argc, char **a_argv, bool a_printArguments=true)
bool isOptionalArgument(std::string const &a_name) const
void addAlias(std::string const &a_name, std::string const &a_alias)
std::string const & descriptor() const
double CPU_timeIncremental() const
std::string toString(std::string a_formatIncremental=LUPI_DeltaTime_toStringFormatIncremental, std::string a_format=LUPI_DeltaTime_toStringFormatTotal, std::string a_sep="; ")
double wallTimeIncremental() const
Exception(std::string const &a_message)
FileStat(std::string const &a_path)
struct stat const & statRef() const
bool isRegularFile() const
std::string const & path() const
void printStatus3(std::string const &a_indent) const
OptionAppend(std::string const &a_name, std::string const &a_descriptor="", int a_minimumNeeded=0, int a_maximumNeeded=-1)
bool requiresAValue() const
std::string printStatus2() const
virtual ~OptionBoolean()=0
OptionBoolean(ArgumentType a_argumentType, std::string const &a_name, std::string const &a_descriptor, bool a_default)
OptionCounter(std::string const &a_name, std::string const &a_descriptor="", int a_minimumNeeded=0, int a_maximumNeeded=-1)
std::string printStatus2() const
OptionFalse(std::string const &a_name, std::string const &a_descriptor="", int a_minimumNeeded=0, int a_maximumNeeded=-1)
std::string const & value(std::size_t a_index=0) const
OptionStore(std::string const &a_name, std::string const &a_descriptor="", int a_minimumNeeded=0, int a_maximumNeeded=-1)
void printStatus3(std::string const &a_indent) const
bool requiresAValue() const
OptionTrue(std::string const &a_name, std::string const &a_descriptor="", int a_minimumNeeded=0, int a_maximumNeeded=-1)
void printStatus3(std::string const &a_indent) const
Positional(std::string const &a_name, std::string const &a_descriptor="", int a_minimumNeeded=1, int a_maximumNeeded=1)
bool requiresAValue() const
bool isOptionalArgument() const
statusMessageReporting * smr()
~StatusMessageReporting()
std::string constructFullMessage(std::string const &a_prefix, int a_reports=1, bool a_clear=false)
std::string constructMessage(std::string a_prefix, int a_reports=1, bool a_clear=false)
DeltaTime deltaTimeAndReset()
std::string basenameWithoutExtension(std::string const &a_path)
std::string _basename(std::string const &a_path)
bool exists(std::string const &a_path)
std::string realPath(std::string const &a_path)
bool createDirectories(std::string const &a_path)
std::string _dirname(std::string const &a_path)
bool isDirectory(std::string const &a_path)
std::string doubleToShortestString(double a_value, int a_significantDigits=15, int a_favorEFormBy=0)
std::vector< std::string > splitXLinkString(std::string const &a_string)
std::string replaceString(std::string const &a_string, std::string const &a_old, std::string const &a_new, bool a_all)
std::string joinStrings(std::string const &a_sep, std::vector< std::string > a_strings)
void printCommand(std::string const &a_indent, int a_argc, char **a_argv)
std::vector< std::string > splitString(std::string const &a_string, char a_delimiter, bool a_strip=false)
std::string argumentsToString(char const *a_format,...)
bool stringToSize_t(std::string const &a_string, std::size_t &a_value)
std::string stripString(std::string const &a_string, bool a_left=true, bool a_right=true)
std::string doubleToString3(char const *a_format, double a_value, bool a_reduceBits=false)
bool stringToInt(std::string const &a_string, int &a_value)
void deprecatedFunction(std::string const &a_functionName, std::string const &a_replacementName, std::string const &a_asOf)
int smr_isInfo(statusMessageReporting const *smr)
void smr_release(statusMessageReporting *smr)
int smr_isOk(statusMessageReporting const *smr)
int smr_isWarning(statusMessageReporting const *smr)
int smr_isError(statusMessageReporting const *smr)