Refactor ReplaceAll 47/269447/7
authorjh9216.park <jh9216.park@samsung.com>
Fri, 14 Jan 2022 08:37:26 +0000 (03:37 -0500)
committerjh9216.park <jh9216.park@samsung.com>
Mon, 17 Jan 2022 06:23:17 +0000 (01:23 -0500)
Change-Id: I9591411f238d09315f8aeb201d31869ebbf2de23
Signed-off-by: jh9216.park <jh9216.park@samsung.com>
23 files changed:
idlc/gen/c_body_gen_base.cc
idlc/gen/c_header_gen_base.cc
idlc/gen/c_proxy_body_gen.cc
idlc/gen/c_proxy_header_gen.cc
idlc/gen/c_stub_body_gen.cc
idlc/gen/c_stub_header_gen.cc
idlc/gen/cpp_gen_base.cc
idlc/gen/cpp_gen_base_cb.h
idlc/gen/cpp_stub_body_gen.cc
idlc/gen/generator.cc
idlc/gen/generator.h
idlc/gen/replace_all.cc [new file with mode: 0644]
idlc/gen/replace_all.h [new file with mode: 0755]
idlc/gen_cion/c_cion_body_gen_base.cc
idlc/gen_cion/c_cion_group_body_gen.cc
idlc/gen_cion/c_cion_group_header_gen.cc
idlc/gen_cion/c_cion_header_gen_base.cc
idlc/gen_cion/c_cion_proxy_body_gen.cc
idlc/gen_cion/c_cion_proxy_header_gen.cc
idlc/gen_cion/c_cion_stub_body_gen.cc
idlc/gen_cion/c_cion_stub_header_gen.cc
idlc/gen_cion/cpp_cion_gen_base.cc
idlc/gen_cion/cpp_cion_gen_base_cb.h

index 929c7ce..9acddc5 100644 (file)
@@ -79,8 +79,7 @@ void CBodyGeneratorBase::GenIncludeHeader(std::ofstream& stream) {
 
 void CBodyGeneratorBase::GenLogTag(std::ofstream& stream,
     const std::string& log_tag) {
-  std::string code = ReplaceAll(CB_LOG_TAG, "<LOG_TAG>", log_tag);
-  stream << code;
+  ReplaceAll(CB_LOG_TAG, "<LOG_TAG>", log_tag).Out(stream);
 }
 
 void CBodyGeneratorBase::GenLogDefinition(std::ofstream& stream) {
@@ -88,7 +87,7 @@ void CBodyGeneratorBase::GenLogDefinition(std::ofstream& stream) {
 }
 
 void CBodyGeneratorBase::GenVersionDefinition(std::ofstream& stream) {
-  stream << ReplaceAll(CB_VERSION_DEF, "<VERSION>", FULLVER);
+  ReplaceAll(CB_VERSION_DEF, "<VERSION>", FULLVER).Out(stream);
 }
 
 void CBodyGeneratorBase::GenBaseDefinition(std::ofstream& stream) {
@@ -126,37 +125,43 @@ void CBodyGeneratorBase::GenStructureArrayDef(std::ofstream& stream,
   auto& type = elm->GetType();
   auto element_type = GetDataTypeString(type, false);
 
-  std::string code = ReplaceAll(CB_STRUCTURE_ARRAY_DEF, {
+  ReplaceAll(CB_STRUCTURE_ARRAY_DEF, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", st.GetID() },
       { "<ELEMENT_TYPE>", element_type }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_STRUCTURE_LIST_DEF
 void CBodyGeneratorBase::GenStructureListDef(std::ofstream& stream,
     const Structure& st) {
-  std::string code = ReplaceAll(CB_STRUCTURE_LIST_DEF, {
+  ReplaceAll(CB_STRUCTURE_LIST_DEF, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", st.GetID() }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_STRUCTURE_BASE_DEF
 void CBodyGeneratorBase::GenStructureBaseDef(std::ofstream& stream,
     const Structure& st) {
   auto& elms = st.GetElements();
-  std::string code = ReplaceAll(CB_STRUCTURE_BASE_DEF, {
+  ReplaceAll(CB_STRUCTURE_BASE_DEF, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", st.GetID() },
       { "<ELEMENTS>", GenBaseElements(elms) }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 void CBodyGeneratorBase::GenStructures(std::ofstream& stream) {
@@ -269,7 +274,7 @@ void CBodyGeneratorBase::GenStructureArrayBase(std::ofstream& stream,
   auto element_type_size = GetDataTypeString(type, false);
   element_type_size = RemoveLastSpaces(element_type_size);
 
-  std::string code = ReplaceAll(CB_STRUCTURE_ARRAY_BASE, {
+  ReplaceAll(CB_STRUCTURE_ARRAY_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", st.GetID() },
       { "<PARCEL_WRITE>", GenArrayParcelWrite(elm) },
@@ -279,9 +284,11 @@ void CBodyGeneratorBase::GenStructureArrayBase(std::ofstream& stream,
       { "<ELEMENT_TYPE>", element_type },
       { "<ELEMENT_TYPE_SIZE>", element_type_size },
       { "<ELEMENTS_FREE>", GenArrayElementsFree(elm) }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_STRUCTURE_LIST_USER_DEFINED_FREE
@@ -413,7 +420,7 @@ void CBodyGeneratorBase::GenStructureListBase(std::ofstream& stream,
   auto& type = elm->GetType();
   auto param_type = GetParamTypeString(ParameterType::Direction::IN, type);
 
-  std::string code = ReplaceAll(CB_STRUCTURE_LIST_BASE, {
+  ReplaceAll(CB_STRUCTURE_LIST_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", st.GetID() },
       { "<DATA_TYPE>", GetDataTypeString(type, true) },
@@ -423,9 +430,11 @@ void CBodyGeneratorBase::GenStructureListBase(std::ofstream& stream,
       { "<PARCEL_READ>", GenListParcelRead(elm) },
       { "<LIST_ADD>", GenListAdd(elm) },
       { "<CALLBACK_PARAM_TYPE>", GenListCallbackParamType(elm) }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 std::string CBodyGeneratorBase::GenBaseElements(const Elements& elms) {
@@ -620,7 +629,7 @@ std::string CBodyGeneratorBase::GenBaseSetGet(const std::string& name,
     auto param_type_out = GetParamTypeString(ParameterType::Direction::OUT,
         type);
 
-    std::string set_get_code = ReplaceAll(CB_STRUCTURE_BASE_SET_GET, {
+    std::string set_get_code(ReplaceAll(CB_STRUCTURE_BASE_SET_GET, {
         { "<PREFIX>", GetHandlePrefix() },
         { "<NAME>", name },
         { "<ELEMENT_NAME>", elm->GetID() },
@@ -628,7 +637,7 @@ std::string CBodyGeneratorBase::GenBaseSetGet(const std::string& name,
         { "<PARAM_TYPE_OUT>", param_type_out },
         { "<BASE_SET>", GenBaseSet(elm) },
         { "<BASE_GET>", GenBaseGet(elm) }
-    });
+    }));
 
     code += set_get_code;
   }
@@ -641,16 +650,18 @@ void CBodyGeneratorBase::GenStructureBase(std::ofstream& stream,
     const Structure& st) {
   auto& elms = st.GetElements();
 
-  std::string code = ReplaceAll(CB_STRUCTURE_BASE, {
+  ReplaceAll(CB_STRUCTURE_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", st.GetID() },
       { "<ELEMENTS_FREE>", GenBaseElementsFree(elms) },
       { "<PARCEL_WRITE>", GenBaseParcelWrite(elms) },
       { "<PARCEL_READ>", GenBaseParcelRead(elms) }
-  });
-
-  code += GenBaseSetGet(st.GetID(), elms);
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string code) {
+    code += GenBaseSetGet(st.GetID(), elms);
+    return SmartIndent(code);
+  })
+  .Out(stream);
 }
 
 const std::string& CBodyGeneratorBase::GetParcelType(const BaseType& type) {
index 256d497..3d6c887 100644 (file)
@@ -101,12 +101,14 @@ void CHeaderGeneratorBase::GenStructures(std::ofstream& stream) {
 // @see #CB_STRUCTURE_HANDLE
 void CHeaderGeneratorBase::GenStructureHandle(std::ofstream& stream,
     const Structure& st) {
-  std::string str = ReplaceAll(CB_STRUCTURE_HANDLE, {
+  ReplaceAll(CB_STRUCTURE_HANDLE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", st.GetID() }
-  });
-
-  stream << SmartIndent(str);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_STRUCTURE_ARRAY_BASE
@@ -117,14 +119,16 @@ void CHeaderGeneratorBase::GenStructureArrayBase(std::ofstream& stream,
   auto param_type_in = GetParamTypeString(ParameterType::Direction::IN, type);
   auto param_type_out = GetParamTypeString(ParameterType::Direction::OUT, type);
 
-  std::string str = ReplaceAll(CB_STRUCTURE_ARRAY_BASE, {
+  ReplaceAll(CB_STRUCTURE_ARRAY_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", st.GetID() },
       { "<PARAM_TYPE_IN>", param_type_in },
       { "<PARAM_TYPE_OUT>", param_type_out }
-  });
-
-  stream << SmartIndent(str);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_STRUCTURE_LIST_BASE
@@ -134,37 +138,45 @@ void CHeaderGeneratorBase::GenStructureListBase(std::ofstream& stream,
   auto& type = elm->GetType();
   auto param_type = GetParamTypeString(ParameterType::Direction::IN, type);
 
-  std::string str = ReplaceAll(CB_STRUCTURE_LIST_BASE, {
+  ReplaceAll(CB_STRUCTURE_LIST_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", st.GetID() },
       { "<PARAM_TYPE_IN>", param_type }
-  });
-
-  stream << SmartIndent(str);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_STRUCTURE_BASE
 void CHeaderGeneratorBase::GenStructureBase(std::ofstream& stream,
     const Structure& st) {
-  std::string str = ReplaceAll(CB_STRUCTURE_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  str = ReplaceAll(str, "<NAME>", st.GetID());
-  stream << SmartIndent(str);
+  ReplaceAll(CB_STRUCTURE_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", st.GetID() }
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 
   for (const auto& e : st.GetElements()) {
     auto& type = e->GetType();
     auto param_type_in = GetParamTypeString(ParameterType::Direction::IN, type);
     auto param_type_out = GetParamTypeString(ParameterType::Direction::OUT, type);
 
-    str = ReplaceAll(CB_STRUCTURE_BASE_SET_GET, {
+    ReplaceAll(CB_STRUCTURE_BASE_SET_GET, {
         { "<PREFIX>", GetHandlePrefix() },
         { "<NAME>", st.GetID() },
         { "<PARAM_TYPE_IN>", param_type_in },
         { "<PARAM_TYPE_OUT>", param_type_out },
         { "<ELEMENT_NAME>", e->GetID() }
-    });
-
-    stream << SmartIndent(str);
+    })
+    .Transform([&](std::string str) {
+      return SmartIndent(str);
+    })
+    .Out(stream);
   }
 }
 
index c4a3fa6..1efe1f4 100644 (file)
@@ -76,24 +76,28 @@ void CProxyBodyGen::GenInterfaceDef(std::ofstream& stream,
 // @see #CB_INTERFACE_DELEGATE_DEF
 void CProxyBodyGen::GenInterfaceDelegateDef(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_DEF, {
+  ReplaceAll(CB_INTERFACE_DELEGATE_DEF, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<DELEGATE_NAME>", decl.GetID() }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_INTERFACE_BASE_DEF
 void CProxyBodyGen::GenInterfaceBaseDef(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE_DEF, {
+  ReplaceAll(CB_INTERFACE_BASE_DEF, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 void CProxyBodyGen::GenInterfaces(std::ofstream& stream) {
@@ -133,15 +137,17 @@ void CProxyBodyGen::GenInterface(std::ofstream& stream,
 void CProxyBodyGen::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
   std::string prefix = GetHandlePrefix();
-  std::string code = ReplaceAll(CB_INTERFACE_BASE, "<PREFIX>", prefix);
   std::string name = iface.GetID();
-  code = ReplaceAll(code, "<NAME>", name);
-  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_PREFIX>", prefix);
-  std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
 
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_BASE)
+      .Change("<PREFIX>", prefix)
+      .Change("<NAME>", name)
+      .ChangeToUpper("<UPPERCASE_PREFIX>", prefix)
+      .ChangeToUpper("<UPPERCASE_NAME>", name)
+      .Transform([&](std::string code) {
+        return SmartIndent(code);
+      })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_DELEGATE_ENUM_BASE
@@ -162,13 +168,15 @@ void CProxyBodyGen::GenInterfaceDelegateEnumBase(std::ofstream& stream,
     return;
 
   std::transform(enums.begin(), enums.end(), enums.begin(), ::toupper);
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_ENUM_BASE, {
+  ReplaceAll(CB_INTERFACE_DELEGATE_ENUM_BASE, {
       { "<ENUMS>", enums },
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 std::string CProxyBodyGen::GenDelegateArgsDecl(const Interface& iface,
@@ -280,7 +288,7 @@ void CProxyBodyGen::GenInterfaceDelegateBase(std::ofstream& stream,
   bool has_free = false;
   std::string delegate_args_free = GenDelegateArgsFree(iface, decl, has_free);
 
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
+  ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<DELEGATE_NAME>", decl.GetID() },
@@ -290,9 +298,11 @@ void CProxyBodyGen::GenInterfaceDelegateBase(std::ofstream& stream,
       { "<DELEGATE_ARGS_FREE>", delegate_args_free },
       { "<DELEGATE_CALLBACK_ARGS>", GenDelegateCallbackArgs(decl) },
       { "<GOTO_STATEMENT>", has_free ? "out:" + NLine(1) : "" }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_INTERFACE_DELEGATE_TABLE
@@ -308,12 +318,12 @@ void CProxyBodyGen::GenInterfaceDelegateTable(std::ofstream& stream,
         "_DELEGATE_" + d->GetID();
     std::transform(enum_value.begin(), enum_value.end(), enum_value.begin(),
         ::toupper);
-    std::string member = ReplaceAll(CB_INTERFACE_DELEGATE_TABLE_MEMBER, {
+    std::string member(ReplaceAll(CB_INTERFACE_DELEGATE_TABLE_MEMBER, {
         { "<ENUM_VALUE>", enum_value },
         { "<PREFIX>", GetHandlePrefix() },
         { "<NAME>", iface.GetID() },
         { "<DELEGATE_NAME>", d->GetID() }
-    });
+    }));
 
     member = RemoveLine(member);
     delegate_handlers += member;
@@ -322,13 +332,15 @@ void CProxyBodyGen::GenInterfaceDelegateTable(std::ofstream& stream,
   if (delegate_handlers.empty())
     delegate_handlers = "nullptr," + NLine(1);
 
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_TABLE, {
+  ReplaceAll(CB_INTERFACE_DELEGATE_TABLE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<DELEGATE_HANDLERS>", delegate_handlers }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_INTERFACE_METHOD_ENUM_BASE
@@ -351,13 +363,15 @@ void CProxyBodyGen::GenInterfaceMethodEnumBase(std::ofstream& stream,
   }
 
   std::transform(enums.begin(), enums.end(), enums.begin(), ::toupper);
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, {
+  ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, {
       { "<ENUMS>", enums },
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str) {
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 std::string CProxyBodyGen::GenMethodParams(const Interface& iface,
@@ -452,8 +466,8 @@ std::string CProxyBodyGen::GenMethodDelegateAppend(const Interface& iface,
     auto& param_type = p->GetParameterType();
     auto& type = param_type.GetBaseType();
     if (IsDelegateType(iface, type)) {
-      std::string delegate_append_code = ReplaceAll(
-          CB_INTERFACE_METHOD_DELEGATE_APPEND, "<ARG>", p->GetID());
+      std::string delegate_append_code(ReplaceAll(
+          CB_INTERFACE_METHOD_DELEGATE_APPEND, "<ARG>", p->GetID()));
       code += delegate_append_code;
     }
   }
@@ -465,27 +479,21 @@ std::string CProxyBodyGen::GenMethodDelegateAppend(const Interface& iface,
 std::string CProxyBodyGen::GenMethodAsyncBase(const Interface& iface,
     const Declaration& decl) {
   std::string prefix = GetHandlePrefix();
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_ASYNC_BASE, "<PREFIX>",
-      prefix);
   std::string name = iface.GetID();
-  code = ReplaceAll(code, "<NAME>", name);
   std::string method_name = decl.GetID();
-  code = ReplaceAll(code, "<METHOD_NAME>", method_name);
-  std::string args = GenMethodParams(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARAMS>", args);
-  std::string args_check = GenMethodParamsCheck(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARAMS_CHECK>", args_check);
-  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_PREFIX>", prefix);
-  std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
-  std::transform(method_name.begin(), method_name.end(), method_name.begin(),
-      ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_METHOD_NAME>", method_name);
-  std::string parcel_write = GenMethodParcelWrite(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARCEL_WRITE>", parcel_write);
-  std::string delegate_append = GenMethodDelegateAppend(iface, decl);
-  code = ReplaceAll(code, "<METHOD_DELEGATE_APPEND>", delegate_append);
+
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_ASYNC_BASE)
+      .Change("<PREFIX>", prefix)
+      .Change("<NAME>", name)
+      .Change("<METHOD_NAME>", method_name)
+      .Change("<METHOD_PARAMS>", GenMethodParams(iface, decl))
+      .Change("<METHOD_PARAMS_CHECK>", GenMethodParamsCheck(iface, decl))
+      .ChangeToUpper("<UPPERCASE_PREFIX>", prefix)
+      .ChangeToUpper("<UPPERCASE_NAME>", name)
+      .ChangeToUpper("<UPPERCASE_METHOD_NAME>", method_name)
+      .Change("<METHOD_PARCEL_WRITE>", GenMethodParcelWrite(iface, decl))
+      .Change("<METHOD_DELEGATE_APPEND>", GenMethodDelegateAppend(iface,
+          decl)));
   return code;
 }
 
@@ -563,35 +571,26 @@ std::string CProxyBodyGen::GenMethodParcelRead(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_BASE
 std::string CProxyBodyGen::GenMethodBase(const Interface& iface,
     const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_BASE, "<RETURN_TYPE>",
-      GetReturnTypeString(decl.GetType()));
   std::string prefix = GetHandlePrefix();
-  code = ReplaceAll(code, "<PREFIX>", prefix);
   std::string name = iface.GetID();
-  code = ReplaceAll(code, "<NAME>", name);
   std::string method_name = decl.GetID();
-  code = ReplaceAll(code, "<METHOD_NAME>", method_name);
-  std::string args = GenMethodParams(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARAMS>", args);
-  std::string values = GenMethodArgs(iface, decl);
-  code = ReplaceAll(code, "<METHOD_ARGS>", values);
-  std::string error_value = GetErrorValue(decl.GetType());
-  code = ReplaceAll(code, "<ERROR_VALUE>", error_value);
-  std::string args_check = GenMethodParamsCheck(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARAMS_CHECK>", args_check);
-  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_PREFIX>", prefix);
-  std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
-  std::transform(method_name.begin(), method_name.end(), method_name.begin(),
-      ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_METHOD_NAME>", method_name);
-  std::string parcel_write = GenMethodParcelWrite(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARCEL_WRITE>", parcel_write);
-  std::string parcel_read = GenMethodParcelRead(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARCEL_READ>", parcel_read);
-  std::string delegate_append = GenMethodDelegateAppend(iface, decl);
-  code = ReplaceAll(code, "<METHOD_DELEGATE_APPEND>", delegate_append);
+
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_BASE)
+      .Change("<RETURN_TYPE>", GetReturnTypeString(decl.GetType()))
+      .Change("<PREFIX>", prefix)
+      .Change("<NAME>", name)
+      .Change("<METHOD_NAME>", method_name)
+      .Change("<METHOD_PARAMS>", GenMethodParams(iface, decl))
+      .Change("<METHOD_ARGS>", GenMethodArgs(iface, decl))
+      .Change("<ERROR_VALUE>", GetErrorValue(decl.GetType()))
+      .Change("<METHOD_PARAMS_CHECK>", GenMethodParamsCheck(iface, decl))
+      .ChangeToUpper("<UPPERCASE_PREFIX>", prefix)
+      .ChangeToUpper("<UPPERCASE_NAME>", name)
+      .ChangeToUpper("<UPPERCASE_METHOD_NAME>", method_name)
+      .Change("<METHOD_PARCEL_WRITE>", GenMethodParcelWrite(iface, decl))
+      .Change("<METHOD_PARCEL_READ>", GenMethodParcelRead(iface, decl))
+      .Change("<METHOD_DELEGATE_APPEND>", GenMethodDelegateAppend(iface,
+          decl)));
   return code;
 }
 
index 5be03de..3668a44 100644 (file)
@@ -60,10 +60,10 @@ void CProxyHeaderGen::GenInterfaceHandles(std::ofstream& stream) {
 // @see #CB_INTERFACE_HANDLE
 void CProxyHeaderGen::GenInterfaceHandle(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_HANDLE, {
+  std::string code(ReplaceAll(CB_INTERFACE_HANDLE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -71,11 +71,11 @@ void CProxyHeaderGen::GenInterfaceHandle(std::ofstream& stream,
 // @see #CB_INTERFACE_DELEGATE_HANDLE
 void CProxyHeaderGen::GenInterfaceDelegateHandle(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE, {
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<DELEGATE_NAME>", decl.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -112,10 +112,10 @@ void CProxyHeaderGen::GenInterface(std::ofstream& stream,
 // @see #CB_INTERFACE_BASE
 void CProxyHeaderGen::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -137,12 +137,12 @@ std::string CProxyHeaderGen::GenDelegateParams(const Interface& iface,
 // @see #CB_INTERFACE_DELEGATE_BASE
 void CProxyHeaderGen::GenInterfaceDelegateBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<DELEGATE_NAME>", decl.GetID() },
       { "<DELEGATE_PARAMS>", GenDelegateParams(iface, decl) }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -164,13 +164,13 @@ std::string CProxyHeaderGen::GenMethodParams(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_BASE
 void CProxyHeaderGen::GenInterfaceMethodBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_BASE, {
       { "<RETURN_TYPE>", GetReturnTypeString(decl.GetType()) },
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<METHOD_NAME>", decl.GetID() },
       { "<METHOD_PARAMS>", GenMethodParams(iface, decl) }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
index 28ad801..367670e 100644 (file)
@@ -79,11 +79,11 @@ void CStubBodyGen::GenInterfaceEnum(std::ofstream& stream,
 
 // @see #CB_INTERFACE_METHOD_ENUM
 std::string CStubBodyGen::GenMethodEnums(const Interface& iface) {
-  std::string method_enum = ReplaceAll(CB_INTERFACE_METHOD_ENUM, {
+  std::string method_enum(ReplaceAll(CB_INTERFACE_METHOD_ENUM, {
       { "<UPPERCASE_PREFIX>", GetHandlePrefix() },
       { "<UPPERCASE_NAME>", iface.GetID() },
       { "<UPPERCASE_METHOD_NAME>", "RESULT_" }
-  });
+  }));
 
   std::string method_enums = RemoveLine(method_enum);
 
@@ -116,11 +116,11 @@ std::string CStubBodyGen::GenMethodEnums(const Interface& iface) {
 // @see #CB_INTERFACE_METHOD_ENUM_BASE
 void CStubBodyGen::GenInterfaceMethodEnumBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<METHOD_ENUMS>", GenMethodEnums(iface) }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -133,12 +133,12 @@ std::string CStubBodyGen::GenDelegateEnums(const Interface& iface) {
     if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
       continue;
 
-    std::string method_enum = ReplaceAll(CB_INTERFACE_DELEGATE_ENUM, {
+    std::string method_enum(ReplaceAll(CB_INTERFACE_DELEGATE_ENUM, {
         { "<UPPERCASE_PREFIX>", GetHandlePrefix() },
         { "<UPPERCASE_NAME>", iface.GetID() },
         { "<UPPERCASE_DELEGATE_NAME>", d->GetID() },
         { "<NUMBER>", std::to_string(num++) }
-    });
+    }));
 
     method_enums += RemoveLine(method_enum);
   }
@@ -155,11 +155,11 @@ void CStubBodyGen::GenInterfaceDelegateEnumBase(std::ofstream& stream,
   if (delegate_enums.empty())
     return;
 
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_ENUM_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_ENUM_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<DELEGATE_ENUMS>", delegate_enums }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -195,11 +195,11 @@ void CStubBodyGen::GenInterfaceDef(std::ofstream& stream,
 // @see #CB_INTERFACE_DELEGATE_DEF
 void CStubBodyGen::GenInterfaceDelegateDef(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_DEF, {
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_DEF, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<DELEGATE_NAME>", decl.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -207,10 +207,10 @@ void CStubBodyGen::GenInterfaceDelegateDef(std::ofstream& stream,
 // @see #CB_INTERFACE_CALLBACK_PORT_CHECK_DEF
 void CStubBodyGen::GenInterfaceCallbackPortCheckDef(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK_DEF, {
+  std::string code(ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK_DEF, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -218,10 +218,10 @@ void CStubBodyGen::GenInterfaceCallbackPortCheckDef(std::ofstream& stream,
 // @see #CB_INTERFACE_CONTEXT_DEF
 void CStubBodyGen::GenInterfaceContextDef(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_CONTEXT_DEF, {
+  std::string code(ReplaceAll(CB_INTERFACE_CONTEXT_DEF, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -229,10 +229,10 @@ void CStubBodyGen::GenInterfaceContextDef(std::ofstream& stream,
 // @see #CB_INTERFACE_BASE_DEF
 void CStubBodyGen::GenInterfaceBaseDef(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE_DEF, {
+  std::string code(ReplaceAll(CB_INTERFACE_BASE_DEF, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -276,10 +276,10 @@ void CStubBodyGen::GenInterface(std::ofstream& stream, const Interface& iface) {
 // @see #CB_INTERFACE_CONTEXT_BASE
 void CStubBodyGen::GenInterfaceContextBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_CONTEXT_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_CONTEXT_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -368,7 +368,7 @@ void CStubBodyGen::GenInterfaceDelegateBase(std::ofstream& stream,
   std::transform(enum_value.begin(), enum_value.end(), enum_value.begin(),
       ::toupper);
 
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<DELEGATE_NAME>", decl.GetID() },
@@ -376,7 +376,7 @@ void CStubBodyGen::GenInterfaceDelegateBase(std::ofstream& stream,
       { "<DELEGATE_PARAMS_CHECK>", GenDelegateParamsCheck(iface, decl) },
       { "<DELEGATE_ENUM_VALUE>", enum_value },
       { "<DELEGATE_PARCEL_WRITE>", GenDelegateParcelWrite(iface, decl) }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -452,8 +452,8 @@ std::string CStubBodyGen::GenMethodHandlerParcelRead(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_CALLBACK_INVOKE
 std::string CStubBodyGen::GenMethodHandlerCallbackInvoke(
     const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_INVOKE,
-      "<METHOD_NAME>", decl.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_INVOKE,
+      "<METHOD_NAME>", decl.GetID()));
 
   if (decl.GetMethodType() == Declaration::MethodType::SYNC)
     code = ReplaceAll(code, "<RES_SET>", "res_ = ");
@@ -623,7 +623,7 @@ std::string CStubBodyGen::GenMethodHandlerArgsFree(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_HANDLER_BASE
 void CStubBodyGen::GenInterfaceMethodHandlerBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_HANDLER_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_HANDLER_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<METHOD_NAME>", decl.GetID() },
@@ -635,7 +635,7 @@ void CStubBodyGen::GenInterfaceMethodHandlerBase(std::ofstream& stream,
       { "<METHOD_HANDLER_PARCEL_WRITE>",
           GenMethodHandlerParcelWrite(iface, decl) },
       { "<METHOD_HANDLER_ARGS_FREE>", GenMethodHandlerArgsFree(iface, decl) }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -651,12 +651,12 @@ std::string CStubBodyGen::GenMethodHandlers(const Interface& iface) {
       "_METHOD_" + d->GetID();
     std::transform(enum_value.begin(), enum_value.end(), enum_value.begin(),
         ::toupper);
-    std::string method_handler = ReplaceAll(CB_INTERFACE_METHOD_HANDLER, {
+    std::string method_handler(ReplaceAll(CB_INTERFACE_METHOD_HANDLER, {
         { "<ENUM_VALUE>", enum_value },
         { "<PREFIX>", GetHandlePrefix() },
         { "<NAME>", iface.GetID() },
         { "<METHOD_NAME>", d->GetID() }
-    });
+    }));
 
     code += RemoveLine(method_handler);
   }
@@ -667,10 +667,10 @@ std::string CStubBodyGen::GenMethodHandlers(const Interface& iface) {
 // @see #CB_INTERFACE_METHOD_TABLE
 void CStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_TABLE, {
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_TABLE, {
       { "<NAME>", iface.GetID() },
       { "<METHOD_HANDLERS>", GenMethodHandlers(iface) }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -678,10 +678,10 @@ void CStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream,
 // @see #CB_INTERFACE_CALLBACK_PORT_CHECK
 void CStubBodyGen::GenInterfaceCallbackPortCheck(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK, {
+  std::string code(ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -692,15 +692,15 @@ std::string CStubBodyGen::GenAccessControlSet(const Interface& iface) {
   std::string code;
   for (const auto& attr : iface.GetAttributes()) {
     if (attr->GetKey() == "privilege") {
-      std::string privilege_add = ReplaceAll(CB_INTERFACE_PRIVILEGE_ADD, {
+      std::string privilege_add(ReplaceAll(CB_INTERFACE_PRIVILEGE_ADD, {
           { "<NAME>", iface.GetID() },
           { "<PRIVILEGE>", attr->GetValue() }
-      });
+      }));
 
       code += privilege_add;
     } else if (attr->GetKey() == "trusted" && attr->GetValue() == "true") {
-      std::string trusted_set = ReplaceAll(CB_INTERFACE_TRUSTED_SET,
-          "<NAME>", iface.GetID());
+      std::string trusted_set(ReplaceAll(CB_INTERFACE_TRUSTED_SET,
+          "<NAME>", iface.GetID()));
 
       code += trusted_set;
     }
@@ -712,11 +712,11 @@ std::string CStubBodyGen::GenAccessControlSet(const Interface& iface) {
 // @see #CB_INTERFACE_BASE
 void CStubBodyGen::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<ACCESS_CONTROL_SET>", GenAccessControlSet(iface) }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
index 1b3543b..3177368 100644 (file)
@@ -60,10 +60,10 @@ void CStubHeaderGen::GenInterfaceHandles(std::ofstream& stream) {
 // @see #CB_INTERFACE_CONTEXT_HANDLE
 void CStubHeaderGen::GenInterfaceContextHandle(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_CONTEXT_HANDLE, {
+  std::string code(ReplaceAll(CB_INTERFACE_CONTEXT_HANDLE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -71,11 +71,11 @@ void CStubHeaderGen::GenInterfaceContextHandle(std::ofstream& stream,
 // @see #CB_INTERFACE_DELEGATE_HANDLE
 void CStubHeaderGen::GenInterfaceDelegateHandle(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE, {
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<DELEGATE_NAME>", decl.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -99,10 +99,10 @@ void CStubHeaderGen::GenInterfaceCallbacks(std::ofstream& stream) {
 // @see #CB_INTERFACE_CALLBACK_BASE
 void CStubHeaderGen::GenInterfaceCallbackBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_CALLBACK_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_CALLBACK_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -124,13 +124,13 @@ std::string CStubHeaderGen::GenMethodParams(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_CALLBACK_BASE
 void CStubHeaderGen::GenInterfaceMethodCallbackBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_BASE, {
       { "<RETURN_TYPE>", GetReturnTypeString(decl.GetType()) },
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<METHOD_NAME>", decl.GetID() },
       { "<METHOD_PARAMS>", GenMethodParams(iface, decl) }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -161,10 +161,10 @@ void CStubHeaderGen::GenInterface(std::ofstream& stream,
 // @see #CB_INTERFACE_CONTEXT_BASE
 void CStubHeaderGen::GenInterfaceContextBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_CONTEXT_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_CONTEXT_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -186,12 +186,12 @@ std::string CStubHeaderGen::GenDelegateParams(const Interface& iface,
 // @see #CB_INTERFACE_DELEGATE_BASE
 void CStubHeaderGen::GenInterfaceDelegateBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<DELEGATE_NAME>", decl.GetID() },
       { "<DELEGATE_PARAMS>", GenDelegateParams(iface, decl) }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
@@ -203,12 +203,12 @@ std::string CStubHeaderGen::GenMethodCallbackDecls(const Interface& iface) {
     if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
       continue;
 
-    std::string method_callback_decl = ReplaceAll(
+    std::string method_callback_decl(ReplaceAll(
         CB_INTERFACE_METHOD_CALLBACK_DECL, {
             { "<PREFIX>", GetHandlePrefix() },
             { "<NAME>", iface.GetID() },
             { "<METHOD_NAME>", d->GetID() }
-        });
+        }));
 
     method_callback_decl = RemoveLine(method_callback_decl);
     method_callback_decls += RemoveLine(method_callback_decl, 2);
@@ -220,11 +220,11 @@ std::string CStubHeaderGen::GenMethodCallbackDecls(const Interface& iface) {
 // @see #CB_INTERFACE_BASE
 void CStubHeaderGen::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE, {
+  std::string code(ReplaceAll(CB_INTERFACE_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<METHOD_CALLBACK_DECLS>", GenMethodCallbackDecls(iface) }
-  });
+  }));
 
   stream << SmartIndent(code);
 }
index ff15437..c0c5eaf 100644 (file)
@@ -712,16 +712,15 @@ void CppGeneratorBase::GenHeaderCallbacks(std::ofstream& stream,
 void CppGeneratorBase::GenHeaderCallback(std::ofstream& stream,
                                          const Declaration& decl,
                                          bool is_proxy) {
-  stream << GenTemplateString(CB_CALLBACK_CLASS,
-      [&]()->std::string {
-        return decl.GetID();
-      },
-      [&]()->std::string {
-        return ReplaceAll(
-            is_proxy ? CB_CALLBACK_CTOR_PROXY : CB_CALLBACK_CTOR_STUB,
-            "##", decl.GetID());
-      },
-      [&]()->std::string {
+  ReplaceAll(CB_CALLBACK_CLASS)
+      .Select("<CTOR>",
+          { CB_CALLBACK_CTOR_PROXY, CB_CALLBACK_CTOR_STUB }, [&]() {
+        if (is_proxy)
+          return 0;
+        return 1;
+      })
+      .Change("<CLS_NAME>", decl.GetID())
+      .Change("<PUBLIC_MEMBERS>", [&]() {
         std::string ret;
         if (is_proxy) {
           ret = Tab(2) + "virtual void OnReceived("
@@ -734,10 +733,11 @@ void CppGeneratorBase::GenHeaderCallback(std::ofstream& stream,
         }
 
         return ret;
-      },
-      [&]()->std::string {
+      })
+      .Change("<PRIVATE_MEMBERS>", [&]() {
         return is_proxy ? CB_CALLBACK_PRIVATE_PROXY : CB_CALLBACK_PRIVATE_STUB;
-      });
+      })
+      .Out(stream);
 }
 
 void CppGeneratorBase::GenVersion(std::ofstream& stream) {
index 84ef269..25b0994 100644 (file)
@@ -164,17 +164,17 @@ R"__cpp_cb(
 
 const char CB_CALLBACK_CLASS[] =
 R"__cpp_cb(
-  class $$ : public CallbackBase {
-   public:$$
-$$
-   private:$$
+  class <CLS_NAME> : public CallbackBase {
+   public:<CTOR>
+<PUBLIC_MEMBERS>
+   private:<PRIVATE_MEMBERS>
   };
 )__cpp_cb";
 
 const char CB_CALLBACK_CTOR_STUB[] =
 R"__cpp_cb(
-    ##(rpc_port_h port, std::weak_ptr<ServiceBase> service)
-        : CallbackBase(static_cast<int>(DelegateId::##), false) {
+    <CLS_NAME>(rpc_port_h port, std::weak_ptr<ServiceBase> service)
+        : CallbackBase(static_cast<int>(DelegateId::<CLS_NAME>), false) {
       port_ = port;
       service_ = std::move(service);
     }
@@ -182,8 +182,8 @@ R"__cpp_cb(
 
 const char CB_CALLBACK_CTOR_PROXY[] =
 R"__cpp_cb(
-    ##(bool once = false)
-        : CallbackBase(static_cast<int>(DelegateId::##), once) {}
+    <CLS_NAME>(bool once = false)
+        : CallbackBase(static_cast<int>(DelegateId::<CLS_NAME>), once) {}
 )__cpp_cb";
 
 const char CB_CALLBACK_PRIVATE_PROXY[] =
index 6082bed..455785d 100644 (file)
@@ -140,9 +140,8 @@ void CppStubBodyGen::GenReceivedEvent(std::ofstream& stream,
         return iface.GetID();
       });
   } else {
-    std::string code = ReplaceAll(CB_ON_RECEIVED_CB_FRONT, "[NAME]",
+    stream << ReplaceAll(CB_ON_RECEIVED_CB_FRONT, "[NAME]",
         iface.GetID());
-    stream << code;
   }
 
   for (const auto& i : iface.GetDeclarations()) {
@@ -159,10 +158,8 @@ void CppStubBodyGen::GenReceivedEvent(std::ofstream& stream,
 
   if (options_->IsThreadEnabled()) {
     stream << CB_RUN_PENDING_JOB_BACK << NLine(1);
-
-    std::string code = ReplaceAll(CB_ON_RECEIVED_CB, "[NAME]",
+    stream << ReplaceAll(CB_ON_RECEIVED_CB, "[NAME]",
         iface.GetID());
-    stream << code;
   } else {
     stream << CB_ON_RECEIVED_CB_BACK << NLine(1);
   }
index 9e541a0..896dbfc 100644 (file)
@@ -87,25 +87,6 @@ std::string Generator::GetFileNamespace() const {
   return FileName.substr(p1, p2 - p1);
 }
 
-std::string Generator::ReplaceAll(std::string str,
-                                  const std::string& from,
-                                  const std::string& to) {
-  std::size_t pos = 0;
-  while ((pos = str.find(from, pos)) != std::string::npos) {
-    str.replace(pos, from.length(), to);
-    pos += to.length();
-  }
-  return str;
-}
-
-std::string Generator::ReplaceAll(std::string str,
-    std::initializer_list<std::pair<std::string, std::string>> list) {
-  for (const auto& i : list)
-    str = ReplaceAll(str, i.first, i.second);
-
-  return str;
-}
-
 bool Generator::IsDelegateType(const BaseType& type) {
   for (auto& i : GetDocument().GetBlocks()) {
     if (i->GetType() != Block::TYPE_INTERFACE)
index cfdab3d..b3529ad 100755 (executable)
@@ -26,6 +26,7 @@
 #include "idlc/ast/document.h"
 #include "idlc/ast/parameter.h"
 #include "idlc/ast/type.h"
+#include "idlc/gen/replace_all.h"
 
 namespace tidl {
 
@@ -37,10 +38,6 @@ class Generator {
   void Run(const std::string& file_name, bool divide_interface = false);
   std::string AddIndent(int indent, std::string lines, bool space = true);
   std::string GetFileNamespace() const;
-  std::string ReplaceAll(std::string str,
-                         const std::string& from, const std::string& to);
-  std::string ReplaceAll(std::string str,
-      std::initializer_list<std::pair<std::string, std::string>> list);
   bool IsDelegateType(const Interface& inf, const BaseType& type);
   bool IsDelegateType(const BaseType& type);
 
@@ -135,21 +132,6 @@ class Generator {
   int type_ = 0;
 };
 
-class Inject {
- public:
-  template <class T>
-  explicit Inject(T t) {
-    str_ = t();
-  }
-
-  operator std::string() const {
-    return str_;
-  }
-
- private:
-  std::string str_;
-};
-
 }  // namespace tidl
 
 #endif  // IDLC_GENERATOR_H_
diff --git a/idlc/gen/replace_all.cc b/idlc/gen/replace_all.cc
new file mode 100644 (file)
index 0000000..a119b36
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <algorithm>
+
+#include "idlc/gen/replace_all.h"
+
+namespace tidl {
+
+ReplaceAll::ReplaceAll(std::string str) : str_(std::move(str)) {}
+
+ReplaceAll::ReplaceAll(std::string str, const std::string& from,
+    const std::string& to) : str_(std::move(str)) {
+  Change(from, to);
+}
+
+ReplaceAll::ReplaceAll(std::string str,
+    std::initializer_list<std::pair<std::string, std::string>> list)
+    : str_(std::move(str)) {
+  for (const auto& i : list)
+    Change(i.first, i.second);
+}
+
+ReplaceAll::operator const char*() const {
+  return str_.c_str();
+}
+
+ReplaceAll& ReplaceAll::Change(const std::string& from,
+    const std::string& to) {
+  std::size_t pos = 0;
+  while ((pos = str_.find(from, pos)) != std::string::npos) {
+    str_.replace(pos, from.length(), to);
+    pos += to.length();
+  }
+
+  return *this;
+}
+
+ReplaceAll& ReplaceAll::ChangeToUpper(const std::string& from,
+    const std::string& to) {
+  return Change(from, [to]() {
+    std::string t = to;
+    std::transform(t.begin(), t.end(), t.begin(), ::toupper);
+    return t;
+  });
+}
+
+ReplaceAll& ReplaceAll::Once(const std::string& from,
+    const std::string& to) {
+  std::size_t pos = 0;
+  if ((pos = str_.find(from, pos)) != std::string::npos) {
+    str_.replace(pos, from.length(), to);
+  }
+
+  return *this;
+}
+
+void ReplaceAll::Out(std::ofstream& stream) {
+  stream << str_;
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/replace_all.h b/idlc/gen/replace_all.h
new file mode 100755 (executable)
index 0000000..553760d
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_REPLACE_ALL_H_
+#define IDLC_REPLACE_ALL_H_
+
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <vector>
+
+namespace tidl {
+
+class ReplaceAll {
+ public:
+  ReplaceAll(std::string str);
+  ReplaceAll(std::string str, const std::string& from,
+      const std::string& to);
+  ReplaceAll(std::string str,
+      std::initializer_list<std::pair<std::string, std::string>> list);
+
+  operator const char*() const;
+  ReplaceAll& Change(const std::string& from, const std::string& to);
+
+  template <class T>
+  ReplaceAll& Change(const std::string& from, T t) {
+    std::string str = t();
+    return Change(from, str);
+  }
+
+  ReplaceAll& ChangeToUpper(const std::string& from, const std::string& to);
+  ReplaceAll& Once(const std::string& from, const std::string& to);
+
+  template <class T>
+  ReplaceAll& Once(const std::string& from, T t) {
+    std::string str = t();
+    return Once(from, str);
+  }
+
+  template <class T>
+  ReplaceAll& Select(std::string str, std::vector<std::string> strs, T t) {
+    int idx = t();
+    return Change(str, strs[idx]);
+  }
+
+  template <class T>
+  ReplaceAll& Transform(T t) {
+    std::string str = t(str_);
+    str_ = str;
+    return *this;
+  }
+
+  void Out(std::ofstream& stream);
+
+ private:
+  std::string str_;
+};
+
+class Inject {
+ public:
+  template <class T>
+  explicit Inject(T t) {
+    str_ = t();
+  }
+
+  operator std::string() const {
+    return str_;
+  }
+
+ private:
+  std::string str_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_REPLACE_ALL_H_
index c44192f..b634d9c 100644 (file)
@@ -79,7 +79,7 @@ void CCionBodyGeneratorBase::GenIncludeHeader(std::ofstream& stream) {
 
 void CCionBodyGeneratorBase::GenLogTag(std::ofstream& stream,
     const std::string& log_tag) {
-  std::string code = ReplaceAll(CB_LOG_TAG, "<LOG_TAG>", log_tag);
+  std::string code(ReplaceAll(CB_LOG_TAG, "<LOG_TAG>", log_tag));
   stream << code;
 }
 
@@ -118,8 +118,8 @@ void CCionBodyGeneratorBase::GenStructureDef(std::ofstream& stream,
 // @see #CB_STRUCTURE_ARRAY_DEF
 void CCionBodyGeneratorBase::GenStructureArrayDef(std::ofstream& stream,
     const Structure& st) {
-  std::string code = ReplaceAll(CB_STRUCTURE_ARRAY_DEF, "<PREFIX>",
-      GetHandlePrefix());
+  std::string code(ReplaceAll(CB_STRUCTURE_ARRAY_DEF, "<PREFIX>",
+      GetHandlePrefix()));
   code = ReplaceAll(code, "<NAME>", st.GetID());
 
   auto& elm = *(st.GetElements().begin());
@@ -133,8 +133,8 @@ void CCionBodyGeneratorBase::GenStructureArrayDef(std::ofstream& stream,
 // @see #CB_STRUCTURE_LIST_DEF
 void CCionBodyGeneratorBase::GenStructureListDef(std::ofstream& stream,
     const Structure& st) {
-  std::string code = ReplaceAll(CB_STRUCTURE_LIST_DEF, "<PREFIX>",
-      GetHandlePrefix());
+  std::string code(ReplaceAll(CB_STRUCTURE_LIST_DEF, "<PREFIX>",
+      GetHandlePrefix()));
   code = ReplaceAll(code, "<NAME>", st.GetID());
 
   stream << SmartIndent(code);
@@ -143,8 +143,8 @@ void CCionBodyGeneratorBase::GenStructureListDef(std::ofstream& stream,
 // @see #CB_STRUCTURE_BASE_DEF
 void CCionBodyGeneratorBase::GenStructureBaseDef(std::ofstream& stream,
     const Structure& st) {
-  std::string code = ReplaceAll(CB_STRUCTURE_BASE_DEF, "<PREFIX>",
-      GetHandlePrefix());
+  std::string code(ReplaceAll(CB_STRUCTURE_BASE_DEF, "<PREFIX>",
+      GetHandlePrefix()));
   code = ReplaceAll(code, "<NAME>", st.GetID());
 
   auto& elms = st.GetElements();
@@ -255,8 +255,8 @@ std::string CCionBodyGeneratorBase::GenArrayElementsFree(
 // @see #CB_STRUCTURE_ARRAY_BASE
 void CCionBodyGeneratorBase::GenStructureArrayBase(std::ofstream& stream,
     const Structure& st) {
-  std::string code = ReplaceAll(CB_STRUCTURE_ARRAY_BASE, "<PREFIX>",
-      GetHandlePrefix());
+  std::string code(ReplaceAll(CB_STRUCTURE_ARRAY_BASE, "<PREFIX>",
+      GetHandlePrefix()));
   code = ReplaceAll(code, "<NAME>", st.GetID());
 
   auto& elm = *(st.GetElements().begin());
@@ -404,8 +404,8 @@ std::string CCionBodyGeneratorBase::GenListCallbackParamType(
 // @see #CB_STRUCTURE_LIST_BASE
 void CCionBodyGeneratorBase::GenStructureListBase(std::ofstream& stream,
     const Structure& st) {
-  std::string code = ReplaceAll(CB_STRUCTURE_LIST_BASE, "<PREFIX>",
-      GetHandlePrefix());
+  std::string code(ReplaceAll(CB_STRUCTURE_LIST_BASE, "<PREFIX>",
+      GetHandlePrefix()));
   code = ReplaceAll(code, "<NAME>", st.GetID());
 
   auto& elm = *(st.GetElements().begin());
@@ -613,8 +613,8 @@ std::string CCionBodyGeneratorBase::GenBaseSetGet(const std::string& name,
     const Elements& elms) {
   std::string code;
   for (const auto& elm : elms) {
-    std::string set_get_code = ReplaceAll(CB_STRUCTURE_BASE_SET_GET,
-        "<PREFIX>", GetHandlePrefix());
+    std::string set_get_code(ReplaceAll(CB_STRUCTURE_BASE_SET_GET,
+        "<PREFIX>", GetHandlePrefix()));
     set_get_code = ReplaceAll(set_get_code, "<NAME>", name);
     set_get_code = ReplaceAll(set_get_code, "<ELEMENT_NAME>", elm->GetID());
 
@@ -637,8 +637,8 @@ std::string CCionBodyGeneratorBase::GenBaseSetGet(const std::string& name,
 // @see #CB_STRUCTURE_BASE
 void CCionBodyGeneratorBase::GenStructureBase(std::ofstream& stream,
     const Structure& st) {
-  std::string code = ReplaceAll(CB_STRUCTURE_BASE, "<PREFIX>",
-      GetHandlePrefix());
+  std::string code(ReplaceAll(CB_STRUCTURE_BASE, "<PREFIX>",
+      GetHandlePrefix()));
   code = ReplaceAll(code, "<NAME>", st.GetID());
 
   auto& elms = st.GetElements();
index 41265af..e6f8b4f 100644 (file)
@@ -57,11 +57,13 @@ void CCionGroupBodyGen::GenInterfaceDefs(std::ofstream& stream) {
 
 void CCionGroupBodyGen::GenInterfaceDef(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE_DEF, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_BASE_DEF)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Transform([&](std::string code) {
+        return SmartIndent(code);
+      })
+      .Out(stream);
 }
 
 void CCionGroupBodyGen::GenInterfaceEnums(std::ofstream& stream) {
@@ -98,13 +100,15 @@ std::string CCionGroupBodyGen::GenMethodEnums(const Interface& iface) {
 
 void CCionGroupBodyGen::GenInterfaceEnum(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, {
+  ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<METHOD_ENUMS>", GenMethodEnums(iface) }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str){
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_INTERFACE_METHOD_HANDLER_TYPE
@@ -145,12 +149,14 @@ void CCionGroupBodyGen::GenInterface(std::ofstream& stream, const Interface& ifa
 // @see #CB_INTERFACE_METHOD_TABLE
 void CCionGroupBodyGen::GenInterfaceMethodTable(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_TABLE, {
+  ReplaceAll(CB_INTERFACE_METHOD_TABLE, {
       { "<NAME>", iface.GetID() },
       { "<METHOD_HANDLERS>", GenMethodHandlers(iface) }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str){
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_INTERFACE_METHOD_HANDLER
@@ -165,12 +171,12 @@ std::string CCionGroupBodyGen::GenMethodHandlers(const Interface& iface) {
     std::transform(enum_value.begin(), enum_value.end(), enum_value.begin(),
         ::toupper);
 
-    std::string method_handler = ReplaceAll(CB_INTERFACE_METHOD_HANDLER, {
+    std::string method_handler(ReplaceAll(CB_INTERFACE_METHOD_HANDLER, {
         { "<ENUM_VALUE>", enum_value },
         { "<PREFIX>", GetHandlePrefix() },
         { "<NAME>", iface.GetID() },
         { "<METHOD_NAME>", d->GetID() }
-    });
+    }));
 
     code += RemoveLine(method_handler);
   }
@@ -182,23 +188,23 @@ std::string CCionGroupBodyGen::GenMethodHandlers(const Interface& iface) {
 void CCionGroupBodyGen::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
   std::string prefix = GetHandlePrefix();
-  std::string code = ReplaceAll(CB_INTERFACE_BASE, "<PREFIX>", prefix);
   std::string name = iface.GetID();
-  code = ReplaceAll(code, "<NAME>", name);
-  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_PREFIX>", prefix);
-  std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
-  std::string security = GenSecurityString(iface);
-  code = ReplaceAll(code, "<SET_SECURITY>", security);
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_BASE)
+      .Change("<PREFIX>", prefix)
+      .Change("<NAME>", name)
+      .ChangeToUpper("<UPPERCASE_PREFIX>", prefix)
+      .ChangeToUpper("<UPPERCASE_NAME>", name)
+      .Change("<SET_SECURITY>", GenSecurityString(iface))
+      .Transform([&](std::string str) {
+        return SmartIndent(str);
+      })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_METHOD_HANDLER_BASE
 void CCionGroupBodyGen::GenInterfaceMethodHandlerBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_HANDLER_BASE, {
+  ReplaceAll(CB_INTERFACE_METHOD_HANDLER_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<METHOD_NAME>", decl.GetID() },
@@ -208,16 +214,18 @@ void CCionGroupBodyGen::GenInterfaceMethodHandlerBase(std::ofstream& stream,
       { "<METHOD_HANDLER_CALLBACK_INVOKE>",
           GenMethodHandlerCallbackInvoke(decl) },
       { "<METHOD_HANDLER_ARGS_FREE>", GenMethodHandlerArgsFree(iface, decl) }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string str){
+    return SmartIndent(str);
+  })
+  .Out(stream);
 }
 
 // @see #CB_INTERFACE_METHOD_CALLBACK_INVOKE
 std::string CCionGroupBodyGen::GenMethodHandlerCallbackInvoke(
     const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_INVOKE,
-      "<METHOD_NAME>", decl.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_INVOKE,
+      "<METHOD_NAME>", decl.GetID()));
 
   if (decl.GetMethodType() == Declaration::MethodType::SYNC)
     code = ReplaceAll(code, "<RES_SET>", "res_ = ");
@@ -418,25 +426,18 @@ std::string CCionGroupBodyGen::GenMethodParcelWrite(const Interface& iface,
 std::string CCionGroupBodyGen::GenMethodAsyncBase(const Interface& iface,
     const Declaration& decl) {
   std::string prefix = GetHandlePrefix();
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_ASYNC_BASE, "<PREFIX>",
-      prefix);
   std::string name = iface.GetID();
-  code = ReplaceAll(code, "<NAME>", name);
   std::string method_name = decl.GetID();
-  code = ReplaceAll(code, "<METHOD_NAME>", method_name);
-  std::string args = GenMethodParams(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARAMS>", args);
-  std::string args_check = GenMethodParamsCheck(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARAMS_CHECK>", args_check);
-  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_PREFIX>", prefix);
-  std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
-  std::transform(method_name.begin(), method_name.end(), method_name.begin(),
-      ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_METHOD_NAME>", method_name);
-  std::string parcel_write = GenMethodParcelWrite(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARCEL_WRITE>", parcel_write);
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_ASYNC_BASE)
+      .Change("<PREFIX>", prefix)
+      .Change("<NAME>", name)
+      .Change("<METHOD_NAME>", method_name)
+      .Change("<METHOD_PARAMS>", GenMethodParams(iface, decl))
+      .Change("<METHOD_PARAMS_CHECK>", GenMethodParamsCheck(iface, decl))
+      .ChangeToUpper("<UPPERCASE_PREFIX>", prefix)
+      .ChangeToUpper("<UPPERCASE_NAME>", name)
+      .ChangeToUpper("<UPPERCASE_METHOD_NAME>", method_name)
+      .Change("<METHOD_PARCEL_WRITE>", GenMethodParcelWrite(iface, decl)));
   return code;
 }
 
index c5bd08d..a80cf4e 100644 (file)
@@ -70,35 +70,41 @@ void CCionGroupHeaderGen::GenInterfaceCallbacks(std::ofstream& stream) {
 
 void CCionGroupHeaderGen::GenInterfaceCallbackBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_CALLBACK_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_CALLBACK_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Transform([&](std::string code) {
+        return SmartIndent(code);
+      })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_METHOD_CALLBACK_BASE
 void CCionGroupHeaderGen::GenInterfaceMethodCallbackBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_BASE, {
+  ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_BASE, {
       { "<RETURN_TYPE>", GetReturnTypeString(decl.GetType()) },
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<METHOD_NAME>", decl.GetID() },
       { "<METHOD_PARAMS>", GenMethodParams(iface, decl) }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string code) {
+    return SmartIndent(code);
+  })
+  .Out(stream);
 }
 
 // @see #CB_INTERFACE_HANDLE
 void CCionGroupHeaderGen::GenInterfaceHandle(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_HANDLE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_HANDLE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Transform([&](std::string code) {
+        return SmartIndent(code);
+      })
+      .Out(stream);
 }
 
 void CCionGroupHeaderGen::GenInterfaces(std::ofstream& stream) {
@@ -127,13 +133,15 @@ void CCionGroupHeaderGen::GenInterface(std::ofstream& stream,
 // @see #CB_INTERFACE_BASE
 void CCionGroupHeaderGen::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE, {
+  ReplaceAll(CB_INTERFACE_BASE, {
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID()},
       { "<METHOD_CALLBACK_DECLS>", GenMethodCallbackDecls(iface) }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string code) {
+    return SmartIndent(code);
+  })
+  .Out(stream);
 }
 
 // @see #CB_INTERFACE_METHOD_CALLBACK_DECL
@@ -143,11 +151,11 @@ std::string CCionGroupHeaderGen::GenMethodCallbackDecls(const Interface& iface)
     if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
       continue;
 
-    std::string method_callback_decl = ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_DECL, {
+    std::string method_callback_decl(ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_DECL, {
         { "<PREFIX>", GetHandlePrefix() },
         { "<NAME>", iface.GetID() },
         { "<METHOD_NAME>", d->GetID() }
-    });
+    }));
 
     method_callback_decl = RemoveLine(method_callback_decl);
     method_callback_decls += RemoveLine(method_callback_decl, 2);
@@ -173,15 +181,17 @@ std::string CCionGroupHeaderGen::GenMethodParams(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_BASE
 void CCionGroupHeaderGen::GenInterfaceMethodBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_BASE, {
+  ReplaceAll(CB_INTERFACE_METHOD_BASE, {
       { "<RETURN_TYPE>", GetReturnTypeString(decl.GetType()) },
       { "<PREFIX>", GetHandlePrefix() },
       { "<NAME>", iface.GetID() },
       { "<METHOD_NAME>", decl.GetID() },
       { "<METHOD_PARAMS>", GenMethodParams(iface, decl) }
-  });
-
-  stream << SmartIndent(code);
+  })
+  .Transform([&](std::string code) {
+    return SmartIndent(code);
+  })
+  .Out(stream);
 }
 
 }  // namespace tidl
index 9df250e..8bbbd07 100644 (file)
@@ -101,64 +101,77 @@ void CCionHeaderGeneratorBase::GenStructures(std::ofstream& stream) {
 // @see #CB_STRUCTURE_HANDLE
 void CCionHeaderGeneratorBase::GenStructureHandle(std::ofstream& stream,
     const Structure& st) {
-  std::string str = ReplaceAll(CB_STRUCTURE_HANDLE, "<PREFIX>",
-      GetHandlePrefix());
-  str = ReplaceAll(str, "<NAME>", st.GetID());
-  stream << SmartIndent(str);
+  ReplaceAll(CB_STRUCTURE_HANDLE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", st.GetID())
+      .Transform([&](std::string str) {
+        return SmartIndent(str);
+      })
+      .Out(stream);
 }
 
 // @see #CB_STRUCTURE_ARRAY_BASE
 void CCionHeaderGeneratorBase::GenStructureArrayBase(std::ofstream& stream,
     const Structure& st) {
-  std::string str = ReplaceAll(CB_STRUCTURE_ARRAY_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  str = ReplaceAll(str, "<NAME>", st.GetID());
-
   auto& elm = *(st.GetElements().begin());
   auto& type = elm->GetType();
-  auto param_type = GetParamTypeString(ParameterType::Direction::IN, type);
-  str = ReplaceAll(str, "<PARAM_TYPE_IN>", param_type);
-
-  param_type = GetParamTypeString(ParameterType::Direction::OUT, type);
-  str = ReplaceAll(str, "<PARAM_TYPE_OUT>", param_type);
 
-  stream << SmartIndent(str);
+  ReplaceAll(CB_STRUCTURE_ARRAY_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", st.GetID())
+      .Change("<PARAM_TYPE_IN>",
+          GetParamTypeString(ParameterType::Direction::IN, type))
+      .Change("<PARAM_TYPE_OUT>",
+          GetParamTypeString(ParameterType::Direction::OUT, type))
+      .Transform([&](std::string str) {
+        return SmartIndent(str);
+      })
+      .Out(stream);
 }
 
 // @see #CB_STRUCTURE_LIST_BASE
 void CCionHeaderGeneratorBase::GenStructureListBase(std::ofstream& stream,
     const Structure& st) {
-  std::string str = ReplaceAll(CB_STRUCTURE_LIST_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  str = ReplaceAll(str, "<NAME>", st.GetID());
-
   auto& elm = *(st.GetElements().begin());
   auto& type = elm->GetType();
-  auto param_type = GetParamTypeString(ParameterType::Direction::IN, type);
-  str = ReplaceAll(str, "<PARAM_TYPE_IN>", param_type);
-  stream << SmartIndent(str);
+
+  ReplaceAll(CB_STRUCTURE_LIST_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", st.GetID())
+      .Change("<PARAM_TYPE_IN>",
+          GetParamTypeString(ParameterType::Direction::IN, type))
+      .Transform([&](std::string str) {
+        return SmartIndent(str);
+      })
+      .Out(stream);
 }
 
 // @see #CB_STRUCTURE_BASE
 void CCionHeaderGeneratorBase::GenStructureBase(std::ofstream& stream,
     const Structure& st) {
-  std::string str = ReplaceAll(CB_STRUCTURE_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  str = ReplaceAll(str, "<NAME>", st.GetID());
-  stream << SmartIndent(str);
+  ReplaceAll(CB_STRUCTURE_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", st.GetID())
+      .Transform([&](std::string str) {
+        return SmartIndent(str);
+      })
+      .Out(stream);
 
   for (const auto& e : st.GetElements()) {
-    str = ReplaceAll(CB_STRUCTURE_BASE_SET_GET, "<PREFIX>", GetHandlePrefix());
-    str = ReplaceAll(str, "<NAME>", st.GetID());
-
     auto& type = e->GetType();
-    auto param_type = GetParamTypeString(ParameterType::Direction::IN, type);
-    str = ReplaceAll(str, "<PARAM_TYPE_IN>", param_type);
 
-    param_type = GetParamTypeString(ParameterType::Direction::OUT, type);
-    str = ReplaceAll(str, "<PARAM_TYPE_OUT>", param_type);
-    str = ReplaceAll(str, "<ELEMENT_NAME>", e->GetID());
-    stream << SmartIndent(str);
+    ReplaceAll(CB_STRUCTURE_BASE_SET_GET)
+        .Change("<PREFIX>", GetHandlePrefix())
+        .Change("<NAME>", st.GetID())
+        .Change("<PARAM_TYPE_IN>",
+            GetParamTypeString(ParameterType::Direction::IN, type))
+        .Change("<PARAM_TYPE_OUT>",
+            GetParamTypeString(ParameterType::Direction::OUT, type))
+        .Change("<ELEMENT_NAME>", e->GetID())
+        .Transform([&](std::string str) {
+          return SmartIndent(str);
+        })
+        .Out(stream);
   }
 }
 
index 2b77f9e..b3472f8 100644 (file)
@@ -76,22 +76,28 @@ void CCionProxyBodyGen::GenInterfaceDef(std::ofstream& stream,
 // @see #CB_INTERFACE_DELEGATE_DEF
 void CCionProxyBodyGen::GenInterfaceDelegateDef(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_DEF, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<DELEGATE_NAME>", decl.GetID());
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_DELEGATE_DEF, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<DELEGATE_NAME>", decl.GetID() }
+  })
+  .Transform([&](std::string code) {
+    return SmartIndent(code);
+  })
+  .Out(stream);
 }
 
 // @see #CB_INTERFACE_BASE_DEF
 void CCionProxyBodyGen::GenInterfaceBaseDef(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE_DEF, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_BASE_DEF, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() }
+  })
+  .Transform([&](std::string code) {
+    return SmartIndent(code);
+  })
+  .Out(stream);
 }
 
 void CCionProxyBodyGen::GenInterfaces(std::ofstream& stream) {
@@ -130,17 +136,18 @@ void CCionProxyBodyGen::GenInterface(std::ofstream& stream, const Interface& ifa
 void CCionProxyBodyGen::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
   std::string prefix = GetHandlePrefix();
-  std::string code = ReplaceAll(CB_INTERFACE_BASE, "<PREFIX>", prefix);
   std::string name = iface.GetID();
-  code = ReplaceAll(code, "<NAME>", name);
-  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_PREFIX>", prefix);
-  std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
-  std::string security = GenSecurityString(iface);
-  code = ReplaceAll(code, "<SET_SECURITY>", security);
 
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_BASE)
+      .Change("<PREFIX>", prefix)
+      .Change("<NAME>", name)
+      .ChangeToUpper("<UPPERCASE_PREFIX>", prefix)
+      .ChangeToUpper("<UPPERCASE_NAME>", name)
+      .Change("<SET_SECURITY>", GenSecurityString(iface))
+      .Transform([&](std::string code) {
+        return SmartIndent(code);
+      })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_DELEGATE_ENUM_BASE
@@ -161,12 +168,15 @@ void CCionProxyBodyGen::GenInterfaceDelegateEnumBase(std::ofstream& stream,
     return;
 
   std::transform(enums.begin(), enums.end(), enums.begin(), ::toupper);
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_ENUM_BASE, "<ENUMS>",
-      enums);
-  code = ReplaceAll(code, "<PREFIX>", GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_DELEGATE_ENUM_BASE, {
+      { "<ENUMS>", enums },
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() }
+  })
+  .Transform([&](std::string code) {
+    return SmartIndent(code);
+  })
+  .Out(stream);
 }
 
 std::string CCionProxyBodyGen::GenDelegateArgsDecl(const Interface& iface,
@@ -271,29 +281,27 @@ std::string CCionProxyBodyGen::GenDelegateCallbackArgs(const Declaration& decl)
 // @see CB_INTERFACE_DELEGATE_BASE
 void CCionProxyBodyGen::GenInterfaceDelegateBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<DELEGATE_NAME>", decl.GetID());
-
   std::string enum_value = GetHandlePrefix() + "_" + iface.GetID() +
       "_DELEGATE_" + decl.GetID();
   std::transform(enum_value.begin(), enum_value.end(), enum_value.begin(),
       ::toupper);
-  code = ReplaceAll(code, "<DELEGATE_ENUM_VALUE>", enum_value);
-  code = ReplaceAll(code, "<DELEGATE_ARGS_DECL>",
-      GenDelegateArgsDecl(iface, decl));
-  code = ReplaceAll(code, "<DELEGATE_PARCEL_READ>",
-      GenDelegateParcelRead(iface, decl));
   bool has_free = false;
   std::string delegate_args_free = GenDelegateArgsFree(iface, decl, has_free);
-  code = ReplaceAll(code, "<DELEGATE_ARGS_FREE>", delegate_args_free);
-  code = ReplaceAll(code, "<DELEGATE_CALLBACK_ARGS>",
-      GenDelegateCallbackArgs(decl));
-  code = ReplaceAll(code, "<GOTO_STATEMENT>",
-      has_free ? "out:" + NLine(1) : "");
 
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_DELEGATE_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Change("<DELEGATE_NAME>", decl.GetID())
+      .Change("<DELEGATE_ENUM_VALUE>", enum_value)
+      .Change("<DELEGATE_ARGS_DECL>", GenDelegateArgsDecl(iface, decl))
+      .Change("<DELEGATE_PARCEL_READ>", GenDelegateParcelRead(iface, decl))
+      .Change("<DELEGATE_ARGS_FREE>", delegate_args_free)
+      .Change("<DELEGATE_CALLBACK_ARGS>", GenDelegateCallbackArgs(decl))
+      .Change("<GOTO_STATEMENT>", has_free ? "out:" + NLine(1) : "")
+      .Transform([&](std::string code) {
+        return SmartIndent(code);
+      })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_DELEGATE_TABLE
@@ -309,25 +317,29 @@ void CCionProxyBodyGen::GenInterfaceDelegateTable(std::ofstream& stream,
         "_DELEGATE_" + d->GetID();
     std::transform(enum_value.begin(), enum_value.end(), enum_value.begin(),
         ::toupper);
-    std::string member = ReplaceAll(CB_INTERFACE_DELEGATE_TABLE_MEMBER,
-        "<ENUM_VALUE>", enum_value);
-    member = ReplaceAll(member, "<PREFIX>", GetHandlePrefix());
-    member = ReplaceAll(member, "<NAME>", iface.GetID());
-    member = ReplaceAll(member, "<DELEGATE_NAME>", d->GetID());
-    member = RemoveLine(member);
+    std::string member(ReplaceAll(CB_INTERFACE_DELEGATE_TABLE_MEMBER, {
+        { "<ENUM_VALUE>", enum_value },
+        { "<PREFIX>", GetHandlePrefix() },
+        { "<NAME>", iface.GetID() },
+        { "<DELEGATE_NAME>", d->GetID() }
+    }));
 
+    member = RemoveLine(member);
     delegate_handlers += member;
   }
 
   if (delegate_handlers.empty())
     delegate_handlers = "nullptr," + NLine(1);
 
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_TABLE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<DELEGATE_HANDLERS>", delegate_handlers);
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_DELEGATE_TABLE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<DELEGATE_HANDLERS>", delegate_handlers }
+  })
+  .Transform([&](std::string code) {
+    return SmartIndent(code);
+  })
+  .Out(stream);
 }
 
 // @see #CB_INTERFACE_METHOD_ENUM_BASE
@@ -350,12 +362,15 @@ void CCionProxyBodyGen::GenInterfaceMethodEnumBase(std::ofstream& stream,
   }
 
   std::transform(enums.begin(), enums.end(), enums.begin(), ::toupper);
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, "<ENUMS>",
-      enums);
-  code = ReplaceAll(code, "<PREFIX>", GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, {
+      { "<ENUMS>", enums },
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() }
+  })
+  .Transform([&](std::string code) {
+    return SmartIndent(code);
+  })
+  .Out(stream);
 }
 
 std::string CCionProxyBodyGen::GenMethodParams(const Interface& iface,
@@ -448,8 +463,8 @@ std::string CCionProxyBodyGen::GenMethodDelegateAppend(const Interface& iface,
     auto& param_type = p->GetParameterType();
     auto& type = param_type.GetBaseType();
     if (IsDelegateType(iface, type)) {
-      std::string delegate_append_code = ReplaceAll(
-          CB_INTERFACE_METHOD_DELEGATE_APPEND, "<ARG>", p->GetID());
+      std::string delegate_append_code(ReplaceAll(
+          CB_INTERFACE_METHOD_DELEGATE_APPEND, "<ARG>", p->GetID()));
       code += delegate_append_code;
     }
   }
@@ -461,33 +476,25 @@ std::string CCionProxyBodyGen::GenMethodDelegateAppend(const Interface& iface,
 std::string CCionProxyBodyGen::GenMethodAsyncBase(const Interface& iface,
     const Declaration& decl) {
   std::string prefix = GetHandlePrefix();
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_ASYNC_BASE, "<PREFIX>",
-      prefix);
   std::string name = iface.GetID();
-  code = ReplaceAll(code, "<NAME>", name);
   std::string method_name = decl.GetID();
-  code = ReplaceAll(code, "<METHOD_NAME>", method_name);
-  std::string args = GenMethodParams(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARAMS>", args);
-  std::string args_check = GenMethodParamsCheck(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARAMS_CHECK>", args_check);
-  std::string file_def = GetFilePayloadDefString(iface, decl);
-  code = ReplaceAll(code, "<FILE_LIST_DEF>", file_def);
-  std::string file_send = GetFilePayloadSendString(iface, decl, true);
-  code = ReplaceAll(code, "<FILE_LIST_SEND>", file_send);
-  std::string file_free = GetFilePayloadFreeString(iface, decl);
-  code = ReplaceAll(code, "<FILE_LIST_FREE>", file_free);
-  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_PREFIX>", prefix);
-  std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
-  std::transform(method_name.begin(), method_name.end(), method_name.begin(),
-      ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_METHOD_NAME>", method_name);
-  std::string parcel_write = GenMethodParcelWrite(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARCEL_WRITE>", parcel_write);
-  std::string delegate_append = GenMethodDelegateAppend(iface, decl);
-  code = ReplaceAll(code, "<METHOD_DELEGATE_APPEND>", delegate_append);
+
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_ASYNC_BASE)
+      .Change("<PREFIX>", prefix)
+      .Change("<NAME>", name)
+      .Change("<METHOD_NAME>", method_name)
+      .Change("<METHOD_PARAMS>", GenMethodParams(iface, decl))
+      .Change("<METHOD_PARAMS_CHECK>", GenMethodParamsCheck(iface, decl))
+      .Change("<FILE_LIST_DEF>", GetFilePayloadDefString(iface, decl))
+      .Change("<FILE_LIST_SEND>", GetFilePayloadSendString(iface, decl, true))
+      .Change("<FILE_LIST_FREE>", GetFilePayloadFreeString(iface, decl))
+      .ChangeToUpper("<UPPERCASE_PREFIX>", prefix)
+      .ChangeToUpper("<UPPERCASE_NAME>", name)
+      .ChangeToUpper("<UPPERCASE_METHOD_NAME>", method_name)
+      .Change("<METHOD_PARCEL_WRITE>", GenMethodParcelWrite(iface, decl))
+      .Change("<METHOD_DELEGATE_APPEND>", GenMethodDelegateAppend(iface,
+          decl)));
+
   return code;
 }
 
@@ -565,41 +572,29 @@ std::string CCionProxyBodyGen::GenMethodParcelRead(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_BASE
 std::string CCionProxyBodyGen::GenMethodBase(const Interface& iface,
     const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_BASE, "<RETURN_TYPE>",
-      GetReturnTypeString(decl.GetType()));
   std::string prefix = GetHandlePrefix();
-  code = ReplaceAll(code, "<PREFIX>", prefix);
   std::string name = iface.GetID();
-  code = ReplaceAll(code, "<NAME>", name);
   std::string method_name = decl.GetID();
-  code = ReplaceAll(code, "<METHOD_NAME>", method_name);
-  std::string args = GenMethodParams(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARAMS>", args);
-  std::string values = GenMethodArgs(iface, decl);
-  code = ReplaceAll(code, "<METHOD_ARGS>", values);
-  std::string error_value = GetErrorValue(decl.GetType());
-  code = ReplaceAll(code, "<ERROR_VALUE>", error_value);
-  std::string args_check = GenMethodParamsCheck(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARAMS_CHECK>", args_check);
-  std::string file_def = GetFilePayloadDefString(iface, decl);
-  code = ReplaceAll(code, "<FILE_LIST_DEF>", file_def);
-  std::string file_send = GetFilePayloadSendString(iface, decl, true);
-  code = ReplaceAll(code, "<FILE_LIST_SEND>", file_send);
-  std::string file_free = GetFilePayloadFreeString(iface, decl);
-  code = ReplaceAll(code, "<FILE_LIST_FREE>", file_free);
-  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_PREFIX>", prefix);
-  std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
-  std::transform(method_name.begin(), method_name.end(), method_name.begin(),
-      ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_METHOD_NAME>", method_name);
-  std::string parcel_write = GenMethodParcelWrite(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARCEL_WRITE>", parcel_write);
-  std::string parcel_read = GenMethodParcelRead(iface, decl);
-  code = ReplaceAll(code, "<METHOD_PARCEL_READ>", parcel_read);
-  std::string delegate_append = GenMethodDelegateAppend(iface, decl);
-  code = ReplaceAll(code, "<METHOD_DELEGATE_APPEND>", delegate_append);
+
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_BASE)
+      .Change("<RETURN_TYPE>", GetReturnTypeString(decl.GetType()))
+      .Change("<PREFIX>", prefix)
+      .Change("<NAME>", name)
+      .Change("<METHOD_NAME>", method_name)
+      .Change("<METHOD_PARAMS>", GenMethodParams(iface, decl))
+      .Change("<METHOD_ARGS>", GenMethodArgs(iface, decl))
+      .Change("<ERROR_VALUE>", GetErrorValue(decl.GetType()))
+      .Change("<METHOD_PARAMS_CHECK>", GenMethodParamsCheck(iface, decl))
+      .Change("<FILE_LIST_DEF>", GetFilePayloadDefString(iface, decl))
+      .Change("<FILE_LIST_SEND>", GetFilePayloadSendString(iface, decl, true))
+      .Change("<FILE_LIST_FREE>", GetFilePayloadFreeString(iface, decl))
+      .ChangeToUpper("<UPPERCASE_PREFIX>", prefix)
+      .ChangeToUpper("<UPPERCASE_NAME>", name)
+      .ChangeToUpper("<UPPERCASE_METHOD_NAME>", method_name)
+      .Change("<METHOD_PARCEL_WRITE>", GenMethodParcelWrite(iface, decl))
+      .Change("<METHOD_PARCEL_READ>", GenMethodParcelRead(iface, decl))
+      .Change("<METHOD_DELEGATE_APPEND>", GenMethodDelegateAppend(iface,
+          decl)));
   return code;
 }
 
index 21bd773..4e9c4f4 100644 (file)
@@ -60,9 +60,10 @@ void CCionProxyHeaderGen::GenInterfaceHandles(std::ofstream& stream) {
 // @see #CB_INTERFACE_HANDLE
 void CCionProxyHeaderGen::GenInterfaceHandle(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_HANDLE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_HANDLE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -70,10 +71,11 @@ void CCionProxyHeaderGen::GenInterfaceHandle(std::ofstream& stream,
 // @see #CB_INTERFACE_DELEGATE_HANDLE
 void CCionProxyHeaderGen::GenInterfaceDelegateHandle(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<DELEGATE_NAME>", decl.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<DELEGATE_NAME>", decl.GetID() }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -110,9 +112,10 @@ void CCionProxyHeaderGen::GenInterface(std::ofstream& stream,
 // @see #CB_INTERFACE_BASE
 void CCionProxyHeaderGen::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -134,11 +137,12 @@ std::string CCionProxyHeaderGen::GenDelegateParams(const Interface& iface,
 // @see #CB_INTERFACE_DELEGATE_BASE
 void CCionProxyHeaderGen::GenInterfaceDelegateBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<DELEGATE_NAME>", decl.GetID());
-  code = ReplaceAll(code, "<DELEGATE_PARAMS>", GenDelegateParams(iface, decl));
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<DELEGATE_NAME>", decl.GetID() },
+      { "<DELEGATE_PARAMS>", GenDelegateParams(iface, decl) }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -160,13 +164,13 @@ std::string CCionProxyHeaderGen::GenMethodParams(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_BASE
 void CCionProxyHeaderGen::GenInterfaceMethodBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_BASE, "<RETURN_TYPE>",
-      GetReturnTypeString(decl.GetType()));
-  code = ReplaceAll(code, "<PREFIX>", GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<METHOD_NAME>", decl.GetID());
-  code = ReplaceAll(code, "<METHOD_PARAMS>", GenMethodParams(iface, decl));
-
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_BASE, {
+      { "<RETURN_TYPE>", GetReturnTypeString(decl.GetType()) },
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<METHOD_NAME>", decl.GetID() },
+      { "<METHOD_PARAMS>", GenMethodParams(iface, decl) }
+  }));
   stream << SmartIndent(code);
 }
 
index af8494b..7e09b51 100644 (file)
@@ -78,8 +78,8 @@ void CCionStubBodyGen::GenInterfaceEnum(std::ofstream& stream,
 
 // @see #CB_INTERFACE_METHOD_ENUM
 std::string CCionStubBodyGen::GenMethodEnums(const Interface& iface) {
-  std::string method_enum = ReplaceAll(CB_INTERFACE_METHOD_ENUM,
-      "<UPPERCASE_PREFIX>", GetHandlePrefix());
+  std::string method_enum(ReplaceAll(CB_INTERFACE_METHOD_ENUM,
+      "<UPPERCASE_PREFIX>", GetHandlePrefix()));
   method_enum = ReplaceAll(method_enum, "<UPPERCASE_NAME>", iface.GetID());
   method_enum = ReplaceAll(method_enum, "<UPPERCASE_METHOD_NAME>", "RESULT_");
   std::string method_enums = RemoveLine(method_enum);
@@ -111,8 +111,8 @@ std::string CCionStubBodyGen::GenMethodEnums(const Interface& iface) {
 // @see #CB_INTERFACE_METHOD_ENUM_BASE
 void CCionStubBodyGen::GenInterfaceMethodEnumBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, "<PREFIX>",
-      GetHandlePrefix());
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, "<PREFIX>",
+      GetHandlePrefix()));
   code = ReplaceAll(code, "<NAME>", iface.GetID());
   code = ReplaceAll(code, "<METHOD_ENUMS>", GenMethodEnums(iface));
 
@@ -127,13 +127,12 @@ std::string CCionStubBodyGen::GenDelegateEnums(const Interface& iface) {
     if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
       continue;
 
-    std::string method_enum = ReplaceAll(CB_INTERFACE_DELEGATE_ENUM,
-        "<UPPERCASE_PREFIX>", GetHandlePrefix());
-    method_enum = ReplaceAll(method_enum, "<UPPERCASE_NAME>", iface.GetID());
-    method_enum = ReplaceAll(method_enum, "<UPPERCASE_DELEGATE_NAME>",
-        d->GetID());
-    method_enum = ReplaceAll(method_enum, "<NUMBER>", std::to_string(num++));
-
+    std::string method_enum(ReplaceAll(CB_INTERFACE_DELEGATE_ENUM, {
+        { "<UPPERCASE_PREFIX>", GetHandlePrefix() },
+        { "<UPPERCASE_NAME>", iface.GetID() },
+        { "<UPPERCASE_DELEGATE_NAME>", d->GetID() },
+        { "<NUMBER>", std::to_string(num++) }
+    }));
     method_enums += RemoveLine(method_enum);
   }
   std::transform(method_enums.begin(), method_enums.end(), method_enums.begin(),
@@ -149,10 +148,11 @@ void CCionStubBodyGen::GenInterfaceDelegateEnumBase(std::ofstream& stream,
   if (delegate_enums.empty())
     return;
 
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_ENUM_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<DELEGATE_ENUMS>", delegate_enums);
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_ENUM_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<DELEGATE_ENUMS>", delegate_enums }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -182,10 +182,11 @@ void CCionStubBodyGen::GenInterfaceDef(std::ofstream& stream,
 // @see #CB_INTERFACE_DELEGATE_DEF
 void CCionStubBodyGen::GenInterfaceDelegateDef(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_DEF, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<DELEGATE_NAME>", decl.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_DEF, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<DELEGATE_NAME>", decl.GetID() }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -193,9 +194,10 @@ void CCionStubBodyGen::GenInterfaceDelegateDef(std::ofstream& stream,
 // @see #CB_INTERFACE_BASE_DEF
 void CCionStubBodyGen::GenInterfaceBaseDef(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE_DEF, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_BASE_DEF, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -233,9 +235,10 @@ void CCionStubBodyGen::GenInterface(std::ofstream& stream, const Interface& ifac
 // @see #CB_INTERFACE_CONTEXT_BASE
 void CCionStubBodyGen::GenInterfaceContextBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_CONTEXT_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_CONTEXT_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -319,28 +322,26 @@ std::string CCionStubBodyGen::GenDelegateParcelWrite(const Interface& iface,
 // @see #CB_INTERFACE_DELEGATE_BASE
 void CCionStubBodyGen::GenInterfaceDelegateBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_BASE, "<PREFIX>",
-      GetHandlePrefix());
   std::string file_send = GetFilePayloadSendString(iface, decl, false);
-  code = ReplaceAll(code, "<FILE_LIST_SEND>", file_send);
   std::string file_free = GetFilePayloadFreeString(iface, decl);
-  code = ReplaceAll(code, "<FILE_LIST_FREE>", file_free);
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<DELEGATE_NAME>", decl.GetID());
-  code = ReplaceAll(code, "<DELEGATE_PARAMS>", GenDelegateParams(iface, decl));
-    std::string file_def = GetFilePayloadDefString(iface, decl, false);
-  code = ReplaceAll(code, "<FILE_LIST_DEF>", file_def);
-  code = ReplaceAll(code, "<DELEGATE_PARAMS_CHECK>",
-      GenDelegateParamsCheck(iface, decl));
   std::string enum_value = GetHandlePrefix() + "_" + iface.GetID() +
       "_DELEGATE_" + decl.GetID();
   std::transform(enum_value.begin(), enum_value.end(), enum_value.begin(),
       ::toupper);
-  code = ReplaceAll(code, "<DELEGATE_ENUM_VALUE>", enum_value);
-  code = ReplaceAll(code, "<DELEGATE_PARCEL_WRITE>",
-      GenDelegateParcelWrite(iface, decl));
-
+  std::string file_def = GetFilePayloadDefString(iface, decl, false);
 
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<FILE_LIST_SEND>", file_send },
+      { "<FILE_LIST_FREE>", file_free },
+      { "<NAME>", iface.GetID() },
+      { "<DELEGATE_NAME>", decl.GetID() },
+      { "<DELEGATE_PARAMS>", GenDelegateParams(iface, decl) },
+      { "<FILE_LIST_DEF>", file_def },
+      { "<DELEGATE_PARAMS_CHECK>", GenDelegateParamsCheck(iface, decl) },
+      { "<DELEGATE_ENUM_VALUE>", enum_value },
+      { "<DELEGATE_PARCEL_WRITE>", GenDelegateParcelWrite(iface, decl) }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -416,8 +417,8 @@ std::string CCionStubBodyGen::GenMethodHandlerParcelRead(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_CALLBACK_INVOKE
 std::string CCionStubBodyGen::GenMethodHandlerCallbackInvoke(
     const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_INVOKE,
-      "<METHOD_NAME>", decl.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_INVOKE,
+      "<METHOD_NAME>", decl.GetID()));
 
   if (decl.GetMethodType() == Declaration::MethodType::SYNC)
     code = ReplaceAll(code, "<RES_SET>", "res_ = ");
@@ -586,26 +587,23 @@ std::string CCionStubBodyGen::GenMethodHandlerArgsFree(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_HANDLER_BASE
 void CCionStubBodyGen::GenInterfaceMethodHandlerBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_HANDLER_BASE, "<PREFIX>",
-      GetHandlePrefix());
   std::string file_send = GetFilePayloadSendString(iface, decl, false);
-  code = ReplaceAll(code, "<FILE_LIST_SEND>", file_send);
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<METHOD_NAME>", decl.GetID());
-  code = ReplaceAll(code, "<METHOD_HANDLER_ARGS_DECL>",
-      GenMethodHandlerArgsDecl(iface, decl));
   std::string file_def = GetFilePayloadDefString(iface, decl, false);
-  code = ReplaceAll(code, "<FILE_LIST_DEF>", file_def);
-  code = ReplaceAll(code, "<METHOD_HANDLER_PARCEL_READ>",
-      GenMethodHandlerParcelRead(iface, decl));
-  code = ReplaceAll(code, "<METHOD_HANDLER_CALLBACK_INVOKE>",
-      GenMethodHandlerCallbackInvoke(decl));
-  code = ReplaceAll(code, "<METHOD_HANDLER_PARCEL_WRITE>",
-      GenMethodHandlerParcelWrite(iface, decl));
   std::string file_free = GetFilePayloadFreeString(iface, decl);
-  code = ReplaceAll(code, "<FILE_LIST_FREE>", file_free);
-  code = ReplaceAll(code, "<METHOD_HANDLER_ARGS_FREE>",
-      GenMethodHandlerArgsFree(iface, decl));
+
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_HANDLER_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<FILE_LIST_SEND>", file_send },
+      { "<NAME>", iface.GetID() },
+      { "<METHOD_NAME>", decl.GetID() },
+      { "<METHOD_HANDLER_ARGS_DECL>", GenMethodHandlerArgsDecl(iface, decl) },
+      { "<FILE_LIST_DEF>", file_def },
+      { "<METHOD_HANDLER_PARCEL_READ>", GenMethodHandlerParcelRead(iface, decl) },
+      { "<METHOD_HANDLER_CALLBACK_INVOKE>", GenMethodHandlerCallbackInvoke(decl) },
+      { "<METHOD_HANDLER_PARCEL_WRITE>",  GenMethodHandlerParcelWrite(iface, decl) },
+      { "<FILE_LIST_FREE>", file_free },
+      { "<METHOD_HANDLER_ARGS_FREE>", GenMethodHandlerArgsFree(iface, decl) }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -621,11 +619,12 @@ std::string CCionStubBodyGen::GenMethodHandlers(const Interface& iface) {
       "_METHOD_" + d->GetID();
     std::transform(enum_value.begin(), enum_value.end(), enum_value.begin(),
         ::toupper);
-    std::string method_handler = ReplaceAll(CB_INTERFACE_METHOD_HANDLER,
-        "<ENUM_VALUE>", enum_value);
-    method_handler = ReplaceAll(method_handler, "<PREFIX>", GetHandlePrefix());
-    method_handler = ReplaceAll(method_handler, "<NAME>", iface.GetID());
-    method_handler = ReplaceAll(method_handler, "<METHOD_NAME>", d->GetID());
+    std::string method_handler(ReplaceAll(CB_INTERFACE_METHOD_HANDLER, {
+        { "<ENUM_VALUE>", enum_value },
+        { "<PREFIX>", GetHandlePrefix() },
+        { "<NAME>", iface.GetID() },
+        { "<METHOD_NAME>", d->GetID() }
+    }));
 
     code += RemoveLine(method_handler);
   }
@@ -636,9 +635,10 @@ std::string CCionStubBodyGen::GenMethodHandlers(const Interface& iface) {
 // @see #CB_INTERFACE_METHOD_TABLE
 void CCionStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_TABLE, "<NAME>",
-      iface.GetID());
-  code = ReplaceAll(code, "<METHOD_HANDLERS>", GenMethodHandlers(iface));
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_TABLE, {
+      { "<NAME>", iface.GetID() },
+      { "<METHOD_HANDLERS>", GenMethodHandlers(iface) }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -646,12 +646,11 @@ void CCionStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream,
 // @see #CB_INTERFACE_BASE
 void CCionStubBodyGen::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  std::string security = GenSecurityString(iface);
-  code = ReplaceAll(code, "<SET_SECURITY>", security);
-
+  std::string code(ReplaceAll(CB_INTERFACE_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<SET_SECURITY>", GenSecurityString(iface) }
+  }));
 
   stream << SmartIndent(code);
 }
index 7452baf..9a6c485 100644 (file)
@@ -57,10 +57,11 @@ void CCionStubHeaderGen::GenInterfaceHandles(std::ofstream& stream) {
 // @see #CB_INTERFACE_DELEGATE_HANDLE
 void CCionStubHeaderGen::GenInterfaceDelegateHandle(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<DELEGATE_NAME>", decl.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<DELEGATE_NAME>", decl.GetID() }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -84,9 +85,10 @@ void CCionStubHeaderGen::GenInterfaceCallbacks(std::ofstream& stream) {
 // @see #CB_INTERFACE_CALLBACK_BASE
 void CCionStubHeaderGen::GenInterfaceCallbackBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_CALLBACK_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
+  std::string code(ReplaceAll(CB_INTERFACE_CALLBACK_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -108,12 +110,13 @@ std::string CCionStubHeaderGen::GenMethodParams(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_CALLBACK_BASE
 void CCionStubHeaderGen::GenInterfaceMethodCallbackBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_BASE,
-      "<RETURN_TYPE>", GetReturnTypeString(decl.GetType()));
-  code = ReplaceAll(code, "<PREFIX>", GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<METHOD_NAME>", decl.GetID());
-  code = ReplaceAll(code, "<METHOD_PARAMS>", GenMethodParams(iface, decl));
+  std::string code(ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_BASE, {
+      { "<RETURN_TYPE>", GetReturnTypeString(decl.GetType()) },
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<METHOD_NAME>", decl.GetID() },
+      { "<METHOD_PARAMS>", GenMethodParams(iface, decl) }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -156,11 +159,12 @@ std::string CCionStubHeaderGen::GenDelegateParams(const Interface& iface,
 // @see #CB_INTERFACE_DELEGATE_BASE
 void CCionStubHeaderGen::GenInterfaceDelegateBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
-  std::string code = ReplaceAll(CB_INTERFACE_DELEGATE_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<DELEGATE_NAME>", decl.GetID());
-  code = ReplaceAll(code, "<DELEGATE_PARAMS>", GenDelegateParams(iface, decl));
+  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<DELEGATE_NAME>", decl.GetID() },
+      { "<DELEGATE_PARAMS>", GenDelegateParams(iface, decl) }
+  }));
 
   stream << SmartIndent(code);
 }
@@ -172,12 +176,12 @@ std::string CCionStubHeaderGen::GenMethodCallbackDecls(const Interface& iface) {
     if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
       continue;
 
-    std::string method_callback_decl = ReplaceAll(
-        CB_INTERFACE_METHOD_CALLBACK_DECL, "<PREFIX>", GetHandlePrefix());
-    method_callback_decl = ReplaceAll(method_callback_decl, "<NAME>",
-        iface.GetID());
-    method_callback_decl = ReplaceAll(method_callback_decl, "<METHOD_NAME>",
-        d->GetID());
+    std::string method_callback_decl(ReplaceAll(
+        CB_INTERFACE_METHOD_CALLBACK_DECL, {
+        { "<PREFIX>", GetHandlePrefix() },
+        { "<NAME>", iface.GetID() },
+        { "<METHOD_NAME>", d->GetID() }
+    }));
 
     method_callback_decl = RemoveLine(method_callback_decl);
     method_callback_decls += RemoveLine(method_callback_decl, 2);
@@ -189,11 +193,11 @@ std::string CCionStubHeaderGen::GenMethodCallbackDecls(const Interface& iface) {
 // @see #CB_INTERFACE_BASE
 void CCionStubHeaderGen::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code = ReplaceAll(CB_INTERFACE_BASE, "<PREFIX>",
-      GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-  code = ReplaceAll(code, "<METHOD_CALLBACK_DECLS>",
-      GenMethodCallbackDecls(iface));
+  std::string code(ReplaceAll(CB_INTERFACE_BASE, {
+      { "<PREFIX>", GetHandlePrefix() },
+      { "<NAME>", iface.GetID() },
+      { "<METHOD_CALLBACK_DECLS>", GenMethodCallbackDecls(iface) }
+  }));
 
   stream << SmartIndent(code);
 }
index 734e5c1..a0319cb 100644 (file)
@@ -207,9 +207,9 @@ void CppCionGeneratorBase::GenStructuresForBody(std::ofstream& stream) {
 void CppCionGeneratorBase::GenStructureForBody(std::ofstream& stream,
     const Structure& st) {
   std::vector<std::pair<std::string, std::string>> v;
-  const char ctor[] = "##::##() {}\n\n" \
-                      "##::##($$)\n" \
-                      "    : $$ {}";
+  const char ctor[] = "<CLS_NAME>::<CLS_NAME>() {}\n\n" \
+                      "<CLS_NAME>::<CLS_NAME>(<PARAMS>)\n" \
+                      "    : <INIT> {}";
 
   for (const auto& i : st.GetElements()) {
     std::pair<std::string, std::string> p;
@@ -219,27 +219,30 @@ void CppCionGeneratorBase::GenStructureForBody(std::ofstream& stream,
     v.push_back(p);
   }
 
-  GenTemplate(ReplaceAll(ctor, "##", st.GetID()), stream,
-    [&]()->std::string {
-      std::string str;
-      for (auto& i : v) {
-        str += i.first + " " + i.second;
+  ReplaceAll(ctor)
+      .Change("<CLS_NAME>", st.GetID())
+      .Change("<PARAMS>", [&]() {
+        std::string str;
+        for (auto& i : v) {
+          str += i.first + " " + i.second;
 
-        if (i != v.back())
-          str += ", ";
-      }
-      return str;
-    },
-    [&]()->std::string {
-      std::string str;
-      for (auto& i : v) {
-        str += i.second + "_(std::move(" + i.second + "))";
+          if (i != v.back())
+            str += ", ";
+        }
+        return str;
+      })
+      .Change("<INIT>", [&]() {
+        std::string str;
+        for (auto& i : v) {
+          str += i.second + "_(std::move(" + i.second + "))";
+
+          if (i != v.back())
+            str += ", ";
+        }
+        return str;
+      })
+      .Out(stream);
 
-        if (i != v.back())
-          str += ", ";
-      }
-      return str;
-    });
   stream <<  NLine(2);
 }
 
@@ -711,16 +714,15 @@ void CppCionGeneratorBase::GenHeaderCallbacks(std::ofstream& stream,
 void CppCionGeneratorBase::GenHeaderCallback(std::ofstream& stream,
                                          const Declaration& decl,
                                          bool is_proxy) {
-  stream << GenTemplateString(CB_CALLBACK_CLASS,
-      [&]()->std::string {
-        return decl.GetID();
-      },
-      [&]()->std::string {
-        return ReplaceAll(
-            is_proxy ? CB_CALLBACK_CTOR_PROXY : CB_CALLBACK_CTOR_STUB,
-            "##", decl.GetID());
-      },
-      [&]()->std::string {
+  ReplaceAll(CB_CALLBACK_CLASS)
+      .Select("<CTOR>",
+          { CB_CALLBACK_CTOR_PROXY, CB_CALLBACK_CTOR_STUB }, [&]() {
+        if (is_proxy)
+          return 0;
+        return 1;
+      })
+      .Change("<CLS_NAME>", decl.GetID())
+      .Change("<PUBLIC_MEMBERS>", [&]() {
         std::string ret;
         if (is_proxy) {
           ret = Tab(2) + "virtual void OnReceived("
@@ -733,10 +735,11 @@ void CppCionGeneratorBase::GenHeaderCallback(std::ofstream& stream,
         }
 
         return ret;
-      },
-      [&]()->std::string {
+      })
+      .Change("<PRIVATE_MEMBERS>", [&]() {
         return is_proxy ? CB_CALLBACK_PRIVATE_PROXY : CB_CALLBACK_PRIVATE_STUB;
-      });
+      })
+      .Out(stream);
 }
 
 void CppCionGeneratorBase::GenVersion(std::ofstream& stream) {
index bfc8585..d6043c9 100644 (file)
@@ -164,17 +164,17 @@ R"__cpp_cb(
 
 const char CB_CALLBACK_CLASS[] =
 R"__cpp_cb(
-  class $$ : public CallbackBase {
-   public:$$
-$$
-   private:$$
+  class <CLS_NAME> : public CallbackBase {
+   public:<CTOR>
+<PUBLIC_MEMBERS>
+   private:<PRIVATE_MEMBERS>
   };
 )__cpp_cb";
 
 const char CB_CALLBACK_CTOR_STUB[] =
 R"__cpp_cb(
-    ##(std::weak_ptr<ServiceBase> service, cion_server_h cion_server)
-        : CallbackBase(static_cast<int>(DelegateId::##), false) {
+    <CLS_NAME>(std::weak_ptr<ServiceBase> service, cion_server_h cion_server)
+        : CallbackBase(static_cast<int>(DelegateId::<CLS_NAME>), false) {
       service_ = std::move(service);
       cion_server_ = cion_server;
     }
@@ -182,8 +182,8 @@ R"__cpp_cb(
 
 const char CB_CALLBACK_CTOR_PROXY[] =
 R"__cpp_cb(
-    ##(bool once = false)
-        : CallbackBase(static_cast<int>(DelegateId::##), once) {}
+    <CLS_NAME>(bool once = false)
+        : CallbackBase(static_cast<int>(DelegateId::<CLS_NAME>), once) {}
 )__cpp_cb";
 
 const char CB_CALLBACK_PRIVATE_PROXY[] =