THRIFT-1275. cpp: always prefix namespaces with ' ::'

Ensures no accidental namespace clashes.

Patch: Adam Simpkins

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1159729 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bryan Duxbury 2011-08-19 18:23:39 +00:00
parent 887ff756cb
commit 0b7eeb5975

View File

@ -3737,10 +3737,17 @@ void t_cpp_generator::generate_serialize_list_element(ofstream& out,
* @return Namespaces
*/
string t_cpp_generator::namespace_prefix(string ns) {
// Always start with "::", to avoid possible name collisions with
// other names in one of the current namespaces.
//
// We also need a leading space, in case the name is used inside of a
// template parameter. "MyTemplate<::foo::Bar>" is not valid C++,
// since "<:" is an alternative token for "[".
string result = " ::";
if (ns.size() == 0) {
return "";
return result;
}
string result = "";
string::size_type loc;
while ((loc = ns.find(".")) != string::npos) {
result += ns.substr(0, loc);