def generate():
    output = licence_header_cpp(__file__)
    output += ["#include \"typedefs.hxx\""]

    output += NAMESPACE_OPEN
    for dtype in constants.DTYPES:
        output.append("template struct ArrayView<{0:}>;".format(to_cpp_type(dtype)))
    output += NAMESPACE_CLOSE
    return "\n".join(output)
Exemple #2
0
def generate():
    output = licence_header_cpp(__file__)
    output += ["#include \"typedefs.hxx\""]

    output += NAMESPACE_OPEN
    for cpptype in make_supported_cpp_types(constants.DTYPES):
        output.append("template const {0:}& PamMap::at<{0:}>("
                      "const std::string& key, const {0:}& default_value) "
                      "const;".format(cpptype))
        output.append(
            "template {0:}& PamMap::at<{0:}>(const std::string& key, "
            "{0:}& default_value);".format(cpptype))

    output += NAMESPACE_CLOSE

    return clang_format("\n".join(output))
def generate():
    output = licence_header_cpp(__file__)
    output.append("#pragma once")
    for hdr in constants.cpp.headers:
        output.append("#include " + hdr)

    output += [
        "",
        "// Typedefs mapping the dtype names to their underlying C++ types",
    ]

    output += NAMESPACE_OPEN
    for dtype in constants.DTYPES:
        underlying_type = constants.cpp.underlying_type[dtype]
        output += [
            "typedef " + underlying_type + " " + to_cpp_type(dtype) + ";"
        ]
    output += NAMESPACE_CLOSE
    return "\n".join(output)
def generate():
    output = licence_header_cpp(__file__)
    output += ["#include \"typedefs.hxx\""]
    output += ["#include <type_traits>"]

    output += NAMESPACE_OPEN
    output += [
        "/** Is the type T supported by pammap for storage. */",
        "template <typename T>",
        "struct IsSupportedType : public std::false_type {};",
    ]

    for cpptype in make_supported_cpp_types(constants.DTYPES):
        output += [
            "",
            "/** Specialisation of IsSupportedType<T> for " + cpptype + ".*/",
            "template <>",
            "struct IsSupportedType<" + cpptype +
            "> : public std::true_type {};",
        ]

    output += NAMESPACE_CLOSE
    return "\n".join(output)
def generate():
    output = licence_header_cpp(__file__)
    output += [
        r"#pragma once",
        r'#include "ArrayView.hpp"',
        r'#include "IsSupportedType.hxx"',
        r'#include "any.hpp"',
        r'#include "typedefs.hxx"',
    ]
    output += NAMESPACE_OPEN

    # Add class header
    output += clean_block(r"""
    /** \brief Class to contain an entry value in a PamMap.
        Essentially a slightly specialised pammap::any */
    class PamMapValue : public any {
     public:
    """)

    # Add fallback constructors
    output += clean_block(r"""
      PamMapValue() = default;

      /** Catch-all constructor, which defaults to an error */
      template <typename ValueType>
      PamMapValue(ValueType) : PamMapValue() {
        static_assert(!std::is_unsigned<ValueType>::value,
                      "Unsigned integer types are not supported with PamMap. "
                      "Use a signed type instead.");

        static_assert(IsSupportedType<ValueType>::value,
                      "This value type is not supported by PamMap.");
      }
    """)
    output.append("")

    # Auto-generate constructors
    for cpptype in make_supported_cpp_types(constants.DTYPES):
        output += [
            "  /** Construction from " + cpptype + " */",
            "  PamMapValue(" + cpptype + " val) : any(std::move(val)) {}", ""
        ]

    # Add transforming constructors
    output += clean_block(r"""
      //
      // The int type gets special treatment because it is the default for raw numbers
      //
      /** \brief Make an PamMapValue out of an int. Behaves like a PamMapValue
       *         containing an INTEGER type */
      PamMapValue(int i) : PamMapValue(static_cast<Integer>(i)) {}

      //
      // Same for const char*
      //
      /** \brief Make an PamMapValue out of a const char*.
       *  This behaves like the equivalent GenMapValue of a std::string */
      PamMapValue(const char* s) : PamMapValue(std::string(s)) {}
    """)
    output.append("")

    # Add type_name() method
    output += clean_block(r"""
      /** Return the demangled typename of the type of the internal object. */
      std::string type_name() const;
    """)

    # Close class and namespace
    output += ["};"]
    output += NAMESPACE_CLOSE
    return "\n".join(output)