client-cpp  0.6.3
DefaultConfigurationDelta.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef DEFAULTCONFIGURATIONDELTA_HPP_
18 #define DEFAULTCONFIGURATIONDELTA_HPP_
19 
20 #include "kaa/KaaDefaults.hpp"
21 
22 #ifdef KAA_USE_CONFIGURATION
23 
24 #include <map>
25 #include <string>
26 #include <memory>
27 
31 
32 namespace kaa {
33 
34 class DefaultConfigurationDelta: public IConfigurationDelta {
35 public:
40  DefaultConfigurationDelta() : handlerId_(0) {}
41 
46  DefaultConfigurationDelta(const DeltaHandlerId& handlerId)
47  : handlerId_(handlerId) {}
48 
53  virtual DeltaHandlerId getHandlerId() {
54  return handlerId_;
55  }
56 
62  virtual bool hasChanged(const std::string& field) {
63  return (deltaTypesStorage_.find(field) != deltaTypesStorage_.end());
64  }
65 
71  virtual DeltaTypePtr getDeltaType(const std::string& field);
72 
77  virtual std::string toString() const;
78 
82  void updateFieldDeltaType(const std::string& field, DeltaTypePtr type) {
83  deltaTypesStorage_[field] = type;
84  }
85 
86 private:
87  DeltaHandlerId handlerId_;
88  std::map<std::string, DeltaTypePtr> deltaTypesStorage_;
89 };
90 
91 inline DeltaTypePtr DefaultConfigurationDelta::getDeltaType(const std::string& field)
92 {
93  auto it = deltaTypesStorage_.find(field);
94  if (it != deltaTypesStorage_.end()) {
95  return it->second;
96  }
97 
98  DeltaTypePtr deltaPtr;
99  return deltaPtr;
100 }
101 
102 inline std::string DefaultConfigurationDelta::toString() const
103 {
104  std::stringstream ss;
105  ss << "[ ";
106  for (auto it = deltaTypesStorage_.begin(); it != deltaTypesStorage_.end();) {
107  ss << "{ \"" << it->first << "\": " << it->second->toString() <<" }";
108  if (++it != deltaTypesStorage_.end()) {
109  ss << ", ";
110  }
111  }
112  ss << " ]";
113  return ss.str();
114 }
115 
116 } /* namespace kaa */
117 
118 #endif
119 
120 #endif /* DEFAULTCONFIGURATIONDELTA_HPP_ */