Sweet cpp header that help in daily life
extremely small unit testing framework
UNITTEST(InformativTestName) {
// your test here
}
int main() {
if(!Unit::runTests()) {
std::cerr<<"Some errors occoured"<<std::endl;
}
return 0;
}
variadic template printf string formatting
easy to use logger
void someRandomFunction() {
LOG();
LOG("Hello");
LOG("Hello %s", "World");
}
We have unittest maybe some Design by Contract might also.
struct SomeStupidClass {
int a = 0;
int b = 9;
INVARIANT_BEGIN
Inv(RN(0,a,32));
Inv(RN(0,b,10));
INVARIANT_END
inline void changeMethod() {
Invariant(); // This makes the Invariant tested at the beginning and
//the end
a = 33; // this contradicts the invariant
}
};
short testFunc(int a, double d, int* ip) {
Rqr(RN(0,a,10), NaN(d), RN(0.0,d,1.0), NN(ip));
// some cracy computation
return Esr(RN(12, a +b *ip, 16));
}
void caller() {
int a;
int b = 9;
short rslt = testFunc(9, 0.1, &a);
SomeStupidClass ssc;
ssc.changeMethod();
}
For a more in depth example take a look into the dbctest folder.
benchmark struct that limits typing work
single header json parser
single header sqlite3 wrapper that makes the conversion from sql table to class and back again extremely simple with minimal typing and speed overhead. Has an iterator interface that makes integration easy.
single header cmd line option parser. With automatic type conversation, short and long option names and pretty help printing.
write to<std::string>(variable)
and get a string. convenience wrapper around
stream operator
Tests if a given cpp file follows some random style rules
Hand in a gtk glade file and get a class in a header file that builds that widget and has protected data member pointing to all the widgets in the glade file. On top of that a cast operator is implemented that casts the class to the type of the top widget.
Usually there is a folder called HEADERNAMEtest that holds an example.
To use the header, just make the sweet.hpp folder an include for your compiler.
Always welcome!