From 0c71feb0363b337152f11e301303f85f9621c148 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 20 Jul 2017 08:55:31 +0200 Subject: Add modularized version --- libmformat/libmformat/buildfile | 15 +++++++++++++++ libmformat/libmformat/format.cxx | 31 +++++++++++++++++++++++++++++++ libmformat/libmformat/format.mxx | 13 +++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 libmformat/libmformat/buildfile create mode 100644 libmformat/libmformat/format.cxx create mode 100644 libmformat/libmformat/format.mxx (limited to 'libmformat/libmformat') diff --git a/libmformat/libmformat/buildfile b/libmformat/libmformat/buildfile new file mode 100644 index 0000000..24acee5 --- /dev/null +++ b/libmformat/libmformat/buildfile @@ -0,0 +1,15 @@ +import libs = libstd-modules%liba{std-modules} + +lib{mformat}: {mxx cxx}{format} $libs + +# For pre-releases use the complete version to make sure they cannot be used +# in place of another pre-release or the final version. +# +if $version.pre_release + lib{mformat}: bin.lib.version = @"-$version.project_id" +else + lib{mformat}: bin.lib.version = @"-$version.major.$version.minor" + +# Install into the libmformat/ subdirectory of, say, /usr/include/. +# +install.include = $install.include/$project/ diff --git a/libmformat/libmformat/format.cxx b/libmformat/libmformat/format.cxx new file mode 100644 index 0000000..fe6ad15 --- /dev/null +++ b/libmformat/libmformat/format.cxx @@ -0,0 +1,31 @@ +// file: libmformat/format.cxx -*- C++ -*- + +module format; + +import std.core; // transform() +import std.io; // to{upper,lower}() + +using namespace std; + +namespace format +{ + string + message (const string& g, const string& n, volume v) + { + string r (g); + + auto tr = [&r] (char (*t) (char)) + { + transform (r.begin (), r.end (), r.begin (), t); + }; + + switch (v) + { + case volume::quiet: tr ([](char c) -> char {return tolower (c);}); break; + case volume::normal: break; + case volume::loud: tr ([](char c) -> char {return toupper (c);}); break; + } + + return r += ", " + n + '!'; + } +} diff --git a/libmformat/libmformat/format.mxx b/libmformat/libmformat/format.mxx new file mode 100644 index 0000000..c1e69ee --- /dev/null +++ b/libmformat/libmformat/format.mxx @@ -0,0 +1,13 @@ +// file: libmformat/format.mxx -*- C++ -*- + +export module format; + +import std.core; + +export namespace format +{ + enum class volume {quiet, normal, loud}; + + __symexport std::string + message (const std::string& greeting, const std::string& name, volume); +} -- cgit v1.1