All Projects → neargye-forks → state_saver

neargye-forks / state_saver

Licence: MIT License
Transferred to https://github.com/Neargye/yacppl

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to state saver

Calculate
Math Expressions Parser Engine
Stars: ✭ 30 (+114.29%)
Mutual labels:  no-dependencies
jthread-lite
C++20's jthread for C++11 and later in a single-file header-only library
Stars: ✭ 43 (+207.14%)
Mutual labels:  no-dependencies
flatboard
A very Fast & Lightweight Flat-file forum software, Markdown and BBcode editor.
Stars: ✭ 30 (+114.29%)
Mutual labels:  no-dependencies
aioconnectors
Simple secure asynchronous message queue
Stars: ✭ 17 (+21.43%)
Mutual labels:  no-dependencies
Minemap
An efficient map viewer for Minecraft seed in a nice GUI with utilities without ever needing to install Minecraft.
Stars: ✭ 104 (+642.86%)
Mutual labels:  no-dependencies
tabbis.js
Pure vanilla javascript tabs with nesting
Stars: ✭ 44 (+214.29%)
Mutual labels:  no-dependencies
http-node-api
O objetivo dessa aplicação era criar uma API sem nenhuma dependência externa, apenas utilizando as bibliotecas nativas do NodeJS. Tudo foi feito utilizando 100% Javascript.
Stars: ✭ 44 (+214.29%)
Mutual labels:  no-dependencies
result
A lightweight C++11-compatible error-handling mechanism
Stars: ✭ 121 (+764.29%)
Mutual labels:  no-dependencies
byte-lite
byte lite - A C++17-like byte type for C++98, C++11 and later in a single-file header-only library
Stars: ✭ 43 (+207.14%)
Mutual labels:  no-dependencies
GitHubSearch
GitHub iOS client with minimum third-party dependencies.
Stars: ✭ 34 (+142.86%)
Mutual labels:  no-dependencies
influxdb-c
💙 C write client for InfluxDB.
Stars: ✭ 28 (+100%)
Mutual labels:  no-dependencies
RouteNow
RouteNow is a small fast library ⚡ that will help you in developing a SinglePage Application without any dependencies like jQuery, AngularJs, vue.js or any of those bulky frameworks.
Stars: ✭ 17 (+21.43%)
Mutual labels:  no-dependencies
CLIp
CLIp is a clipboard manager for a command line interface written in 100% standard C only. Pipe to it to copy, pipe from it to paste.
Stars: ✭ 12 (-14.29%)
Mutual labels:  no-dependencies
komapper
Kotlin SQL Mapper
Stars: ✭ 28 (+100%)
Mutual labels:  no-dependencies
iutest
c++ testing framework
Stars: ✭ 58 (+314.29%)
Mutual labels:  no-dependencies
value-ptr-lite
value-ptr-lite - A C++ smart-pointer with value semantics for C++98, C++11 and later in a single-file header-only library
Stars: ✭ 38 (+171.43%)
Mutual labels:  no-dependencies
autocomplete
Simple accessible autocomplete for vanilla javacript with support for remote & local data, ~3KB gzip
Stars: ✭ 38 (+171.43%)
Mutual labels:  no-dependencies
tall
Promise-based, No-dependency URL unshortner (expander) module for Node.js
Stars: ✭ 56 (+300%)
Mutual labels:  no-dependencies
subjx
Drag/Resize/Rotate Javascript library
Stars: ✭ 155 (+1007.14%)
Mutual labels:  no-dependencies
github-profile-card
Simple and easy to use widget with your GitHub profile — No dependencies
Stars: ✭ 98 (+600%)
Mutual labels:  no-dependencies
  _____ _        _          _____                         _____
 / ____| |      | |        / ____|                       / ____|_     _
| (___ | |_ __ _| |_ ___  | (___   __ ___   _____ _ __  | |   _| |_ _| |_
 \___ \| __/ _` | __/ _ \  \___ \ / _` \ \ / / _ \ '__| | |  |_   _|_   _|
 ____) | || (_| | ||  __/  ____) | (_| |\ V /  __/ |    | |____|_|   |_|
|_____/ \__\__,_|\__\___| |_____/ \__,_| \_/ \___|_|     \_____|

Github Releases License

State Saver C++

Sometimes a certain value has to change only for a limited scope. This class wrapper saves a copy of the current state of some object, and resets the object’s state at destruction time, undoing any change the object may have gone through.

  • saver_exit - saves the original variable value and restores on scope exit.

  • saver_fail - saves the original variable value and restores on scope exit when an exception has been thrown.

  • saver_success - saves the original variable value and restores on scope exit when no exceptions have been thrown.

Features

  • C++11
  • Header-only
  • Dependency-free

Examples

  • State Saver on exit

    void Foo(A& a)
      SAVER_EXIT(a);
      ... // Alter state from non-const functions.
      ... // Other code.
      // Original state automatically restored on scope exit.
    }
  • State Saver on fail

    void Foo(A& a)
      SAVER_FAIL(a);
      ... // Alter state from non-const functions.
      ... // Other code.
      // Original state automatically restored when an exception has been thrown.
    }
  • State Saver on success

    void Foo(A& a)
      SAVER_SUCCESS(a);
      ... // Alter state from non-const functions.
      ... // Other code.
      // Original state automatically restored when no exceptions have been thrown.
    }

Synopsis

Reference

saver_exit

  • saver_exit<decltype(object)> state_saver{object}; - creation saver_exit for the object.
  • SAVER_EXIT{object}; - macro for creating saver_exit for the object.
  • MAKE_SAVER_EXIT(name) {object}; - macro for creating named saver_exit for the object.
  • WITH_SAVER_EXIT(object) {/*...*/}; - macro for creating scope with saver_exit for the object.

saver_fail

  • saver_fail<decltype(object)> state_saver{object}; - creation saver_fail for the object.
  • SAVER_FAIL{object}; - macro for creating saver_fail for the object.
  • MAKE_SAVER_FAIL(name) {object}; - macro for creating scope with saver_fail for the object.
  • WITH_SAVER_FAIL(object) {/*...*/}; - macro for creating scope with saver_fail for the object.

saver_success

  • saver_success<decltype(object)> state_saver{object}; - creation saver_success for the object.
  • SAVER_SUCCESS{object}; - macro for creating saver_success for the object.
  • MAKE_SAVER_SUCCESS(name) {object}; - macro for creating scope with saver_success for the object.
  • WITH_SAVER_SUCCESS(object) {/*...*/}; - macro for creating scope with saver_success for the object.

Interface of state_saver

saver_exit, saver_fail, saver_success implement state_saver interface.

  • constructor state_saver(T& object) - construct state_saver with saved object.

  • dismiss() - dismiss restore on scope exit.

  • restore() - resets the object’s state. Requirements copy operator =.

Requirements to saved object

  • POD or object semantic (cannot be reference, function, ...).
  • Copy constructor.
  • operator= (no-throw one preferred).

Configuration macros

Throwable settings

  • STATE_SAVER_NO_THROW_CONSTRUCTIBLE define this to require nothrow constructible.

  • STATE_SAVER_MAY_THROW_RESTORE define this to restore may throw exceptions.

  • STATE_SAVER_NO_THROW_RESTORE define this to require noexcept restore.

  • STATE_SAVER_SUPPRESS_THROW_RESTORE define this to exceptions during restore will be suppressed.

  • By default using STATE_SAVER_MAY_THROW_RESTORE.

  • STATE_SAVER_CATCH_HANDLER define this to add exceptions handler. If STATE_SAVER_SUPPRESS_THROW_RESTORE is not defined, it will do nothing.

Assignable settings

  • STATE_SAVER_FORCE_MOVE_ASSIGNABLE define this to restore on scope exit will be move assigned.

  • STATE_SAVER_FORCE_COPY_ASSIGNABLE define this to restore on scope exit will be copy assigned.

  • By default using move assignable if noexcept.

Integration

You should add required file state_saver.hpp.

Compiler compatibility

  • Clang/LLVM >= 5
  • MSVC++ >= 14.0 / Visual Studio >= 2015
  • Xcode >= 9
  • GCC >= 5

Licensed under the MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].