GithubHelp home page GithubHelp logo

maplewang / sweet.hpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from burner/sweet.hpp

0.0 2.0 0.0 3.7 MB

Nice sweet cpp header that help in daily life

License: Other

CMake 1.16% Makefile 1.15% C++ 92.69% Python 1.33% JavaScript 3.56% Shell 0.11%

sweet.hpp's Introduction

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!

sweet.hpp's People

Contributors

burner avatar eikemoe avatar orthographic-pedant avatar powertomato avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.