client-cpp  0.0.1-SNAPSHOT
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 <map>
21 #include <string>
22 #include <memory>
23 
27 
28 namespace kaa {
29 
31 public:
36  DefaultConfigurationDelta() : handlerId_(0) {}
37 
43  : handlerId_(handlerId) {}
44 
50  return handlerId_;
51  }
52 
58  virtual bool hasChanged(const std::string& field) {
59  return (deltaTypesStorage_.find(field) != deltaTypesStorage_.end());
60  }
61 
67  virtual DeltaTypePtr getDeltaType(const std::string& field);
68 
73  virtual std::string toString() const;
74 
78  void updateFieldDeltaType(const std::string& field, DeltaTypePtr type) {
79  deltaTypesStorage_[field] = type;
80  }
81 
82 private:
83  DeltaHandlerId handlerId_;
84  std::map<std::string, DeltaTypePtr> deltaTypesStorage_;
85 };
86 
87 inline DeltaTypePtr DefaultConfigurationDelta::getDeltaType(const std::string& field)
88 {
89  auto it = deltaTypesStorage_.find(field);
90  if (it != deltaTypesStorage_.end()) {
91  return it->second;
92  }
93 
94  DeltaTypePtr deltaPtr;
95  return deltaPtr;
96 }
97 
98 inline std::string DefaultConfigurationDelta::toString() const
99 {
100  std::stringstream ss;
101  ss << "[ ";
102  for (auto it = deltaTypesStorage_.begin(); it != deltaTypesStorage_.end();) {
103  ss << "{ \"" << it->first << "\": " << it->second->toString() <<" }";
104  if (++it != deltaTypesStorage_.end()) {
105  ss << ", ";
106  }
107  }
108  ss << " ]";
109  return ss.str();
110 }
111 
112 } /* namespace kaa */
113 
114 #endif /* DEFAULTCONFIGURATIONDELTA_HPP_ */
DefaultConfigurationDelta(const DeltaHandlerId &handlerId)
void updateFieldDeltaType(const std::string &field, DeltaTypePtr type)
virtual bool hasChanged(const std::string &field)
virtual std::string toString() const
boost::shared_ptr< IDeltaType > DeltaTypePtr
Definition: IDeltaType.hpp:28
virtual DeltaTypePtr getDeltaType(const std::string &field)