https://github.com/gammasoft71/properties
another c#-like property accessor for C++11 and above.
https://github.com/gammasoft71/properties
cpp cpp-library cpp11 cpp14 cpp17 multi-platform properties property property-accessors
Last synced: about 1 month ago
JSON representation
another c#-like property accessor for C++11 and above.
- Host: GitHub
- URL: https://github.com/gammasoft71/properties
- Owner: gammasoft71
- License: mit
- Created: 2018-08-11T16:39:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-09T10:08:50.000Z (11 months ago)
- Last Synced: 2025-03-26T21:11:21.254Z (7 months ago)
- Topics: cpp, cpp-library, cpp11, cpp14, cpp17, multi-platform, properties, property, property-accessors
- Language: C++
- Homepage: https://gammasoft71.wixsite.com/properties
- Size: 1.26 MB
- Stars: 20
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# properties
**another c#-like property accessor for C++11 and above.**
[](https://gammasoft71.wixsite.com/properties)
## Continuous Integration build status
| Operating system | Status |
|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| Windows | [](https://ci.appveyor.com/project/gammasoft71/xtd-properties) |
| macOS | [](https://travis-ci.org/gammasoft71/xtd_properties) |
| Linux | [](https://travis-ci.org/gammasoft71/xtd_properties) |## Download the latest stable tunit version
[](https://sourceforge.net/projects/properties/files/latest/download)
## Features
* **properties** add c#-like property accessor to your c++ class.
* **properties** is distributed as a single header file.## What is it ?
A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods.
### For more information see
* [website](https://gammasoft71.wixsite.com/properties)
* [markdown documentations](docs/home.md)
* [sources](https://github.com/gammasoft71/properties)
* [Reference Guide](https://codedocs.xyz/gammasoft71/properties/)
* [Try it online](https://wandbox.org/permlink/yJY2t1qX5wV9FAcl)## There are three types of properties :
### readwrite :
The property accessor can be read and write.
```c++
class Foo {
public:
//...
property_ Number {
get_ {return this->number;},
set_ {this->number = value;}
};
//...
private:
int number = 0;
};
```### readonly :
The property accessor can be read only.
```c++
class Foo {
public:
//...
property_ Number {
get_ {return this->number;}
};
//...
private:
int number = 0;
};
```### writeonly :
The property accessor can be write only.
```c++
class Foo {
public:
//...
property_ Number {
set_ {this->number = value;}
};
//...
private:
int number = 0;
};
```## Read and write properties full example
person.cpp:
```c++
#include
#include
#includeclass person {
public:
person() noexcept = default;
person(person &&) noexcept = default;// Must be specified because the copy contructor of property class is deleted.
// The implicit or default copy constructor is not sufficient.
person(const person& other) noexcept : name_(other.name_), age_(other.age_) {}person& operator=(person&&) noexcept = default;
person& operator=(const person&) noexcept = default;
// Declare a name property of type std::string:
property_ name {
get_ {return name_;},
set_ {name_ = value;}
};
// Declare an age property of type int:
property_ age {
get_ {return age_;},
set_ {age_ = value;}
};
friend std::ostream& operator<<(std::ostream& os, const person& value) {return os << "[name = " << value.name << ", age = " << value.age << "]";}
private:
std::string name_ = "N/A";
int age_ = 0;
};int main(int argc, char* argv[]) {
std::cout << "Simple Properties" << std::endl;
// Create a new person object:
person p;
// Print out the name and the age associated with the pers:
std::cout << "person details - " << p << std::endl;// Set some values on the pers object:
p.name = "Joe";
p.age = 99;
std::cout << "person details - " << p << std::endl;// Increment the age property:
p.age += 1;
std::cout << "person details - " << p << std::endl;
}
```Console output:
```
Simple Properties
person details - [name = N/A, age = 0]
person details - [name = Joe, age = 99]
person details - [name = Joe, age = 100]
```## Getting Started
* [Installation](docs/downloads.md) provides download and install documentation.
* [Portability](docs/portability.md) provides information about C++, libraries dependency, Operating System suported, Compilators and Devepment Environment tools.
* [Examples](docs/examples.md) provides some examples.______________________________________________________________________________________________
© 2021 Gammasoft.