Awesome data-driven shell I am using: Nushell
From crago install
| int totalize(const std::vector<int> &v, int pos) { | |
| int total = 0; | |
| for(int i=0; i < pos.size(); ++i) { | |
| total += v[i]; | |
| } | |
| return total; | |
| } |
| some_class *get_operation(read_only_conn &db, const std::string &operation_id) { | |
| return new Operation(db.get_operation(operation_id)); | |
| } |
| some_class get_operation(read_only_conn &db, const std::string &operation_id) { | |
| return std::move(db.get_operation(operation_id)); | |
| } |
| struct my_value { | |
| std::string sval; | |
| using const_iterator = std::string::const_iterator; | |
| }; | |
| //... | |
| auto cfg = configuration::load<std::string, my_value>(fname, | |
| [](auto &config, iter_type b, iter_type m, iter_type e) { | |
| std::string k(b, m); | |
| my_value mv; | |
| mv.sval = std::string(m+1, e); |
| //Leitura de uma chave | |
| const std::string &log_dir = cfg.get("log.base_dir"); | |
| //Agora vamos pegar todas as configurações relativas a log | |
| auto plugins = cfg.prefix("log."); | |
| for(auto p : plugins) | |
| std::cout << p.first << "=>" << p.second << std::endl; | |
| //Lista de plugins na configuração | |
| auto tok = cfg.next_token("plugin.", '.'); |
| auto after(const Key &prefix) const -> std::unordered_set<Key> { | |
| std::unordered_set<Key> values; | |
| iterate_and_check(prefix, [&values, &prefix](const std::pair<Key,Value> &pair) { | |
| values.insert( pair.first.substr( prefix.size() ) ); | |
| }); | |
| return values; | |
| } | |
| auto next_token(const Key &prefix, const typename Key::value_type separator) const -> std::unordered_set<Key> { | |
| std::unordered_set<Key> values; |
| auto prefix(const Key &prefix) const -> std::vector<map_value> { | |
| std::vector<map_value> values; | |
| iterate_and_check(prefix, [&values](const std::pair<Key,Value> &pair) { | |
| values.push_back(pair); | |
| }); | |
| return values; | |
| } |
| using adder_func = std::function<void(const std::pair<Key,Value> &pair)>; | |
| void iterate_and_check(const Key &prefix, adder_func f_adder) const { | |
| std::for_each(begin(_items), end(_items), [&prefix, &f_adder](const std::pair<Key,Value> &pair) { | |
| //let's check prefix | |
| if( std::equal( begin(prefix), end(prefix), begin(pair.first) ) ) | |
| f_adder(pair); | |
| }); | |
| } |
| auto get(const Key &key) const -> const Value & { | |
| auto it = _items.find(key); | |
| if( it == _items.end() ) | |
| return _empty; | |
| return it->second; | |
| } |