SetOnce is a header ony library that allows you to initialize the value of an object only once i.e. single-assignment. Once assigned a value, a final variable's value cannot be changed.
Build enviroment must support C++11 standard.
- Ultralight (less than 100 LOC)
- Easy to use
- Headers only
- No 3rd-party dependencies
- Cross-platform (Windows, Linux, vxWorks, FreeBSD, macOS, Android)
- Thread and type safe
- Uses modern CMake; alternatively can be used wothout CMake by just adding the header file to source-code
- Only C++11 support required
- Store Configuration Data
- Store Calibration Data
- Store Compensation Data
- Any Data that needs to be stored/written only once but read overtime throughout the lifetime of program
- Import Library Header
#include <SetOnce.hxx>
#include <iostream> //Not needed by SetOnce library but is needed for std::cout [Step 3, 5, 6]
- Create an object of SetOnce class.
SetOnce<int> a; //Craete an instance of SetOnce object holding integer data
- Check if data has been set i.e. the data has been initialized in SetOnce object
std::cout << "Is the value of 'a' set : " << std::boolalpha << a.is_set() << std::endl; //Check if the value of a has been set
- Set the value (data) to the SetOnce object
a.set(66); //Set the value of 66 to a
- Check if data has been set i.e. the data has been initialized in SetOnce object
std::cout << "Is the value of 'a' set : " << std::boolalpha << a.is_set() << std::endl; //Check if the value of a has been set
- Read the value stored in the SetOnce object (return by value)
std::cout << "a : " << a.get() << std::endl; //Get the value of a
- Alternatively read the value stored in the SetOnce object (return by constant reference)
const int& b = a.get_const_reference();
std::cout << "a : " << b << std::endl; //Get the value of a
This version of SetOnce is licensed under the Apache2 license. You can freely use it in your commercial or opensource software.
Initial public release