Small fixes
[evolve-layout.git] / C / Layout.cpp
blob4be660ba7926368ca4cf0c00ed6694dcfa93fac0
1 #pragma once
3 #include <string>
4 #include <vector>
5 #include <iterator>
7 #include <glibmm/ustring.h>
8 class Layout {
9 typedef Glib::ustring string;
10 typedef std::vector<string::value_type> vector;
11 public:
12 typedef vector::iterator iterator;
13 typedef vector::reverse_iterator reverse_iterator;
15 Layout(const std::string &s = "") {
16 this->layout.reserve(12+11+10); // 33 keys
18 this->layout.clear();
19 this->add(s);
21 virtual ~Layout() {}
22 //Layout(const Layout &l) {}
23 //Layout &operator=(const Layout &l) {}
25 void add(const string &s) {
26 copy(s.begin(), s.end(), std::back_inserter(this->layout));
28 void add(const std::string &s) {
29 this->add(string(s));
31 void addLine(const std::string &s) {
32 this->add(s);
33 this->layout.push_back('\n');
36 void add(const string::value_type c) {
37 this->layout.push_back(c);
40 // TODO write a back_inserter
41 const std::string toString() const {
42 std::string s;
44 vector::const_iterator it = this->layout.begin();
45 vector::const_iterator end;
47 for(end = it+5; it != end; ++it) {
48 s.append(string(1, *it)); }
49 s.append(" ");
51 for(end = it+7; it != end; ++it) {
52 s.append(string(1, *it)); }
53 s.append("\n");
55 for(end = it+5; it != end; ++it) {
56 s.append(string(1, *it)); }
57 s.append(" ");
59 for(end = it+6; it != end; ++it) {
60 s.append(string(1, *it)); }
61 s.append("\n");
63 for(end = it+5; it != end; ++it) {
64 s.append(string(1, *it)); }
65 s.append(" ");
67 for(end = this->layout.end(); it != end; ++it) {
68 s.append(string(1, *it)); }
70 return s;
72 const string toUString() const {
73 string s;
74 for(vector::const_iterator it = this->layout.begin();
75 it != this->layout.end(); ++it) {
76 s.append(string(1, *it));
78 return s;
81 // random access
82 string::reference operator[](const int i) {
83 return this->layout[i];
86 // return an iterator on the vector
87 // iterates gunichars, need to be converted before sending to stream
88 iterator begin() {
89 return this->layout.begin();
91 iterator end() {
92 return this->layout.end();
94 reverse_iterator rbegin() {
95 return this->layout.rbegin();
97 reverse_iterator rend() {
98 return this->layout.rend();
100 private:
101 // a vector storing keys to allow random (write) access
102 // only stores a single char per position
103 vector layout;