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) {
}
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) {
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) {
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) },
{ "<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
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) },
{ "<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) {
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() },
{ "<PARAM_TYPE_OUT>", param_type_out },
{ "<BASE_SET>", GenBaseSet(elm) },
{ "<BASE_GET>", GenBaseGet(elm) }
- });
+ }));
code += set_get_code;
}
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) {
// @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
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
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);
}
}
// @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) {
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
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,
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() },
{ "<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
"_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;
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
}
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,
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;
}
}
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;
}
// @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;
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
// @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);
}
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);
}
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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
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() },
{ "<DELEGATE_PARAMS_CHECK>", GenDelegateParamsCheck(iface, decl) },
{ "<DELEGATE_ENUM_VALUE>", enum_value },
{ "<DELEGATE_PARCEL_WRITE>", GenDelegateParcelWrite(iface, decl) }
- });
+ }));
stream << SmartIndent(code);
}
// @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_ = ");
// @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() },
{ "<METHOD_HANDLER_PARCEL_WRITE>",
GenMethodHandlerParcelWrite(iface, decl) },
{ "<METHOD_HANDLER_ARGS_FREE>", GenMethodHandlerArgsFree(iface, decl) }
- });
+ }));
stream << SmartIndent(code);
}
"_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);
}
// @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);
}
// @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);
}
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;
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
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);
// @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);
}
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("
}
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) {
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);
}
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[] =
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()) {
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);
}
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)
#include "idlc/ast/document.h"
#include "idlc/ast/parameter.h"
#include "idlc/ast/type.h"
+#include "idlc/gen/replace_all.h"
namespace tidl {
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);
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_
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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_
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;
}
// @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());
// @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);
// @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();
// @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());
// @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());
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());
// @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();
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) {
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
// @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
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);
}
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() },
{ "<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_ = ");
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;
}
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) {
// @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
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);
// @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
// @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);
}
}
// @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) {
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
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,
// @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
"_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
}
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,
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;
}
}
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;
}
// @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;
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
// @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));
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(),
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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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_ = ");
// @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);
}
"_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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
// @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);
}
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);
// @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);
}
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;
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);
}
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("
}
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) {
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;
}
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[] =