Skip to content
/ ntbpp Public

NTB++ is a cross-platform header-only utility library for C++ >= 17

License

Notifications You must be signed in to change notification settings

notixbit/ntbpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notixbit C++ Utility Library (NTB++)

GitHub license CMake Test (Linux) CMake Test (Windows) CMake Test (macOS) CodeQL Analysis Generate Docs

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.

Table of contents


Namespaces

Ntb

using namespace Ntb;

Exposes the following namespaces:

namespace Ntb::Types
namespace Ntb::Templates
namespace Ntb::Colors

Ntb::Types

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>

Ntb::Templates

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 of Ntb::Types and exposes it.


Ntb::Colors

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 of Ntb::Types and exposes it.


Build

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

CMake

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


Install

You can use vcpkg, git clone or git submodule to install this library.

vcpkg

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

git clone <url>

Git Submodule

git submodule add <url>

Testing

Unit Testing Framework: CTest

make all test

Usage (Ntb::Colors)

#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:


Contributing

You're very welcome and free to contribute. Thank you.


License

MIT