NTB++ is a cross-platform header-only utility library for C++ >= 17.
It includes Colors, Templates & Types.
Useful for printing colors, std::map
and std::vector
into std::cout
.
A couple of common typealiases (typedefs) like String
, UInt
, StringMap
, StringMapOf<Type>
are included as well.
Motivation:
We developed this lib as part of a program for a customer,
and we figured it might benefit other developers too.
using namespace Ntb;
Exposes the following namespaces:
namespace Ntb::Types
namespace Ntb::Templates
namespace Ntb::Colors
using namespace Ntb::Types;
Exposes the following types:
using Bool
using Char
using UChar
using Short
using UShort
using Int
using UInt
using Long
using LongLong
using ULong
using ULongLong
using String
using MapOf<Type,Type2>
using StringMapOf<Type>
using StringMap
using Vector<Type>
using namespace Ntb::Templates;
Exposes the following templates:
/**
* Overloads the '<<' cout operator to recognize vectors.
*
* @param The vector of type <T>.
* @return ostream.
*/
std::ostream &operator<<(std::ostream &os, const Vector<T> &v)
/**
* Overloads the '<<' cout operator to recognize maps.
*
* Prints a newline for all elements but the last.
*
* @param The map of type <T,U>.
* @return ostream.
*/
std::ostream &operator<<(std::ostream &os, const MapOf<T,U> &v)
Ntb::Templates
makes use ofNtb::Types
and exposes it.
using namespace Ntb::Colors;
Exposes the following utilities for coloring std::cout
output:
enum Colors : const UInt
/** Color helpers (optional) */
const UInt Colors::RESET
const UInt Colors::BLACK
const UInt Colors::RED
const UInt Colors::GREEN
const UInt Colors::YELLOW
const UInt Colors::BLUE
const UInt Colors::MAGENTA
const UInt Colors::CYAN
const UInt Colors::WHITE
/**
* Color marker for foreground/background.
*
* @param color The color code.
* @return String with color marker.
*/
const String col(const UInt color = Colors::RESET)
/**
* Color marker for foreground, background and text.
*
* @param str The input text.
* @param front The foreground color code.
* @param back The background color code.
* @return Encapsulated string with color markers.
*/
const String col(const String str, const UInt front, const UInt back = Colors::RESET)
Ntb::Colors
makes use ofNtb::Types
and exposes it.
Min Std: C++17
(structured bindings, inline, nested namespaces)
Tested against OS:
- Linux 4.14.154 Ubuntu 18.04.4 LTS x86_64 (Bionic Beaver)
- Windows 7 Home Premium SP1 64 bit
- Windows 10 Home/Pro
Tested against Compiler:
- Clang 9.0.0+
- MSVC 14.28.29910
- MSVC 19.28.29914
You can use cmake
to install the include files.
cd ntbpp
mkdir build && cd build
cmake ..
make install
Include files will be placed into: ${CMAKE_INSTALL_PREFIX}/include/notixbit/ntbpp
You can use vcpkg, git clone or git submodule to install this library.
Create/Edit the following files in your project:
vcpkg.json
{
"name": "your-project",
"version": "0",
"dependencies": [
"ntbpp"
]
}
vcpkg-configuration.json
{
"default-registry": {
"kind": "git",
"repository": "https://github.com/Microsoft/vcpkg",
"baseline": "e79c0d2b5d72eb3063cf32a1f7de1a9cf19930f3"
},
"registries": [
{
"kind": "git",
"repository": "https://github.com/notixbit/vcpkg-registry",
"baseline": "c4f78a946944d1a51e89bde41cd61b0460eb6a60",
"packages": [ "ntbpp" ]
}
]
}
Run: vcpkg install --feature-flags=registries,manifests
git clone <url>
git submodule add <url>
Unit Testing Framework: CTest
make all test
#include <notixbit.h>
using namespace Ntb::Colors;
std::cout
<< col("Notixbit Creative", Colors::WHITE, Colors::RED)
<< std::endl << std::endl
<< col("====POLICE==LINE==DO==NOT==CROSS====", Colors::BLACK, Colors::YELLOW)
<< std::endl << std::endl;
Result:
You're very welcome and free to contribute. Thank you.