Skip to content

papricasix/sweet.hpp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SWEET_HPP

alt text

A bunch of header useful for daily life. The headers contain functionally for everyday life. The tests are usually the documentation.

Functionality Documentation Header Test
Database Abstraction sweetql.hpp sweeql.hpp here
Logging logger.hpp here
Asyc Logging log.hpp here
Unit testing unit.hpp unit.hpp here
Design by Contract dbc.hpp dbc.hpp here
Type Safe Comparison compare.hpp compare.hpp here
Filesystem filesystem.hpp here
Fixed-point Types fixed.hpp here
int128 int128.hpp here
Benchmarking benchmark.hpp benchmark.hpp here
Json sjson.hpp here
Trie trie.hpp
Base64 base64.hpp here
bitset bitset.hpp here
Allocator bllocator.hpp here
Type Safe Conversation conv.hpp conv.hpp here
Fixed Size Vector fector.hpp here
Fixed Size Map fap.hpp here
String formatting format.hpp format.hpp here
Cmd line parser options.hpp options.hpp here
Semaphore semaphore.hpp
Stream helper functions streamhelper.hpp
String helper functions stringhelper.hpp
Sysinfo sysinfo.hpp

Usage

To use the header, just make the sweet.hpp folder an include for your compiler.

unit.hpp

Extremely small unit testing framework with a lot of nice unit testing features. All assert macros also have a non unit test version usable in "normal" code. Also includes QuickCheck like functionality.

UNITTEST(InformativTestName) {
	// your test here
	AS_T(boolValue);
	AS_T_M(boolValue, "some msg");
	AS_T_C(boolValue, [&]() { /* your code here */ });
	AS_EQ(1, 54);
	AS_NEQ(1, 54);
	AS_NEQ_C(1, 54, [&](/* your code here */ ) { });
}

int main() {
	if(!sweet::Unit::runTests()) {
		std::cerr<<"Some errors occoured"<<std::endl;
	}
	return 0;
}

More examples in: here

format.hpp

Variadic template type safe printf string formatting functions. Internally it uses std::stream operation, so custom types can be used by creating custom opertor<<(std::ostream&, CustomType); functions.

std::string s = format("Hello %s", "World");
format(someOutputStream, "Hello %s", "World");

More examples in: here

logger.hpp

Easy to use logger.

void someRandomFunction() {
	LOG();
	LOG("Hello");
	LOG("Hello %s", "World");
}

More examples in: here

dbc.hpp

We have unittest maybe some Design by Contract might also help.

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();
}

More examples in: here

benchmark.hpp

Benchmark structs that limits typing work, a Bench struct that stops time and a macro that stops time in a Compound Statement in a thread save manner.

#include <benchmark.hpp>

void fun() {
	BENCH(fun);
	...
}

int main() {
	sweet::Bench t; // Simple time stopping struct

	sweet::Benchmark::printResults(); // print results of BENCH marcos

	std::cout<<t.milli();
}

More examples in: here

sjson.hpp

Single header json parser with some bonus features like comments and multiline strings.

sweetql.hpp

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.

class ReservationPerson {
public:
	ReservationPerson() {}

	static SqlTable<ReservationPerson>& table() {
		static SqlTable<ReservationPerson> tab = 
			SqlTable<ReservationPerson>::sqlTable("ReservationPerson",
			SqlColumn<ReservationPerson>("Firstname", makeAttr(&ReservationPerson::firstname))
			SqlColumn<ReservationPerson>("age", makeAttr(&ReservationPerson::age))
		);

		return tab;
	};

	std::string firstname;
	long age;
};

...

	Sqlite3 dbImpl("dbfilename.db");
	SweetQL<Sqlite3> db(dbImpl);

	auto sel(db.select<ReservationPerson>());
	std::for_each(sel.first, sel.second, [&toDel](const ReservationPerson& p) {
	});

More examples in: here

options.hpp

A single header cmd line option parser. With automatic type conversation, short and long option names and pretty help printing.

Examples in: here

compare.hpp

With this header you can make type safe comparisons without taking care of the types of the values compared.

bool eq = sweet::equal(1337u,1337)
bool neq = sweet::notEqual(1337u,1337)

Examples in: here

conv.hpp

A D like "to" function thats safely converts single value types to another value type.

int a = to<int>("some int value as string");
std::string a = to<std::string>(a);

More examples in: here

sweetcpp.py

Tests if a given cpp file follows some random style rules

g2cpp.py

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.

trie.hpp

A trie implementation that is ""not yet"" stl quality but does work.

Contributions

Always welcome!

About

Nice sweet cpp header that help in daily life

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 92.2%
  • JavaScript 3.5%
  • CMake 1.8%
  • Python 1.3%
  • Makefile 1.1%
  • Shell 0.1%