Git init
[pkgs/e/elektra.git] / src / bindings / cpp / include / keyset
1 #ifndef CPP_KEYSET_H
2 #define CPP_KEYSET_H
3
4 #include <string>
5
6 #include <kdb.h>
7 #include <key>
8
9 namespace kdb {
10
11 class KeySetException : public std::exception
12 {
13         const char* what() {return "Key Exception";}
14 };
15
16 class KeySetOutOfRange : public KeySetException
17 {
18         const char* what() {return "Out of range in KeySet";}
19 };
20
21 class KeySetNotFound : public KeySetException
22 {
23         const char* what() {return "Could not find Key in KeySet";}
24 };
25
26 /**Key represents an elektra key.*/
27 class KeySet
28 {
29 public:
30         KeySet () :ks (ckdb::ksNew(0)) {}
31         KeySet (ckdb::KeySet *k) :ks(k) {}
32         KeySet (const KeySet &other);
33         KeySet (size_t alloc, va_list ap);
34         KeySet (size_t alloc, ...);
35         ~KeySet ();
36
37         ckdb::KeySet * getKeySet () const { return ks; }
38         void setKeySet (ckdb::KeySet * k) { ks = k; }
39
40         ckdb::KeySet* dup () const { return ckdb::ksDup(ks); }
41
42         void copy (const KeySet &other) { ckdb::ksCopy(ks,other.ks); }
43         void clear () { ckdb::ksCopy(ks,0); }
44
45         void sort();
46
47         size_t size () const;
48
49         size_t append (const Key &toAppend);
50         size_t append (const KeySet &toAppend);
51
52         Key pop();
53
54         void rewind () const;
55         Key next();
56         Key current() const;
57
58         Key head() const;
59         Key tail() const;
60
61         void setCursor(cursor_t cursor);
62         cursor_t getCursor() const;
63
64         Key lookup (const Key &k, const option_t options = KDB_O_NONE) const;
65         Key lookup (const std::string &name, const option_t options = KDB_O_NONE) const;
66         Key lookup (const char *name, const option_t options = KDB_O_NONE) const;
67
68         /*
69         ssize_t toStream(FILE* stream = stdout, option_t options = (option_t)0) const;
70         ssize_t output(FILE* stream = stdout, option_t options = 0) const;
71         ssize_t generate(FILE* stream = stdout, option_t options = 0) const;
72         */
73
74         friend std::ostream & operator << (std::ostream & os, const KeySet &d);
75         friend std::istream & operator >> (std::istream & os, KeySet &d);
76
77 private:
78         /*
79         KeySet (KeySet &k) :ks (k.ks) { }
80         KeySet (const KeySet &k) :ks (k.ks) { }
81         */
82
83 private:
84         ckdb::KeySet * ks; // holds elektra keyset struct
85 };
86
87 } // end of namespace kdb
88
89 #endif
90