项目作者: m-ri

项目描述 :
A class which help you to manage getter/setter in cpp projects
高级语言: C++
项目地址: git://github.com/m-ri/cpp_GetterSetter_Utilities.git
创建时间: 2017-12-26T16:58:34Z
项目社区:https://github.com/m-ri/cpp_GetterSetter_Utilities

开源协议:GNU General Public License v3.0

下载


cpp_GetterSetter_Utilities

A class which help you to manage getter/setter in cpp projects. You can trasparently add/delete these modifiers on existings variables, without big changes in the code

GetSet.h contains the library, while GetSet_Experiments.cpp provides some examples (ranging from trivial examples with integers and strings, to advanced usage with copy and move constructors).

Basic example

  1. #include "GetSet.h"
  2. GetSet<int> positiveVariable(3);
  3. positiveVariable.setGetter([](int& currentItem)-> int {return max(currentItem, 0); });
  4. positiveVariable.setSetter([](int& currentItem, int newValue) {
  5. if (newValue >= 0)currentItem = newValue;
  6. else currentItem = currentItem;/* throw std::exception("Added negative value");*/;
  7. });
  8. positiveVariable = 5;
  9. positiveVariable = -10;
  10. cout << positiveVariable;//output: 5