Subversion Repositories HomeAutomation

Rev

Rev 1620 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1620 Rev 1627
Line 32... Line 32...
32
 
32
 
33
Store::Store(std::string filename)
33
Store::Store(std::string filename)
34
{
34
{
35
    this->filename_ = filename;
35
    this->filename_ = filename;
36
    this->modified_ = false;
36
    this->modified_ = false;
-
 
37
    this->flush_policy = FLUSH_INSTANT;
37
   
38
   
38
    std::ifstream file(filename.data());
39
    std::ifstream file(filename.data());
39
   
40
   
40
    if (!file.is_open())
41
    if (!file.is_open())
41
    {
42
    {
Line 69... Line 70...
69
}
70
}
70
 
71
 
71
Store::~Store()
72
Store::~Store()
72
{
73
{
73
   
74
   
-
 
75
}
-
 
76
 
-
 
77
void Store::SetFlushPolicy(Store::FlushPolicy flush_policy)
-
 
78
{
-
 
79
    this->flush_policy = flush_policy;
74
}
80
}
75
 
81
 
76
void Store::Flush()
82
void Store::Flush()
77
{
83
{
78
    if (this->modified_)
84
    if (this->modified_)
79
    {
85
    {
80
        std::ofstream file(this->filename_.data());
86
        std::ofstream file(this->filename_.data());
81
 
87
 
82
        if (!file.is_open())
88
        if (!file.is_open())
83
        {
89
        {
84
            throw std::runtime_error("Could not open " + this->filename_);
90
            throw std::runtime_error("Could not open " + this->filename_);
85
        }
91
        }
86
       
92
       
Line 93... Line 99...
93
        this->modified_ = false;
99
        this->modified_ = false;
94
    }
100
    }
95
}
101
}
96
 
102
 
97
Store::ParameterList& Store::GetParameters()
103
Store::ParameterList& Store::GetParameters()
98
{
104
{
99
    return this->parameters_;
105
    return this->parameters_;
100
}
106
}
101
 
107
 
102
std::string Store::GetParameter(std::string name)
108
std::string Store::GetParameter(std::string name)
103
{
109
{
104
    ParameterList::iterator it = this->parameters_.find(name);
110
    ParameterList::iterator it = this->parameters_.find(name);
105
   
111
   
106
    if (it == this->parameters_.end())
112
    if (it == this->parameters_.end())
107
    {
113
    {
108
        throw std::runtime_error("No such parameter");
114
        throw std::runtime_error("No such parameter");
109
    }
115
    }
110
   
116
   
111
    return it->second;
117
    return it->second;
112
}
118
}
113
 
119
 
114
void Store::SetParameter(std::string name, std::string value)
120
void Store::SetParameter(std::string name, std::string value)
115
{
121
{
116
    if (this->parameters_[name] != value)
122
    if (this->parameters_[name] != value)
-
 
123
    {
-
 
124
        if (value == "")
-
 
125
        {
-
 
126
            this->parameters_.erase(name);
-
 
127
        }
-
 
128
        else
117
    {
129
        {
118
        this->parameters_[name] = value;
130
            this->parameters_[name] = value;
-
 
131
        }  
-
 
132
           
119
        this->modified_ = true;
133
        this->modified_ = true;
120
       
134
       
-
 
135
        if (this->flush_policy == FLUSH_INSTANT)
-
 
136
        {
121
        this->Flush();
137
            this->Flush();
-
 
138
        }
122
    }
139
    }
123
}
140
}
124
   
141
   
125
}; // namespace storage
142
}; // namespace storage
126
}; // namespace atom
143
}; // namespace atom