GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
Core.h
Go to the documentation of this file.
1#line 2 "src/Glb/Core.h"
2
3#ifndef __GCW_CORE_H___
4#define __GCW_CORE_H___
5
6#include <string>
7#include <vector>
8
9#include <Wt/Json/Object.h>
10#include <Wt/WTemplate.h>
11
12#include "Numeric.h"
13
14//#define COUT_FLF __FILE__, __LINE__, __FUNCTION__
15//#define COUT_BEG std::cout << __FILE__ << ":" << __LINE__ << "(" << __PRETTY_FUNCTION__ << ") "
16//#define COUT_END std::endl
17//#define COUT_LINE std::cout << __FILE__ << ":" << __LINE__ << "(" << __PRETTY_FUNCTION__ << ")" << COUT_END
18//#define COUT_(x) COUT_BEG << x << COUT_END
19
20
21namespace GCW {
22
23 /*!
24 ** \brief helper functions and features
25 **
26 */
27 namespace Core {
28
29
30std::vector<std::string> split( const std::string & value, char delim );
31
32extern const char* trim_ws;
33std::string & rtrim( std::string & s, const char* t = trim_ws );
34std::string & ltrim( std::string & s, const char* t = trim_ws );
35std::string & trim( std::string & s, const char* t = trim_ws );
36std::string toupper( const std::string & s );
37std::string tolower( const std::string & s );
38
40
41std::string hexDump( const std::string & data, int start = -1, int end = -1 );
42
43/*!
44** \brief Generate new GUID string value
45**
46** This GUID is suitable for use as the primary-guid-key value for the
47** data tables.
48**
49*/
50auto newGuid()-> std::string ;
51
52/*!
53** \brief Current Date/Time
54**
55** This will return the current date/time suitable for back-end storage
56**
57*/
59
60auto dateStorageString( const Wt::WDate * _date )-> std::string ;
61auto dateTimeStorageString( const Wt::WDateTime & _dateTime )-> std::string ;
62auto dateTimeDisplayString( const Wt::WDateTime & _dateTime )-> std::string ;
63auto currentDateTimeStorageString()-> std::string ;
64auto currentDateTimeDisplayString()-> std::string ;
65
66/* * * * * * * * * * * * * * * * * * * * */
67
68std::string makeFileName( const std::string & value );
69
70/*!
71** \brief Check if a File or Folder exists
72**
73**
74*/
75bool fileExists( const std::string & fileName );
76
77/*!
78** \brief Execute a system command
79**
80** This runs a command in the console and returns the result code.
81**
82*/
83int system_command( const std::string & cmd, bool show = false );
84
85/*!
86** \brief File Listing
87**
88** This procedure will scan a folder and return a list of all the files
89** in it.
90*/
91std::vector<std::string> fileList( const std::string & folder );
92
93/*!
94** \brief Find File
95**
96** This scans a directory folder and returns a list containing
97** the full file-name of all the files that matche the value.
98**
99*/
100std::vector<std::string> findFiles( const std::string & folder, const std::string & match );
101
102/*!
103** \brief Convert a String to an Integer
104**
105*/
106int stoi( const std::string & value );
107
108/*!
109** \brief Convert an Integer to a String
110**
111*/
112std::string itos( int value );
113
114/*!
115** \brief Convert a String to Float
116**
117*/
118double stof( const std::string & value );
119
120/*!
121** \brief Convert a Float to String with decimal precision
122**
123*/
124std::string ftos( double value, int decimals = 2 );
125std::string ftos( double value, const std::string & suffix, int decimals = 2 );
126std::string ftos( const std::string & prefix, double value, int decimals = 2 );
127std::string ftom( double value, int decimals = 2 );
128std::string ftom( const std::string & prefix, double value, int decimals = 2 );
129
130/*!
131** \brief Check if a string ends with another string
132**
133*/
134bool ends_with( const std::string & value, const std::string & ending );
135
136/*!
137** \brief Append a string to string
138**
139** This will append a string to another string and place
140** a separator if there is already data in the lead string
141**
142*/
143std::string append( const std::string & s, const std::string & append, const std::string & separator );
144
145/*!
146** \brief Prepend some number of characters in front of another string
147**
148** This procedure is often used to zero-pad a number, such that numbers
149** like 23 and 2005 and 10553 will always appear as 00023 and 02005
150** and 10553 respectively.
151**
152*/
153std::string prepend( const std::string & s, int length = 0, char pad = '0' );
154
155/*!
156** \brief Upper Case a string
157**
158** this procedure converts a string to all upper case
159*/
160std::string ucase( const std::string & value );
161
162/*!
163** \brief Lower Case a string
164**
165** this procedure converts a string to all lower case
166*/
167std::string lcase( const std::string & value );
168
169/*!
170** \brief Round a number up
171**
172** This will round a number up
173**
174*/
175int roundUp( float value );
176
177/*!
178** \brief Round a number down
179**
180** This will round a number down
181**
182*/
183int roundDown( float value );
184
185/*!
186** \brief Round a number for Currency
187**
188** This will round a number up or down depending on the value
189** of the currency. 1.3999999 becomes 1.4
190**
191*/
192float roundCurrency( float value );
193
194/*!
195** \brief Replace a String
196**
197** This will replace all occurrences of a substring within another string with some other string;
198**
199*/
200std::string replace( const std::string & string, const std::string & before, const std::string & after );
201
202std::vector<std::string> readCSVRow( const std::string & row );
203
204/*!
205** This compares two floating point numbers if they are equal
206**
207*/
208bool feq( double a, double b, double epsilon = 0.005f, bool trace = false );
209
210std::string to_string( Wt::WTemplate & templt );
211std::string to_string( Wt::WTemplate * templt );
212
213bool to_htmlfile( Wt::WTemplate & templt, const std::string & folderName, const std::string & fileName );
214bool to_htmlfile( Wt::WTemplate * templt, const std::string & folderName, const std::string & fileName );
215
216typedef struct CharConv
217{
218 const char * symbol;
219 const char * html;
220 const char * utf8;
221 const char * pdf;
222 const char * description;
223
225
226extern const CharConv_t g_iso8859Conv[256];
227
228 } // endnamespace Core
229} // endnamespace GCW
230
231#endif
232
const char * trim_ws
Definition Core.cpp:47
struct GCW::Core::CharConv CharConv_t
int system_command(const std::string &cmd, bool show=false)
Execute a system command.
Definition Core.cpp:413
int roundUp(float value)
Round a number up.
Definition Core.cpp:772
double stof(const std::string &value)
Convert a String to Float.
Definition Core.cpp:601
std::string toupper(const std::string &s)
Definition Core.cpp:77
std::string lcase(const std::string &value)
Lower Case a string.
Definition Core.cpp:761
auto currentDateTime() -> Wt::WDateTime
Current Date/Time.
Definition Core.cpp:270
std::string ucase(const std::string &value)
Upper Case a string.
Definition Core.cpp:750
std::string tolower(const std::string &s)
Definition Core.cpp:88
bool ends_with(const std::string &value, const std::string &ending)
Check if a string ends with another string.
Definition Core.cpp:694
int roundDown(float value)
Round a number down.
Definition Core.cpp:785
std::string ftom(double value, int decimals=2)
Definition Core.cpp:667
auto dateTimeDisplayString(const Wt::WDateTime &_dateTime) -> std::string
Definition Core.cpp:309
bool fileExists(const std::string &fileName)
Check if a File or Folder exists.
Definition Core.cpp:559
std::string append(const std::string &s, const std::string &append, const std::string &separator)
Append a string to string.
Definition Core.cpp:706
std::string ftos(double value, int decimals=2)
Convert a Float to String with decimal precision.
Definition Core.cpp:628
std::vector< std::string > split(const std::string &value, char delim)
Definition Core.cpp:40
bool feq(double a, double b, double epsilon=0.005f, bool trace=false)
Definition Core.cpp:937
float roundCurrency(float value)
Round a number for Currency.
Definition Core.cpp:794
std::string itos(int value)
Convert an Integer to a String.
Definition Core.cpp:588
auto dateStorageString(const Wt::WDate *_date) -> std::string
std::string & trim(std::string &s, const char *t=trim_ws)
Definition Core.cpp:70
std::string & ltrim(std::string &s, const char *t=trim_ws)
Definition Core.cpp:61
std::string replace(const std::string &string, const std::string &before, const std::string &after)
Replace a String.
Definition Core.cpp:809
std::string makeFileName(const std::string &value)
Make File Name.
Definition Core.cpp:343
std::vector< std::string > findFiles(const std::string &folder, const std::string &match)
Find File.
Definition Core.cpp:544
int stoi(const std::string &value)
Convert a String to an Integer.
Definition Core.cpp:569
auto currentDateTimeDisplayString() -> std::string
Definition Core.cpp:321
std::string prepend(const std::string &s, int length=0, char pad='0')
Prepend some number of characters in front of another string.
Definition Core.cpp:736
const CharConv_t g_iso8859Conv[256]
Definition Core.cpp:1015
std::string hexDump(const std::string &data, int start=-1, int end=-1)
Definition Core.cpp:180
std::string to_string(Wt::WTemplate &templt)
Definition Core.cpp:961
std::string & rtrim(std::string &s, const char *t=trim_ws)
Definition Core.cpp:52
bool to_htmlfile(Wt::WTemplate &templt, const std::string &folderName, const std::string &fileName)
Definition Core.cpp:996
Wt::Json::Object toJson(Wt::WTreeView *_view)
Definition Core.cpp:158
std::vector< std::string > readCSVRow(const std::string &row)
Definition Core.cpp:835
auto dateTimeStorageString(const Wt::WDateTime &_dateTime) -> std::string
Definition Core.cpp:288
auto newGuid() -> std::string
Generate new GUID string value.
Definition Core.cpp:245
auto currentDateTimeStorageString() -> std::string
Definition Core.cpp:300
std::vector< std::string > fileList(const std::string &folder)
File Listing.
Definition Core.cpp:464
Definition App.h:18
const char * pdf
Definition Core.h:221
const char * description
Definition Core.h:222
const char * utf8
Definition Core.h:220
const char * symbol
Definition Core.h:218
const char * html
Definition Core.h:219