7 #ifndef INCLUDE_SPARROW_EMBED_COMMON_H
8 #define INCLUDE_SPARROW_EMBED_COMMON_H
10 #include "boost/optional.hpp"
15 inline std::ostream& sep(std::ostream& os) {
20 inline std::ostream& nl(std::ostream& os) {
25 inline std::string sp(
unsigned i) {
26 return std::string(i,
' ');
30 std::vector<std::string> includes;
31 std::vector<std::string> namespaces;
32 boost::optional<std::string> guard = boost::none;
34 void writeHeader(std::ostream& os) {
38 os << R
"delim(/**
* @file
* @copy)delim"
39 << R"delim(right This code is licensed under the 3-clause BSD license.\n
* Copyright ETH Zurich, Laboratory of Physical Chemistry, Reiher Group.\n
* See LICENSE.txt for details.
*
* @note This file was generated by the Embed binary from runtime values.
* Prefer improving the generator over editing this file whenever possible.
*
)delim";
43 os << R
"delim( * This file contains functions generating runtime values. It was
* generated from runtime values of its return type. It is not intended to be
* human-readable. A small guide: Return values are directly brace-initialized
* in deep nesting to keep file size to a minimum. Types are annotated only when
* necessary. Floating point values are represented in hexadecimal (see
* std::hexfloat) to ensure serialization does not cause loss of accuracy.
*
* The functions defined here might be declared and called elsewhere entirely.
*
)delim";
46 os << R"delim( */
)delim";
49 os <<
"#ifndef " << guard.value() << nl;
50 os <<
"#define " << guard.value() << nl << nl;
53 for (
auto& include : includes) {
54 if (include[0] ==
'<' || include[0] ==
'\"') {
55 os <<
"#include " << include << nl;
58 os <<
"#include \"" << include <<
"\"" << nl;
63 for (
auto& name : namespaces) {
64 os <<
"namespace " << name <<
" {" << nl;
70 void writeFooter(std::ostream& os) {
72 for (
auto iter = std::rbegin(namespaces); iter != std::rend(namespaces); ++iter) {
73 os <<
"} // namespace " << *iter << nl;
82 inline std::string lower(std::string a) {
83 std::transform(std::begin(a), std::end(a), std::begin(a), [](
unsigned char c) {
return std::tolower(c); });
87 inline std::string upper(std::string a) {
88 std::transform(std::begin(a), std::end(a), std::begin(a), [](
unsigned char c) {
return std::toupper(c); });
94 template<
typename Arg>
95 void writePack(std::ostream& os, Arg arg) {
99 template<
typename Arg,
typename... Args>
100 void writePack(std::ostream& os, Arg arg1, Args... args) {
102 writePack(os, args...);
105 template<
typename Tuple, std::size_t... Inds>
106 void writeTuplePackHelper(std::ostream& os,
const Tuple& tup, std::index_sequence<Inds...>
108 writePack(os, std::get<Inds>(tup)...);
111 template<
typename Tuple>
112 void writeTuplePack(std::ostream& os,
const Tuple& tup) {
113 writeTuplePackHelper(os, tup, std::make_index_sequence<std::tuple_size<Tuple>::value>{});
118 template<
typename... Args>
120 Joiner(
const Args&... args) : bound(args...) {
123 std::tuple<
const Args&...> bound;
126 template<
typename... Args>
127 auto join(
const Args&... args) {
128 return Joiner<Args...>(args...);
131 template<
typename... Args>
132 std::ostream& operator<<(std::ostream& os,
const Joiner<Args...>& join) {
133 detail::writeTuplePack(os, join.bound);
144 boost::optional<T> optional;
148 auto wrapOptional(
const boost::optional<T>& optional) {
153 std::ostream& operator<<(std::ostream& os, const OptionalWrapper<T>& o) {
155 os << o.optional.value();