File: tablestorage.cpp

package info (click to toggle)
einstein 2.0.dfsg.2-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,164 kB
  • ctags: 1,652
  • sloc: cpp: 10,429; makefile: 118; sh: 1
file content (59 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "tablestorage.h"
#include "unicode.h"
#include "exceptions.h"


TableStorage::TableStorage()
{
    try {
        table = Table(toMbcs(getFileName()));
    } catch (Exception &e) {
        std::cerr << e.getMessage() << std::endl;
    } catch (...) {
        std::cerr << "Unknown config file error" << std::endl;
    }
}

TableStorage::~TableStorage()
{
    flush();
}

std::wstring TableStorage::getFileName()
{
#ifndef WIN32
    return std::wstring(fromMbcs(getenv("HOME"))) + L"/.einstein/einsteinrc";
#else
    return L"einstein.cfg";
#endif
}

int TableStorage::get(const std::wstring &name, int dflt)
{
    return table.getInt(name, dflt);
}

std::wstring TableStorage::get(const std::wstring &name, 
            const std::wstring &dflt)
{
    return table.getString(name, dflt);
}

void TableStorage::set(const std::wstring &name, int value)
{
    table.setInt(name, value);
}

void TableStorage::set(const std::wstring &name, const std::wstring &value)
{
    table.setString(name, value);
}

void TableStorage::flush()
{
    table.save(getFileName());
}