00001
00002
00011 #ifndef CXXUTILS_CLASSNAME_H
00012 #define CXXUTILS_CLASSNAME_H
00013
00014
00015 #include <string>
00016 #include <vector>
00017 #include <map>
00018 #include <stdexcept>
00019
00020
00021 namespace CxxUtils {
00022
00023
00097 class ClassName
00098 {
00099 public:
00100
00104 class ExcBadClassName
00105 : public std::runtime_error
00106 {
00107 public:
00108 ExcBadClassName (const std::string& name);
00109 };
00110
00111
00115 class ExcMissingVariable
00116 : public std::runtime_error
00117 {
00118 public:
00119 ExcMissingVariable (const std::string& var);
00120 };
00121
00122
00126 class Rules
00127 {
00128 public:
00132 size_t size() const;
00133
00134
00145 void add (const ClassName& pattern, const ClassName& replacement);
00146
00147
00148 #if __cplusplus > 201100
00149
00159 void add (ClassName&& pattern, ClassName&& replacement);
00160 #endif
00161
00162
00174 bool applyTo (ClassName& cn) const;
00175
00176
00185 std::string apply (const std::string& name) const;
00186
00187
00188 private:
00190 typedef std::pair<ClassName, ClassName> pat_repl_t;
00191
00193 typedef std::multimap<std::string, pat_repl_t> rulemap_t;
00194 rulemap_t m_rules;
00195 };
00196
00197
00199 typedef std::map<std::string, ClassName> match_t;
00200
00201
00207 ClassName ();
00208
00209
00216 ClassName (const char* name);
00217
00218
00225 ClassName (const std::string& name);
00226
00227
00235 ClassName (const std::string& name, std::string::size_type& pos);
00236
00237
00242 void swap (ClassName& other);
00243
00244
00248 void setConst();
00249
00250
00256 std::string name() const;
00257
00258
00264 std::string qualifiedName() const;
00265
00266
00270 std::string fullName() const;
00271
00272
00276 bool operator== (const ClassName& other) const;
00277
00278
00282 bool operator!= (const ClassName& other) const;
00283
00284
00295 bool match (const ClassName& pattern, match_t& matches) const;
00296
00297
00309 void subst (const match_t& matches);
00310
00311
00323 ClassName substCopy (const match_t& matches) const;
00324
00325
00338 void applyRules (const Rules& rules);
00339
00340
00354 static std::string applyRules (const std::string& name,
00355 const Rules& rules);
00356
00357
00358 private:
00367 void parse (const std::string& name, std::string::size_type& pos);
00368
00369
00381 std::string parsePrimary (const std::string& name,
00382 std::string::size_type& pos);
00383
00384
00398 void parseNamespace (const std::string& name, std::string::size_type& pos);
00399
00400
00413 void parseTemplateArgs (const std::string& name, std::string::size_type& pos);
00414
00415
00424 void skipSpaces (const std::string& name, std::string::size_type& pos);
00425
00426
00437 bool match1 (const ClassName& pattern, match_t& matches) const;
00438
00439
00450 bool applyRules1 (const Rules& rules);
00451
00452
00454 bool m_const;
00455
00460 std::vector<ClassName> m_namespace;
00461
00463 std::string m_name;
00464
00466 std::vector<ClassName> m_targs;
00467 };
00468
00469
00470 }
00471
00472
00473 #endif // not CXXUTILS_CLASSNAME_H