1 /*************************************************************************** 2 * 3 * Copyright 2012 BMW Car IT GmbH 4 * 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 ****************************************************************************/ 19 20 21 #ifndef __STRINGMAPTREE_H__ 22 #define __STRINGMAPTREE_H__ 23 24 #include <map> 25 #include <list> 26 #include <string> 27 28 using std::map; 29 using std::list; 30 using std::string; 31 32 class StringMapTree 33 { 34 public: 35 string mNodeLabel; 36 map<string, pair<string, string> > mNodeValues;//key: property name, value= pair(type, property value) 37 list<StringMapTree*> mChildren;// pair(type, child component node) 38 39 string toString(string prefix = "") 40 { 41 string result; 42 result += prefix + mNodeLabel + ":{\n"; 43 for(map<string, pair<string, string> >::iterator it = mNodeValues.begin(); it != mNodeValues.end(); ++it) 44 { 45 result += prefix + "\t[" + it->first + ":" + it->second.first + "]=[" + it->second.second + "]\n"; 46 } 47 for(list<StringMapTree*>::iterator it = mChildren.begin(); it != mChildren.end(); ++it) 48 { 49 result += (*it)->toString(prefix + "\t") +"\n"; 50 } 51 result += prefix + "}"; 52 53 return result; 54 } 55 ~StringMapTree()56 virtual ~StringMapTree() 57 { 58 for(list<StringMapTree*>::iterator it = mChildren.begin(); it != mChildren.end(); ++it) 59 { 60 delete *it; 61 } 62 } 63 }; 64 65 #endif /* __STRINGMAPTREE_H__ */ 66