Example #1
0
void string_helper::
format(assistant& a, const formattables::helper_properties& /*hp*/) const {
a.stream() << "inline std::string tidy_up_string(std::string s) {" << std::endl;
a.stream() << "    boost::replace_all(s, \"\\r\\n\", \"<new_line>\");" << std::endl;
a.stream() << "    boost::replace_all(s, \"\\n\", \"<new_line>\");" << std::endl;
a.stream() << "    boost::replace_all(s, \"\\\"\", \"<quote>\");" << std::endl;
a.stream() << "    return s;" << std::endl;
a.stream() << "}" << std::endl;
a.stream() << std::endl;
}
Example #2
0
void char_helper::
format(assistant& a, const formattables::helper_properties& hp) const {
    const auto d(hp.current());
    const auto qn(d.name_tree_qualified());
    const auto ident(d.name_tree_identifiable());
a.stream() << std::endl;
a.stream() << qn << " create_" << ident << "(const unsigned int position) {" << std::endl;
a.stream() << "    return static_cast<" << qn << ">(((position % 95) + 32) == 34) ? 35 : ((position % 95) + 32);" << std::endl;
a.stream() << "}" << std::endl;
}
Example #3
0
void smart_pointer_helper::
format(assistant& a, const formattables::helper_properties& hp) const {
    {
        const auto d(hp.current());
        const auto nt_qn(d.name_tree_qualified());
        const auto n_qn(d.name_qualified());
        auto snf(a.make_scoped_namespace_formatter(d.namespaces()));
        const auto containee(hp.direct_descendants().front());
a.stream() << std::endl;
a.stream() << "inline std::ostream& operator<<(std::ostream& s, const " << nt_qn << "& v) {" << std::endl;
a.stream() << "    s << \"{ \" << \"\\\"__type__\\\": \" << \"\\\"" << n_qn << "\\\"\" << \", \"" << std::endl;
a.stream() << "      << \"\\\"memory\\\": \" << \"\\\"\" << static_cast<void*>(v.get()) << \"\\\"\" << \", \";" << std::endl;
a.stream() << std::endl;
a.stream() << "    if (v)" << std::endl;
a.stream() << "        s << \"\\\"data\\\": \" << " << a.streaming_for_type(containee, "*v") << ";" << std::endl;
a.stream() << "    else" << std::endl;
a.stream() << "        s << \"\\\"data\\\": \"\"\\\"<null>\\\"\";" << std::endl;
a.stream() << "    s << \" }\";" << std::endl;
a.stream() << "    return s;" << std::endl;
a.stream() << "}" << std::endl;
a.stream() << std::endl;
    }
a.stream() << std::endl;
}
dogen::formatters::file forward_declarations_formatter_stitch(
    assistant& a, const formattables::forward_declarations_info& fd) {

    {
        auto sbf(a.make_scoped_boilerplate_formatter());
        {
            auto snf(a.make_scoped_namespace_formatter(fd.namespaces()));

            if (fd.is_enum()) {
a.stream() << std::endl;
a.stream() << "enum class " << fd.name() << " : " << fd.enum_type() << ";" << std::endl;
a.stream() << std::endl;
            } else {
a.stream() << std::endl;
a.stream() << "class " << fd.name() << ";" << std::endl;
a.stream() << std::endl;
            }
        } // snf
a.stream() << std::endl;
    } // sbf
    return a.make_file();
}
Example #5
0
void optional_helper::
format(assistant& a, const formattables::helper_properties& hp) const {
    const auto d(hp.current());
    const auto qn(d.name_tree_qualified());
    const auto ident(d.name_tree_identifiable());
    const auto containee(hp.direct_descendants().front());
a.stream() << std::endl;
a.stream() << "inline std::size_t hash_" << ident << "(const " << qn << "& v) {" << std::endl;
a.stream() << "    std::size_t seed(0);" << std::endl;
a.stream() << std::endl;
a.stream() << "    if (!v)" << std::endl;
a.stream() << "        return seed;" << std::endl;
a.stream() << std::endl;
    if (!containee.requires_hashing_helper())
a.stream() << "    combine(seed, *v);" << std::endl;
    else
a.stream() << "    combine(seed, hash_" << containee.name_tree_identifiable() << "(*v));" << std::endl;
a.stream() << "    return seed;" << std::endl;
a.stream() << "}" << std::endl;
}
Example #6
0
void ptime_helper::
format(assistant& a, const formattables::helper_properties& hp) const {
    const auto d(hp.current());
    const auto qn(d.name_tree_qualified());
    const auto ident(d.name_tree_identifiable());
a.stream() << std::endl;
a.stream() << qn << std::endl;
a.stream() << "create_" << ident << "(const unsigned int position) {" << std::endl;
a.stream() << "    unsigned int day(1 + (position % 27));" << std::endl;
a.stream() << "    using boost::gregorian::date;" << std::endl;
a.stream() << "    using boost::posix_time::ptime;" << std::endl;
a.stream() << "    using boost::posix_time::time_duration;" << std::endl;
a.stream() << "    date d(2002, 2, day);" << std::endl;
a.stream() << "    ptime r(d, time_duration(1,2,3));" << std::endl;
a.stream() << "    return r;" << std::endl;
a.stream() << "}" << std::endl;
}
dogen::formatters::file class_implementation_formatter_stitch(
    assistant& a, const formattables::class_info& c) {

    {
        auto sbf(a.make_scoped_boilerplate_formatter());
        a.add_helper_methods(c);

        {
            auto snf(a.make_scoped_namespace_formatter(c.namespaces()));
            const bool no_arg(!c.is_parent() && c.parents().empty() &&
                c.properties().empty());
a.stream() << std::endl;
a.stream() << "std::ostream& operator<<(std::ostream& s, const " << c.name() << "&" << (no_arg ? "" : " v") << ") {" << std::endl;
            if (c.is_parent() || !c.parents().empty()) {
a.stream() << "    v.to_stream(s);" << std::endl;
a.stream() << "    return(s);" << std::endl;
            } else
                io::inserter_implementation_helper_stitch(a, c, false/*inside_class*/);
a.stream() << "}" << std::endl;
a.stream() << std::endl;
        } // snf
    } // sbf
    return a.make_file();
}
Example #8
0
void associative_container_helper::
format(assistant& a, const formattables::helper_properties& hp) const {
    const auto d(hp.current());
    const auto qn(d.name_tree_qualified());
    const auto ident(d.name_tree_identifiable());
a.stream() << std::endl;
a.stream() << qn << " create_" << ident << "(unsigned int position) {" << std::endl;
a.stream() << "    " << qn << " r;" << std::endl;
a.stream() << "    for (unsigned int i(0); i < 4; ++i) {" << std::endl;
    if (hp.direct_descendants().size() == 1) {
        const auto containee(hp.direct_descendants().front());
a.stream() << "        r.insert(create_" << containee.name_tree_identifiable() << "(position + i));" << std::endl;
    } else if (hp.direct_descendants().size() == 2) {
        const auto key(hp.direct_descendants().front());
        const auto value(hp.direct_descendants().back());
a.stream() << "        r.insert(std::make_pair(create_" << key.name_tree_identifiable() << "(position + i), create_" << value.name_tree_identifiable() << "(position + i)));" << std::endl;
    }
a.stream() << "    }" << std::endl;
a.stream() << "    return r;" << std::endl;
a.stream() << "}" << std::endl;
}
dogen::formatters::file class_header_formatter_stitch(
    assistant& a, const formattables::class_info& c) {

    {
        auto sbf(a.make_scoped_boilerplate_formatter());
        const auto odbs(a.get_odb_settings());
        if (!odbs || odbs->pragmas().empty()) {
a.stream() << "// class has no ODB pragmas defined." << std::endl;
a.stream() << std::endl;
        } else {
            {
                auto snf(a.make_scoped_namespace_formatter(c.namespaces()));

a.stream() << std::endl;
a.stream() << "#ifdef ODB_COMPILER" << std::endl;
a.stream() << std::endl;
                const std::string odb_key("odb_pragma");
                for (const auto& pg : odbs->pragmas())
a.stream() << "#pragma db object(" << c.name() << ") " << pg << std::endl;

                bool is_first(true);
                for (const auto p : c.properties()) {
                    const auto podbs(a.get_odb_settings(p.id()));
                    if (podbs) {
                        for (const auto pg : podbs->pragmas()) {
                            if (is_first)
a.stream() << std::endl;
                            is_first = false;
a.stream() << "#pragma db member(" << c.name() << "::" << a.make_member_variable_name(p) << ") " << pg << std::endl;
                        }
                    }
                }
a.stream() << std::endl;
a.stream() << "#endif" << std::endl;
a.stream() << std::endl;
            }
a.stream() << std::endl;
        }
    } // sbf
    return a.make_file();
}
dogen::formatters::file enum_implementation_formatter_stitch(
    assistant& a, const yarn::enumeration& e) {

    {
        auto sbf(a.make_scoped_boilerplate_formatter());
        {
            const auto ns(a.make_namespaces(e.name()));
            auto snf(a.make_scoped_namespace_formatter(ns));
a.stream() << std::endl;
a.stream() << e.name().simple() << "_generator::" << e.name().simple() << "_generator() : position_(0) { }" << std::endl;
a.stream() << "void " << e.name().simple() << "_generator::" << std::endl;
a.stream() << "populate(const unsigned int position, result_type& v) {" << std::endl;
a.stream() << "    v = static_cast<" << e.name().simple() << ">(position % " << e.enumerators().size() << ");" << std::endl;
a.stream() << "}" << std::endl;
a.stream() << std::endl;
a.stream() << e.name().simple() << "_generator::result_type" << std::endl;
a.stream() << e.name().simple() << "_generator::create(const unsigned int  position) {" << std::endl;
a.stream() << "    result_type r;" << std::endl;
a.stream() << "    " << e.name().simple() << "_generator::populate(position, r);" << std::endl;
a.stream() << "    return r;" << std::endl;
a.stream() << "}" << std::endl;
a.stream() << std::endl;
a.stream() << e.name().simple() << "_generator::result_type" << std::endl;
a.stream() << e.name().simple() << "_generator::operator()() {" << std::endl;
a.stream() << "    return create(position_++);" << std::endl;
a.stream() << "}" << std::endl;
a.stream() << std::endl;
         } // snf
    } // sbf
    return a.make_file();
}
Example #11
0
bool string_helper::is_enabled(const assistant& a,
    const formattables::helper_properties& hp) const {
    return a.is_streaming_enabled(hp);
}
Example #12
0
void associative_container_helper::
format(assistant& a, const formattables::helper_properties& hp) const {
    {
        const auto d(hp.current());
        const auto qn(d.name_tree_qualified());
        auto snf(a.make_scoped_namespace_formatter(d.namespaces()));

        if (hp.direct_descendants().size() == 2) {
            const auto key(hp.direct_descendants().front());
            const auto value(hp.direct_descendants().back());
a.stream() << std::endl;
a.stream() << "inline std::ostream& operator<<(std::ostream& s, const " << qn << "& v) {" << std::endl;
a.stream() << "    s << \"[\";" << std::endl;
a.stream() << "    for (auto i(v.begin()); i != v.end(); ++i) {" << std::endl;
a.stream() << "        if (i != v.begin()) s << \", \";" << std::endl;
a.stream() << "        s << \"[ { \" << \"\\\"__type__\\\": \" << \"\\\"key\\\"\" << \", \" << \"\\\"data\\\": \";" << std::endl;
a.stream() << "        s << " << a.streaming_for_type(key, "i->first") << ";" << std::endl;
a.stream() << "        s << \" }, { \" << \"\\\"__type__\\\": \" << \"\\\"value\\\"\" << \", \" << \"\\\"data\\\": \";" << std::endl;
a.stream() << "        s << " << a.streaming_for_type(value, "i->second") << ";" << std::endl;
a.stream() << "        s << \" } ]\";" << std::endl;
a.stream() << "    }" << std::endl;
a.stream() << "    s << \" ] \";" << std::endl;
a.stream() << "    return s;" << std::endl;
a.stream() << "}" << std::endl;
a.stream() << std::endl;
        } else {
        const auto containee(hp.direct_descendants().front());
a.stream() << std::endl;
a.stream() << "inline std::ostream& operator<<(std::ostream& s, const " << qn << "& v) {" << std::endl;
a.stream() << "    s << \"[ \";" << std::endl;
a.stream() << "    for (auto i(v.begin()); i != v.end(); ++i) {" << std::endl;
a.stream() << "        if (i != v.begin()) s << \", \";" << std::endl;
a.stream() << "        s << " << a.streaming_for_type(containee, "*i") << ";" << std::endl;
a.stream() << "    }" << std::endl;
a.stream() << "    s << \"] \";" << std::endl;
a.stream() << "    return s;" << std::endl;
a.stream() << "}" << std::endl;
a.stream() << std::endl;
        }
    }
a.stream() << std::endl;
}
Example #13
0
bool associative_container_helper::is_enabled(const assistant& a,
    const formattables::helper_properties& hp) const {
    return a.is_streaming_enabled(hp);
}
Example #14
0
void associative_container_helper::
format(assistant& a, const formattables::helper_properties& hp) const {
    const auto d(hp.current());
    const auto qn(d.name_tree_qualified());
    const auto ident(d.name_tree_identifiable());

    if (hp.direct_descendants().size() == 2) {
        const auto key(hp.direct_descendants().front());
        const auto value(hp.direct_descendants().back());
a.stream() << std::endl;
a.stream() << "inline std::size_t hash_" << ident << "(const " << qn << "& v) {" << std::endl;
a.stream() << "    std::size_t seed(0);" << std::endl;
a.stream() << "    for (const auto i : v) {" << std::endl;
        if (!key.requires_hashing_helper())
a.stream() << "        combine(seed, i.first);" << std::endl;
        else
a.stream() << "        combine(seed, hash_" << key.name_tree_identifiable() << "(i.first));" << std::endl;

        if (!(value.requires_hashing_helper()))
a.stream() << "        combine(seed, i.second);" << std::endl;
        else
a.stream() << "        combine(seed, hash_" << value.name_tree_identifiable() << "(i.second));" << std::endl;
a.stream() << "    }" << std::endl;
a.stream() << "    return seed;" << std::endl;
a.stream() << "}" << std::endl;
    } else {
        const auto containee(hp.direct_descendants().front());
a.stream() << std::endl;
a.stream() << "inline std::size_t hash_" << ident << "(const " << qn << "& v) {" << std::endl;
a.stream() << "    std::size_t seed(0);" << std::endl;
a.stream() << "    for (const auto i : v) {" << std::endl;
    if (!containee.requires_hashing_helper())
a.stream() << "        combine(seed, i);" << std::endl;
    else
a.stream() << "        combine(seed, hash_" << containee.name_tree_identifiable() << "(i));" << std::endl;
a.stream() << "    }" << std::endl;
a.stream() << "    return seed;" << std::endl;
a.stream() << "}" << std::endl;
    }
}
dogen::formatters::file odb_options_formatter_stitch(
    assistant& a, const formattables::odb_options_info& i) {

    {
        a.make_annotation_preamble(i.general_settings());
a.stream() << "# enable C++11. FIXME: causes ODB crash in options file." << std::endl;
a.stream() << "# --std c++11" << std::endl;
a.stream() << std::endl;
a.stream() << "# target postgres" << std::endl;
a.stream() << "--database pgsql" << std::endl;
a.stream() << std::endl;
a.stream() << "# use the boost profile" << std::endl;
a.stream() << "--profile boost" << std::endl;
a.stream() << std::endl;
a.stream() << "# generate queries and embedded schemas" << std::endl;
a.stream() << "--generate-query" << std::endl;
a.stream() << "--generate-schema" << std::endl;
a.stream() << "--schema-format embedded" << std::endl;
a.stream() << std::endl;
a.stream() << "# use extensions similar to the dogen ones" << std::endl;
a.stream() << "# --ixx-suffix .ipp" << std::endl;
a.stream() << "# --hxx-suffix .hpp" << std::endl;
a.stream() << "--cxx-suffix .cpp" << std::endl;
a.stream() << std::endl;
a.stream() << "# fix domain includes" << std::endl;
a.stream() << "--include-regex '%(.*).hpp%" << i.product_name() << "/" << i.model_name() << "/types/$1.hpp%'" << std::endl;
a.stream() << std::endl;
a.stream() << "# fix odb generated includes" << std::endl;
a.stream() << "--include-regex '%(^[a-zA-Z0-9_]+)-odb.(.*)%" << i.product_name() << "/" << i.model_name() << "/odb/$1-odb.$2%'" << std::endl;
a.stream() << "--include-regex '%" << i.product_name() << "/" << i.model_name() << "/types/(.*)-odb.(.*)%" << i.product_name() << "/" << i.model_name() << "/odb/$1-odb.$2%'" << std::endl;
a.stream() << std::endl;
a.stream() << "# debug regexes" << std::endl;
a.stream() << "# --include-regex-trace" << std::endl;
a.stream() << std::endl;
a.stream() << "# make the header guards similar to dogen ones" << std::endl;
a.stream() << "--guard-prefix " << boost::to_upper_copy(i.product_name()) << "_" << boost::to_upper_copy(i.model_name()) << "_" << boost::to_upper_copy(i.odb_folder()) << std::endl;
    } // sbf
    return a.make_file(i.file_path());
}
Example #16
0
void inserter_implementation_helper(
    assistant& a, const yarn::object& o, const bool inside_class) {

    const auto qn(a.get_qualified_name(o.name()));

    if (a.requires_stream_manipulators()) {
a.stream() << "    boost::io::ios_flags_saver ifs(s);" << std::endl;
a.stream() << "    s.setf(std::ios_base::boolalpha);" << std::endl;
a.stream() << "    s.setf(std::ios::fixed, std::ios::floatfield);" << std::endl;
a.stream() << "    s.precision(6);" << std::endl;
a.stream() << "    s.setf(std::ios::showpoint);" << std::endl;
a.stream() << std::endl;
    }

    const bool no_parent_and_no_attributes(!o.parent() &&
        o.all_attributes().empty());
a.stream() << "    s << \" { \"" << std::endl;
a.stream() << "      << \"\\\"__type__\\\": \" << \"\\\"" << qn << "\\\"\"" << (no_parent_and_no_attributes ? " << \" }\";" : " << \", \"") << std::endl;

    dogen::formatters::sequence_formatter sf(o.parent() ? 1 : 0);
    sf.prefix_configuration().first("  << ").not_first("s << ");
    sf.element_separator("");
    if (o.parent()) {
        const auto& pn(*o.parent());
        const auto pqn(a.get_qualified_name(pn));
a.stream() << "    " << sf.prefix() << "\"\\\"__parent_" << sf.current_position() << "__\\\": \"" << sf.postfix() << ";" << std::endl;
a.stream() << "    " << pqn << "::to_stream(s);" << std::endl;
        sf.next();
    }

    sf.reset(o.local_attributes().size());

    if (o.parent())
        sf.prefix_configuration().first("s << \", \"\n      ");
    else
        sf.prefix_configuration().first("  ");
    sf.prefix_configuration().not_first("  ");
    sf.postfix_configuration().not_last(" << \", \"");
    sf.element_separator("");

    for (const auto attr : o.local_attributes()) {
        std::string variable_name;
        if (inside_class)
            variable_name = a.make_member_variable_name(attr);
        else
            variable_name = "v." + a.make_getter_setter_name(attr) + "()";

a.stream() << "    " << sf.prefix() << "<< \"\\\"" << attr.name().simple() << "\\\": \" << " << a.streaming_for_type(attr.parsed_type().current(), variable_name) << sf.postfix() << std::endl;
        sf.next();
    }

    if (!no_parent_and_no_attributes) {
        if (!o.local_attributes().empty())
a.stream() << "      << \" }\";" << std::endl;
        else
a.stream() << "    s << \" }\";" << std::endl;
    }

    if (!inside_class)
a.stream() << "    return(s);" << std::endl;
}