PLaSK library

Loading...
Searching...
No Matches
format.hpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef PLASK__UTILS_FORMAT_H
15#define PLASK__UTILS_FORMAT_H
16
21#include <complex>
22
23//#include <plask/config.hpp>
24#include <boost/lexical_cast.hpp>
25#include "fmt/format.h"
26#include "fmt/ostream.h"
27
28 namespace plask {
29
30 using fmt::format;
31
36 template <typename T>
37 inline std::string str(T x) {
38 return boost::lexical_cast<std::string>(x);
39}
40
46 inline std::string str(double x, const char* fmt="{:.9g}") {
47 return format(fmt, x);
48}
49
56 inline std::string str(std::complex<double> x, const char* fmt="{:.9g}{:+0.9g}j", const char* rfmt=nullptr) {
57 if (!rfmt || imag(x) != 0.)
58 return format(fmt, real(x), imag(x));
59 else
60 return format(rfmt, real(x));
61}
62
63} // namespace plask
64
65#endif // PLASK__FORMAT_UTILS_H