From 2b9ebd770d39c15cc654c8dd4e9b0c563e7186bb Mon Sep 17 00:00:00 2001 From: Philippe Canal <pcanal@fnal.gov> Date: Fri, 3 Apr 2009 19:52:28 +0000 Subject: [PATCH] From Axel: Implement TClassEdit::InsertStd() is requested at Savannah 46871: it puts "std::" in front of all STL classes. git-svn-id: http://root.cern.ch/svn/root/trunk@28095 27541ba8-7e3a-0410-8455-c3a389f83636 --- core/metautils/inc/TClassEdit.h | 1 + core/metautils/src/TClassEdit.cxx | 175 ++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) diff --git a/core/metautils/inc/TClassEdit.h b/core/metautils/inc/TClassEdit.h index 3108a2382bf..b29be653428 100644 --- a/core/metautils/inc/TClassEdit.h +++ b/core/metautils/inc/TClassEdit.h @@ -68,6 +68,7 @@ namespace TClassEdit { int STLArgs (int kind); //Min number of arguments without allocator std::string ResolveTypedef(const char *tname, bool resolveAll = false); std::string ShortType (const char *typeDesc, int mode); + std::string InsertStd(const char *tname); } #endif diff --git a/core/metautils/src/TClassEdit.cxx b/core/metautils/src/TClassEdit.cxx index 589cbe3d938..4794c34d067 100644 --- a/core/metautils/src/TClassEdit.cxx +++ b/core/metautils/src/TClassEdit.cxx @@ -8,6 +8,7 @@ #include "TClassEdit.h" #include <ctype.h> #include "Rstrstream.h" +#include <set> // CINT's API. #ifndef R__BUILDING_CINT7 @@ -713,4 +714,178 @@ string TClassEdit::ResolveTypedef(const char *tname, bool resolveAll) } +//______________________________________________________________________________ +string TClassEdit::InsertStd(const char *tname) +{ + + // Return the name of type 'tname' with all STL classes prepended by "std::". + // For example for "vector<set<auto_ptr<int*> > >" it returns + // "std::vector<std::set<std::auto_ptr<int*> > >" + // + + static const char* sSTLtypes[] = { + "allocator", + "auto_ptr", + "bad_alloc", + "bad_cast", + "bad_exception", + "bad_typeid", + "basic_filebuf", + "basic_fstream", + "basic_ifstream", + "basic_ios", + "basic_iostream", + "basic_istream", + "basic_istringstream", + "basic_ofstream", + "basic_ostream", + "basic_ostringstream", + "basic_streambuf", + "basic_string", + "basic_stringbuf", + "basic_stringstream", + "binary_function", + "binary_negate", + "bitset", + "char_traits", + "codecvt_byname", + "codecvt", + "collate", + "collate_byname", + "compare", + "complex", + "ctype_byname", + "ctype", + "deque", + "divides", + "domain_error", + "equal_to", + "exception", + "fpos", + "greater_equal", + "greater", + "gslice_array", + "gslice", + "indirect_array", + "invalid_argument", + "ios_base", + "istream_iterator", + "istreambuf_iterator", + "istrstream", + "iterator_traits", + "iterator", + "length_error", + "less_equal", + "less", + "list", + "locale", + "localedef utility", + "locale utility", + "logic_error", + "logical_and", + "logical_not", + "logical_or", + "map", + "mask_array", + "mem_fun", + "mem_fun_ref", + "messages", + "messages_byname", + "minus", + "modulus", + "money_get", + "money_put", + "moneypunct", + "moneypunct_byname", + "multimap", + "multiplies", + "multiset", + "negate", + "not_equal_to", + "num_get", + "num_put", + "numeric_limits", + "numpunct", + "numpunct_byname", + "ostream_iterator", + "ostreambuf_iterator", + "ostrstream", + "out_of_range", + "overflow_error", + "pair", + "plus", + "pointer_to_binary_function", + "pointer_to_unary_function", + "priority_queue", + "queue", + "range_error", + "raw_storage_iterator", + "reverse_iterator", + "runtime_error", + "set", + "slice_array", + "slice", + "stack", + "string", + "strstream", + "strstreambuf", + "time_get_byname", + "time_get", + "time_put_byname", + "time_put", + "unary_function", + "unary_negate", + "underflow_error", + "valarray", + "vector", + "wstring" + }; + static set<string> sSetSTLtypes; + + if ( tname==0 || tname[0]==0) return tname; + + if (sSetSTLtypes.empty()) { + // set up static set + const size_t nSTLtypes = sizeof(sSTLtypes) / sizeof(const char*); + for (size_t i = 0; i < nSTLtypes; ++i) + sSetSTLtypes.insert(sSTLtypes[i]); + } + + size_t b = 0; + size_t len = strlen(tname); + string ret; + ret.reserve(len + 20); // expect up to 4 extra "std::" to insert + string id; + while (b < len) { + // find beginning of next identifier + bool precScope = false; // whether the identifier was preceded by "::" + while (!(isalnum(tname[b]) || tname[b] == '_') && b < len) { + precScope = (b < len - 2) && (tname[b] == ':') && (tname[b + 1] == ':'); + if (precScope) { + ret += "::"; + b += 2; + } else + ret += tname[b++]; + } + + // now b is at the beginning of an identifier or len + size_t e = b; + // find end of identifier + id.clear(); + while (e < len && (isalnum(tname[e]) || tname[e] == '_')) + id += tname[e++]; + if (!id.empty()) { + if (!precScope) { + set<string>::const_iterator iSTLtype = sSetSTLtypes.find(id); + if (iSTLtype != sSetSTLtypes.end()) + ret += "std::"; + } + + ret += id; + b = e; + } + } + return ret; +} + -- GitLab