Skip to content

funatsufumiya/ofxAbseil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ofxAbseil

abseil-cpp for openFrameworks (tested on v0.12.0 Win/Mac/Linux/iOS, abseil version: lts_2024_07_22)

Notes

  • Some Windows workaround fixes (e.g. fix min/max problem, disable RawLog, etc) are applied.
  • *_test.cc, *_benchmark.cc, and related files are not included in this addon.
  • Already includes gmock and gtest from googletest as dependencies.

Usage

See example. (NOTE: Please use projectGenerator before run it)

#include "absl/strings/str_join.h"
#include "absl/types/optional.h"
#include "absl/hash/hash.h"
#include "absl/container/flat_hash_map.h"
#include "absl/types/any.h"

void ofApp::setup(){
    ofLogToConsole();

    // test of absl str_join

    std::vector<std::string> v = {"foo", "bar", "baz"};
    std::string s = absl::StrJoin(v, "-");

    ofLogNotice("ofApp") << "absl::StrJoin(v, \"-\") = " << s;

    // test of absl optional

    absl::optional<int> o1 = 42;
    absl::optional<int> o2 = absl::nullopt;
    
    ofLogNotice("ofApp") << "absl::optional: o1 = " << o1.value_or(0);
    ofLogNotice("ofApp") << "absl::optional: o2 = " << o2.value_or(0);
    
    // test of absl hash
    
    absl::Hash<std::string> hasher;
    std::string str = "hello";
    size_t hash = hasher(str);

    ofLogNotice("ofApp") << "absl::Hash<std::string>: hash = " << hash;

    // test of hash map of any type

    absl::flat_hash_map<std::string, absl::any> map;
    map["int"] = 42;
    map["string"] = std::string("hello");

    ofLogNotice("ofApp") << "absl::flat_hash_map<std::string, absl::any>: map[\"int\"] = " << absl::any_cast<int>(map["int"]);
    ofLogNotice("ofApp") << "absl::flat_hash_map<std::string, absl::any>: map[\"string\"] = " << absl::any_cast<std::string>(map["string"]);
}

// Result:
// [notice ] ofApp: absl::StrJoin(v, "-") = foo-bar-baz
// [notice ] ofApp: absl::optional: o1 = 42
// [notice ] ofApp: absl::optional: o2 = 0
// [notice ] ofApp: absl::Hash<std::string>: hash = 8734633936850012531
// [notice ] ofApp: absl::flat_hash_map<std::string, absl::any>: map["int"] = 42
// [notice ] ofApp: absl::flat_hash_map<std::string, absl::any>: map["string"] = hello

LICENSE

NOTE: No specific copyright is claimed for this repository changes (for oF binding), but the Apache License 2.0 or MIT License can be applied if necessary.

Side notes

  • If you would like to use std::ranges alternative (not included in abseil), use ofxRangeV3

About

abseil for openFrameworks

Topics

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE.md
Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published