mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 12:14:26 +00:00
Move ArgList::Map to the internal namespace and rename to ArgMap
since it shouldn't be a part of the public API. Also break long lines.
This commit is contained in:
parent
4325c155f7
commit
a98583dde3
18
format.cc
18
format.cc
@ -586,11 +586,13 @@ FMT_FUNC void fmt::internal::format_windows_error(
|
||||
#endif
|
||||
|
||||
template <typename Char>
|
||||
void fmt::ArgList::Map<Char>::init(const ArgList &args) {
|
||||
void fmt::internal::ArgMap<Char>::init(const ArgList &args) {
|
||||
if (!map_.empty())
|
||||
return;
|
||||
const internal::NamedArg<Char>* named_arg;
|
||||
bool use_values = args.type(MAX_PACKED_ARGS - 1) == internal::Arg::NONE;
|
||||
typedef internal::NamedArg<Char> NamedArg;
|
||||
const NamedArg* named_arg = 0;
|
||||
bool use_values =
|
||||
args.type(ArgList::MAX_PACKED_ARGS - 1) == internal::Arg::NONE;
|
||||
if (use_values) {
|
||||
for (unsigned i = 0;/*nothing*/; ++i) {
|
||||
internal::Arg::Type arg_type = args.type(i);
|
||||
@ -598,7 +600,7 @@ void fmt::ArgList::Map<Char>::init(const ArgList &args) {
|
||||
case internal::Arg::NONE:
|
||||
return;
|
||||
case internal::Arg::NAMED_ARG:
|
||||
named_arg = static_cast<const internal::NamedArg<Char>*>(args.values_[i].pointer);
|
||||
named_arg = static_cast<const NamedArg*>(args.values_[i].pointer);
|
||||
map_.insert(Pair(named_arg->name, *named_arg));
|
||||
break;
|
||||
default:
|
||||
@ -607,19 +609,19 @@ void fmt::ArgList::Map<Char>::init(const ArgList &args) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (unsigned i = 0; i != MAX_PACKED_ARGS; ++i) {
|
||||
for (unsigned i = 0; i != ArgList::MAX_PACKED_ARGS; ++i) {
|
||||
internal::Arg::Type arg_type = args.type(i);
|
||||
if (arg_type == internal::Arg::NAMED_ARG) {
|
||||
named_arg = static_cast<const internal::NamedArg<Char>*>(args.args_[i].pointer);
|
||||
named_arg = static_cast<const NamedArg*>(args.args_[i].pointer);
|
||||
map_.insert(Pair(named_arg->name, *named_arg));
|
||||
}
|
||||
}
|
||||
for (unsigned i = MAX_PACKED_ARGS;/*nothing*/; ++i) {
|
||||
for (unsigned i = ArgList::MAX_PACKED_ARGS;/*nothing*/; ++i) {
|
||||
switch (args.args_[i].type) {
|
||||
case internal::Arg::NONE:
|
||||
return;
|
||||
case internal::Arg::NAMED_ARG:
|
||||
named_arg = static_cast<const internal::NamedArg<Char>*>(args.args_[i].pointer);
|
||||
named_arg = static_cast<const NamedArg*>(args.args_[i].pointer);
|
||||
map_.insert(Pair(named_arg->name, *named_arg));
|
||||
break;
|
||||
default:
|
||||
|
35
format.h
35
format.h
@ -972,7 +972,8 @@ class MakeValue : public Arg {
|
||||
return IsConvertibleToInt<T>::value ? Arg::INT : Arg::CUSTOM;
|
||||
}
|
||||
|
||||
// Additional template param `Char_` is needed here because make_type always uses MakeValue<char>.
|
||||
// Additional template param `Char_` is needed here because make_type always
|
||||
// uses MakeValue<char>.
|
||||
template <typename Char_>
|
||||
MakeValue(const NamedArg<Char_> &value) { pointer = &value; }
|
||||
|
||||
@ -1110,6 +1111,9 @@ class RuntimeError : public std::runtime_error {
|
||||
|
||||
template <typename Char>
|
||||
class ArgFormatter;
|
||||
|
||||
template <typename Char>
|
||||
class ArgMap;
|
||||
} // namespace internal
|
||||
|
||||
/** An argument list. */
|
||||
@ -1135,13 +1139,13 @@ class ArgList {
|
||||
(types_ & (mask << shift)) >> shift);
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
friend class internal::ArgMap;
|
||||
|
||||
public:
|
||||
// Maximum number of arguments with packed types.
|
||||
enum { MAX_PACKED_ARGS = 16 };
|
||||
|
||||
template <typename Char>
|
||||
struct Map;
|
||||
|
||||
ArgList() : types_(0) {}
|
||||
|
||||
ArgList(ULongLong types, const internal::Value *values)
|
||||
@ -1176,11 +1180,19 @@ class ArgList {
|
||||
}
|
||||
};
|
||||
|
||||
struct FormatSpec;
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename Char>
|
||||
struct fmt::ArgList::Map {
|
||||
class ArgMap {
|
||||
private:
|
||||
typedef std::map<fmt::BasicStringRef<Char>, internal::Arg> MapType;
|
||||
typedef typename MapType::value_type Pair;
|
||||
|
||||
MapType map_;
|
||||
|
||||
public:
|
||||
void init(const ArgList &args);
|
||||
|
||||
const internal::Arg* find(const fmt::BasicStringRef<Char> &name) const {
|
||||
@ -1189,16 +1201,8 @@ struct fmt::ArgList::Map {
|
||||
return &it->second;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
MapType map_;
|
||||
};
|
||||
|
||||
struct FormatSpec;
|
||||
|
||||
namespace internal {
|
||||
|
||||
class FormatterBase {
|
||||
protected:
|
||||
ArgList args_;
|
||||
@ -1255,7 +1259,7 @@ class BasicFormatter : private internal::FormatterBase {
|
||||
private:
|
||||
BasicWriter<Char> &writer_;
|
||||
const Char *start_;
|
||||
ArgList::Map<Char> map_;
|
||||
internal::ArgMap<Char> map_;
|
||||
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(BasicFormatter);
|
||||
|
||||
@ -1263,7 +1267,8 @@ class BasicFormatter : private internal::FormatterBase {
|
||||
|
||||
// Checks if manual indexing is used and returns the argument with
|
||||
// specified name.
|
||||
internal::Arg get_arg(const BasicStringRef<Char>& arg_name, const char *&error);
|
||||
internal::Arg get_arg(const BasicStringRef<Char>& arg_name,
|
||||
const char *&error);
|
||||
|
||||
// Parses argument index and returns corresponding argument.
|
||||
internal::Arg parse_arg_index(const Char *&s);
|
||||
|
Loading…
Reference in New Issue
Block a user