Giter Club home page Giter Club logo

rst's Introduction

Build Status

RST C++ library

This is the RST C++11 library. It doesn't use exceptions and RTTI.

It is licensed under the Simplified BSD License.

Now the library contains the following components:

Bind

A set of std::function utilities like NullFunction and DoNothing.

Check

A set of macros for better programming error handling.

void Foo(void* ptr) {
  // Aborts in debug build.
  RST_DCHECK(ptr != nullptr);
  // Aborts in debug and release builds.
  RST_CHECK(ptr != nullptr);
  // RST_DCHECK(false) actually.
  RST_NOTREACHED();
}

Defer

A Go-like (also a Microsoft GSL finally-like) method of deferring the action execution at the end of the function.

void Foo() {}

void Bar() {
  // When block ends, calls Foo().
  RST_DEFER(Foo);
}

Files

File utils.

Format

A Python-like string format library

const std::string res = "{} {}, {}{}{}"_format(1234, "Hello", "wor", 'l', 'd');
EXPECT_EQ(res, "1234 Hello, world");

GUID

GUID generation.

// Returns GUID as described in RFC 4122.
const std::string guid = GenerateGUID();

Hidden String

A compile time string encryption. It's useful when you need to have a "secret" strings in a program that are not findable in a hex editor.

RST_HIDDEN_STRING(kFirst, "abcDEF");
EXPECT_EQ(kFirst.Decrypt(), "abcDEF");

Legacy

A set of features unavaliable for C++11 compilers:

  • make_unique
  • Optional

Logger

A fast flexible thread-safe logger for C++11.

auto sink = FileNameSink::Create("path.log");
sink.Ignore();  // Handle error here.

Logger logger(std::move(*sink));
Logger::SetLogger(&logger);

LOG_DEBUG("Log");

Macros

A Google-like RST_DISALLOW_COPY_AND_ASSIGN macros.

class Foo {
 private:
  RST_DISALLOW_COPY(Foo);
  RST_DISALLOW_ASSIGN(Foo);
  RST_DISALLOW_COPY_AND_ASSIGN(Foo);
  RST_DISALLOW_IMPLICIT_CONSTRUCTORS(Foo);
};

A Chromium-like build-flag support.

#define RST_BUILDFLAG_FOO() (true)
#define RST_BUILDFLAG_BAR() (false)

#if RST_BUILDFLAG(FOO)
// These lines compile.
#endif  // RST_BUILDFLAG(FOO)

#if RST_BUILDFLAG(BAR)
// These lines are not included to the build.
#endif  // RST_BUILDFLAG(BAR)

Memory

A set of memory related utilities like WeakPtr, WrapUnique.

std::unique_ptr<int> ptr;
ptr = WrapUnique(new int(0));

class Foo {
 public:
  WeakPtr<Foo> AsWeakPtr() const { return weak_factory_.GetWeakPtr(); }

 private:
  WeakPtrFactory weak_factory_{this};
};

WeakPtr<Foo> ptr;
{
  Foo foo;
  ptr = foo.AsWeakPtr();
}

if (ptr != nullptr) {
  // Do something here.
}

NoDestructor

A Chromium-like static storage duration support.

const std::string& GetString() {
  static NoDestructor<std::string> str("Hello!");
  return *str;
}

NotNull

Microsoft GSL-like NotNull class that restricts a pointer or smart pointer to only hold non-null values.

void Foo(NotNul<int*>) {
}

int i = 0;
Foo(&i);  // OK.
Foo(nullptr);  // Compilation error.

int* ptr = nullptr;
Foo(ptr);  // Debug assert.

Nullable class that permits a pointer or smart pointer to be nullptr. Must be checked for null in order to dereference.

void Foo(Nullable<int*> ptr) {
  if (ptr != nullptr)
    *ptr = 0;  // OK.
}

void Bar(Nullable<int*> ptr) {
  *ptr = 0;  // Debug assert.
}

Preferences

Chromium-like preferences.

Random

Random device to be used in one place.

RTTI

LLVM-like custom RTTI support.

STL

A set of STL utilities.

const std::vector<int> vec = {1, 2, 3, 4};
std::string str;
for (const auto i : Reversed(&vec))
  str += std::to_string(i);
EXPECT_EQ(str, "4321");

std::vector<int> vec = {-1, 400, 10, 0, 3, -5};
Sort(&vec);
EXPECT_TRUE(std::is_sorted(std::cbegin(vec), std::cend(vec)));
// etc.

Status

A Google-like Status class for recoverable error handling with small improvements. It's impossible now to ignore an error.

TaskRunner

A set of task runner utilities like PollingTaskRunner and ThreadTaskRunner.

Threading

A set of thread related utilities like Barrier.

Type

A Chromium-like StrongAlias class.

Value

A Chromium-like Value class for representing JSON values in a program.

rst's People

Contributors

sabbakumov 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.