torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParameterMap.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef HAVE_CONFIG_H
17 #include "torc/generic/config.h"
18 #endif
19 
23 #include "torc/generic/View.hpp"
24 
25 namespace torc {
26 namespace generic {
27 
29  const {
30  if(!inContext) {
31  return ParameterSharedPtr();
32  }
33  ParameterSharedPtr param;
34  ParamDataPtr data;
35  mParameters.get(inContext, data);
36  if(!data) {
37  return ParameterSharedPtr();
38  } else {
39  data->mParams.get(inName, param);
40  if(!param) //Get default param value from parent
41  {
42  return get(data->mParentContext, inName);
43  }
44  }
45  return param;
46 }
47 
48 void ParameterMap::set(const ParameterContext& inContext, const std::string& inName,
49  const ParameterSharedPtr& inParam) {
50  ParamDataPtr data;
51  mParameters.get(inContext, data);
52  if(!data) {
53  return;
54  } else {
55  data->mParams.set(inName, inParam);
56  }
57  return;
58 }
59 
61  ParameterSharedPtr>& outParams) const {
62  typedef std::map<std::string, ParameterSharedPtr> DataMap;
63  ParamDataPtr data;
64  mParameters.get(inContext, data);
65  if(!data) {
66  return;
67  } else {
68  if(data->mParentContext) {
69  ParamDataPtr parentData;
70  mParameters.get(data->mParentContext, parentData);
71  parentData->mParams.getValueMap(outParams);
72  DataMap::iterator param = outParams.begin();
73  DataMap::iterator pEnd = outParams.end();
74  for(; param != pEnd; ++param) {
75  ParameterSharedPtr newValue;
76  data->mParams.get((*param).first, newValue);
77  //Value was overridden in child
78  if(newValue) {
79  outParams[(*param).first] = newValue;
80  }
81  }
82  } else {
83  //We have the cell context itself
84  data->mParams.getValueMap(outParams);
85  }
86  }
87 
88  return;
89 }
90 
92  ParameterSharedPtr>& outParams) const {
93  typedef std::map<std::string, ParameterSharedPtr> DataMap;
94  ParamDataPtr data;
95  mParameters.get(inContext, data);
96  if(!data) {
97  return;
98  } else {
99  //We have the cell context itself
100  data->mParams.getValueMap(outParams);
101  }
102  return;
103 }
104 
106  return mNextContext++;
107 }
108 
110  const ParameterContext& inParentContext) throw (Error) {
111  ParamDataPtr data;
112  mParameters.get(inContext, data);
113  if(data) {
114  //TBD::ERROR
115  } else {
116  data = boost::shared_ptr < ParamData > (new ParamData());
117  data->mParentContext = inParentContext;
118  mParameters.set(inContext, data);
119  }
120 }
121 
123  ParamDataPtr data;
124  mParameters.get(inContext, data);
125  return data;
126 }
127 
129  mParameters.remove(inContext);
130 }
131 
132 ParameterMap::ParameterMap() : mParameters(), mNextContext(1) {}
133 
135 
136 ParameterMap::ParameterMap(const ParameterMap& source) : mParameters(source.mParameters),
137  mNextContext(1) {}
138 
140  if(this != &source) {
141  mParameters = source.mParameters;
142  mNextContext = 1;
143  }
144  return *this;
145 }
146 
147 } // namespace generic
148 } // namespace torc
boost::shared_ptr< Parameter > ParameterSharedPtr
void registerContext(const ParameterContext &inContext, const ParameterContext &inParentContext=ParameterContext())
bool remove(const KeyType &inKey)
Definition: SymTab.hpp:153
std::string string
ParameterMap & operator=(const ParameterMap &source)
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
ParameterContext getNewContext()
SymTab< ParameterContext, ParamDataPtr > mParameters
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
void set(const ParameterContext &inContext, const std::string &inName, const ParameterSharedPtr &inParam)
void unregisterContext(const ParameterContext &inContext)
void getAllParameters(const ParameterContext &inContext, std::map< std::string, ParameterSharedPtr > &outParams) const
boost::shared_ptr< ParamData > ParamDataPtr
void getOverriddenParameters(const ParameterContext &inContext, std::map< std::string, ParameterSharedPtr > &outParams) const
bool isContextRegistered(const ParameterContext &inContext) const
ParameterSharedPtr get(const ParameterContext &inContext, const std::string &inName) const
ParameterContext mNextContext