/bspec-cpp

A C++ library for structuring business rules

Primary LanguageC++MIT LicenseMIT

bspec-cpp Build Status

A C++ library for structuring business rules.

Overview

Structuring and validating business rules in JavaScript

Usage

The essential part of the library is a specification -- an object with the following properties:

  • it can be combined with other specification-objects using .And(), .Or() and .Not() methods to form a composite specification and express more complex rules.
  • it implements is_satisfied_by method -- a predicate that determines whether a candidate object does or does not satisfy some criteria.

To create a specification:

  • create a new class that inherits basic_spec<T>.
  • override the clone method to allow copying.
  • override the is_satisfied_by method.

API

.And(const basic_spec&)

the and of a set of specifications is true if and only if all of its operands are true.

auto spec = spec1.And(spec2);

.Or(const basic_spec&)

the or of a set of specifications is true if and only if one or more of its operands is true

auto spec = spec1.Or(spec2);

.Not()

not negates the specification

auto spec = spec1.Not();

.is_satisfied_by(const T&) : bool

checks whether some candidate object satisfies the specification.

  auto result = spec.is_satisfied_by(obj);
  
  // `result` true|false value
  // should throw an exception in case of an error

Tested compilers

  • Linux (x86/64)
    • GCC 5.1
    • Clang 3.7

Installation

This is a header only library, in order to use it make the bspec-include directory available to your project and include the header file in your source code:

#include "bspec/spec.h"

Building Tests & Examples

This project tests and examples use the Cross-platform Make (CMake) build system. Tests depend on Google Test Framework. gtest-1.7.0 is recommended.

Linux

The recommended way is to create 'out of source' build:

mkdir build
cd build
cmake ..
make

Contact

[Grigoriy Chudnov] (mailto:g.chudnov@gmail.com)

License

Distributed under the The MIT License (MIT).