NCL Composer  0.1.5
 All Classes Functions Variables Pages
qnstutil.h
1 #ifndef QNSTUTIL_H
2 #define QNSTUTIL_H
3 
4 #include <algorithm>
5 #include <QMap>
6 
7 #include "qnstgraphicsentity.h"
8 
10 
11 class QnstUtil {
12 public:
21  static QnstGraphicsEntity *makeGraphicsEntity(Qnst::EntityType type,
22  QnstGraphicsEntity *parent = 0,
23  const QMap<QString, QString> &props = (QMap<QString,QString>()));
24 
32  static Qnst::EntityType getnstTypeFromMime(const QString &mimeType);
33 
40  static QString iconFromMediaType(Qnst::EntityType type);
41 
48  static Qnst::EntityType getnstTypeFromExtension(const QString &ext);
49 
56  static Qnst::EntityType getnstTypeFromStr(const QString &strType);
57 
66  static QString getStrFromNstType(Qnst::EntityType type);
67 
74  static QString getPrefixIdFromType(Qnst::EntityType type);
75 
83  static Qnst::BindType getBindTypeFromStr(const QString &role);
84 
92  static QString getStrFromBindType(Qnst::BindType type);
93 
94 private:
95  static std::map <Qnst::EntityType, QString> iconFromTypeMap;
96  static std::map <QString, Qnst::EntityType> typeFromExtMap;
97  static std::map <QString, Qnst::EntityType> typeFromStr;
98  static std::map <Qnst::EntityType, QString> strFromType;
99  static std::map <Qnst::EntityType, QString> prefixIdFromType;
100  static std::map <QString, Qnst::BindType> bindTypeFromRoleStr;
101  static std::map <Qnst::BindType, QString> strFromBindType;
102 };
103 
107 template <typename T, typename U>
109 {
110 private:
111  std::map<T, U> m_map;
112 
113 public:
114  create_map(const T& key, const U& val)
115  {
116  m_map[key] = val;
117  }
118 
119  create_map<T, U>& operator()(const T& key, const U& val)
120  {
121  m_map[key] = val;
122  return *this;
123  }
124 
125  operator std::map<T, U>()
126  {
127  return m_map;
128  }
129 };
130 
134 template<typename K, typename V>
135 std::pair<V, K> flip_pair(const std::pair<K, V>& p)
136 {
137  return std::make_pair(p.second, p.first);
138 }
139 
144 template <typename K, typename V>
145 std::map <K, V> invert_map (const std::map <V, K> &in)
146 {
147  std::map<K, V> out;
148  std::transform(in.begin(), in.end(),
149  std::inserter(out, out.begin()),
150  flip_pair<V, K>);
151  return out;
152 }
153 
154 #endif