https://github.com/bdfoster/flags
C++ library to easily and efficiently add boolean flags to your code.
https://github.com/bdfoster/flags
Last synced: about 1 year ago
JSON representation
C++ library to easily and efficiently add boolean flags to your code.
- Host: GitHub
- URL: https://github.com/bdfoster/flags
- Owner: bdfoster
- License: mit
- Created: 2016-04-05T00:26:26.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-10T03:38:37.000Z (almost 10 years ago)
- Last Synced: 2025-02-06T04:41:25.911Z (over 1 year ago)
- Language: C++
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Flags is a simple C++ script you can use to keep your boolean values for
your software. It is extremely simple, so much so that you may be
wondering why I even made it (I needed it... and a simple array wasn't
going to cut it).
Anyway, here's how to use it.
```
Flags flags = new Flags();
```
Inventive, I know...
To set a flag:
```
flags.set("logIt");
flags.read("logIt"); // true
flags.unset("logIt");
flags.read("logIt"); // false
```
That's great, but what if I didn't already set the flag?
Well, then it's false.
```
flags.read("noLog"); // false
```
Now, use it in our premade class:
```
class MyClass {
public:
Flags flag;
MyClass (void): flags (new Flags()) {
// Preset some flags
flag.set("readOnly");
flag.set("async");
flag.set("nonBlocking");
// Go on about your day...
}
void open (std::string, flags) {
if (flag.read("readOnly") {
...
} else {
...
}
...
}
};
```
And... that's it! Really simple, you don't need to know anything else.
Take a look at the well documented code in Flags.h
I'm always looking to do some optimization whilist making it easier to
use. You can open an issue at https://github.com/bdfoster/flags/issues
or send a pull request.