Files
core_zero/ReadMe.md
Timothy Prepscius 996151a56a flatten 20260225
2026-02-25 12:43:06 -05:00

2.1 KiB
Executable File

Core_Zero

Basic foundational classes

Building

Most of Core_Zero is header-only. To enable header-only use: #define TJP_CORE_HEADER_ONLY

The entire Core_Zero project will be converted to header only compatible soon.

To build all of the project use these steps.

mkdir my_project
cd my_project

git clone http://github.com/timprepscius/Core_Libraries
git clone http://github.com/timprepscius/Core_Zero
git clone http://github.com/timprepscius/Core_Make
cd Core_Zero
make

cd tests
make
.bin/Core_Zero_Tests.exe

How to use

Locks

// ----------------------------------------
// example for locks
// ----------------------------------------
void example_lock_tjp()
{
	Mutex mutex;
	
	auto lock = lock_of(mutex);
	do_something();
	
	auto should_send_signal = true;
	if (should_send_signal)
	{
		auto unlock = unlock_of(mutex);
		do_something();
	}
}

// using std
void example_lock_cpp()
{
	std::mutex mutex;
	std::lock_guard<std::mutex> lock(mutex);
	do_something();

	auto should_send_signal = true;
	if (should_send_signal)
	{
		try
		{
			mutex.unlock();
			do_something();
			mutex.lock();
		}
		catch (...)
		{
			mutex.lock();
		}
	}
}

Maps

// ----------------------------------------
// example for maps
// ----------------------------------------
void example_map_tjp()
{
	Map<int, int> map;
	if (auto value = map_value(map, 42))
		do_something_with(*value);

	if (auto value = map_value_erase(map, 42))
		do_something_with(*value);
}


// using std
void example_map_cpp()
{
	std::map<int, int> map;
	auto i = map.find(42);
	if (i != map.end())
	{
		do_something_with(*i);
	}
	
	auto j = map.find(42);
	if (j != map.end())
	{
		auto v = std::move(j->second);
		map.erase(j);
		
		do_something_with(v);
	}
}

Range iteration

// ----------------------------------------
// example for range
// ----------------------------------------
void example_range_tjp()
{
	for (auto i: range(42))
		do_something_with(i);
}

// using std
void example_range_cpp()
{
	for (auto k=0; k<42; ++k)
		do_something_with(k);
}

Other examples

Look at Core_Zero/Examples.cpp for more examples on how to use this library.