GUIDOLib  1.7.7
Guido Engine Internal Documentation
TagParameterMap.h
1 /*
2  GUIDO Library
3  Copyright (C) 2017 Grame
4 
5  This Source Code Form is subject to the terms of the Mozilla Public
6  License, v. 2.0. If a copy of the MPL was not distributed with this
7  file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9  Grame Research Laboratory, 11, cours de Verdun Gensoul 69002 Lyon - France
10  research@grame.fr
11 
12 */
13 
14 #ifndef ___TagParameterMap___
15 #define ___TagParameterMap___
16 
17 #include <iostream>
18 #include <string>
19 #include <vector>
20 #include <map>
21 #include <memory>
22 
23 #include "TagParameter.h"
24 
25 class TagParameter;
26 
27 //-------------------------------------------------------------------------------------------
30 //-------------------------------------------------------------------------------------------
31 class TagParameterMap : public std::map<std::string, STagParameterPtr>
32 {
33  public:
35  // creates a new TagParameterMap out of a definition string ...
36  TagParameterMap(const std::string & str);
37  virtual ~TagParameterMap() {}
38 
39  void Add (STagParameterPtr param);
40  void Add (const TagParameterMap& map);
41  void Remove (const char* key);
42 // void clear () { fMap.clear(); }
43 // size_t size () const { return fMap.size(); }
44  // check a parameters list againts with current one:
45  // - check that current params include required param in list
46  // - check that current params exist in list
47  // - check float parameters type for unit settings
48  bool Match (const TagParameterMap& list, const char* tagName) const;
49  void checkUnit (const TagParameterMap& list) const;
50 
51  std::vector<std::string> getKeys() const;
52 
53 
54  template<typename T> const T* get (const char* param) const {
55  const_iterator i = find (param);
56  if (i == end()) return 0;
57  return dynamic_cast<const T*>(i->second.get());
58  }
59 
60  void print (std::ostream& out, bool gmnform=true) const;
61 
62  static std::vector<std::string> split (const std::string & str, char sep);
63  static std::vector<std::string> getKeys (const std::string & str);
64 
65  private:
66  typedef std::map<std::string, STagParameterPtr> TPMap;
67  typedef std::pair<std::string, STagParameterPtr> TIMap;
68 
69 // TPMap fMap;
70 //
71 // TPMap::const_iterator begin() const { return fMap.begin(); }
72 // TPMap::const_iterator end() const { return fMap.end(); }
73 
74 // STagParameterPtr find (const std::string & str) const;
75  STagParameterPtr str2tagParam (const std::string & str) const;
76  bool checkRequired (const TagParameterMap& list, const char* tagName) const;
77  bool checkExist (const TagParameterMap& list) const;
78 };
79 inline std::ostream& operator << ( std::ostream & os, const TagParameterMap& m) { m.print(os); return os; }
80 inline std::ostream& operator << ( std::ostream & os, const TagParameterMap* m) { m->print(os); return os; }
81 
82 
83 #endif
TagParameterMap::Remove
void Remove(const char *key)
TagParameterMap::get
const T * get(const char *param) const
Definition: TagParameterMap.h:54
TagParameterMap::Match
bool Match(const TagParameterMap &list, const char *tagName) const
TagParameterMap::TagParameterMap
TagParameterMap()
TagParameterMap::print
void print(std::ostream &out, bool gmnform=true) const
TagParameterMap::checkUnit
void checkUnit(const TagParameterMap &list) const
TagParameterMap::Add
void Add(STagParameterPtr param)
TagParameter
The base class for all guido tags.
Definition: TagParameter.h:26
TagParameterMap::split
static std::vector< std::string > split(const std::string &str, char sep)
TagParameterMap::~TagParameterMap
virtual ~TagParameterMap()
Definition: TagParameterMap.h:37
TagParameterMap::getKeys
std::vector< std::string > getKeys() const
TagParameterMap
A list of tag parameters represented as a map.
Definition: TagParameterMap.h:31
operator<<
std::ostream & operator<<(std::ostream &os, const svgendl &eol)

Guido Project Copyright © 2019 Grame-CNCM