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:
vitaut 2015-06-10 08:49:22 -07:00
parent 4325c155f7
commit a98583dde3
2 changed files with 30 additions and 23 deletions

View File

@ -586,11 +586,13 @@ FMT_FUNC void fmt::internal::format_windows_error(
#endif #endif
template <typename Char> template <typename Char>
void fmt::ArgList::Map<Char>::init(const ArgList &args) { void fmt::internal::ArgMap<Char>::init(const ArgList &args) {
if (!map_.empty()) if (!map_.empty())
return; return;
const internal::NamedArg<Char>* named_arg; typedef internal::NamedArg<Char> NamedArg;
bool use_values = args.type(MAX_PACKED_ARGS - 1) == internal::Arg::NONE; const NamedArg* named_arg = 0;
bool use_values =
args.type(ArgList::MAX_PACKED_ARGS - 1) == internal::Arg::NONE;
if (use_values) { if (use_values) {
for (unsigned i = 0;/*nothing*/; ++i) { for (unsigned i = 0;/*nothing*/; ++i) {
internal::Arg::Type arg_type = args.type(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: case internal::Arg::NONE:
return; return;
case internal::Arg::NAMED_ARG: 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)); map_.insert(Pair(named_arg->name, *named_arg));
break; break;
default: default:
@ -607,19 +609,19 @@ void fmt::ArgList::Map<Char>::init(const ArgList &args) {
} }
return; 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); internal::Arg::Type arg_type = args.type(i);
if (arg_type == internal::Arg::NAMED_ARG) { 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)); 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) { switch (args.args_[i].type) {
case internal::Arg::NONE: case internal::Arg::NONE:
return; return;
case internal::Arg::NAMED_ARG: 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)); map_.insert(Pair(named_arg->name, *named_arg));
break; break;
default: default:

View File

@ -972,7 +972,8 @@ class MakeValue : public Arg {
return IsConvertibleToInt<T>::value ? Arg::INT : Arg::CUSTOM; 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_> template <typename Char_>
MakeValue(const NamedArg<Char_> &value) { pointer = &value; } MakeValue(const NamedArg<Char_> &value) { pointer = &value; }
@ -1110,6 +1111,9 @@ class RuntimeError : public std::runtime_error {
template <typename Char> template <typename Char>
class ArgFormatter; class ArgFormatter;
template <typename Char>
class ArgMap;
} // namespace internal } // namespace internal
/** An argument list. */ /** An argument list. */
@ -1135,13 +1139,13 @@ class ArgList {
(types_ & (mask << shift)) >> shift); (types_ & (mask << shift)) >> shift);
} }
template <typename Char>
friend class internal::ArgMap;
public: public:
// Maximum number of arguments with packed types. // Maximum number of arguments with packed types.
enum { MAX_PACKED_ARGS = 16 }; enum { MAX_PACKED_ARGS = 16 };
template <typename Char>
struct Map;
ArgList() : types_(0) {} ArgList() : types_(0) {}
ArgList(ULongLong types, const internal::Value *values) ArgList(ULongLong types, const internal::Value *values)
@ -1176,11 +1180,19 @@ class ArgList {
} }
}; };
struct FormatSpec;
namespace internal {
template <typename Char> template <typename Char>
struct fmt::ArgList::Map { class ArgMap {
private:
typedef std::map<fmt::BasicStringRef<Char>, internal::Arg> MapType; typedef std::map<fmt::BasicStringRef<Char>, internal::Arg> MapType;
typedef typename MapType::value_type Pair; typedef typename MapType::value_type Pair;
MapType map_;
public:
void init(const ArgList &args); void init(const ArgList &args);
const internal::Arg* find(const fmt::BasicStringRef<Char> &name) const { const internal::Arg* find(const fmt::BasicStringRef<Char> &name) const {
@ -1189,16 +1201,8 @@ struct fmt::ArgList::Map {
return &it->second; return &it->second;
return 0; return 0;
} }
private:
MapType map_;
}; };
struct FormatSpec;
namespace internal {
class FormatterBase { class FormatterBase {
protected: protected:
ArgList args_; ArgList args_;
@ -1255,7 +1259,7 @@ class BasicFormatter : private internal::FormatterBase {
private: private:
BasicWriter<Char> &writer_; BasicWriter<Char> &writer_;
const Char *start_; const Char *start_;
ArgList::Map<Char> map_; internal::ArgMap<Char> map_;
FMT_DISALLOW_COPY_AND_ASSIGN(BasicFormatter); 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 // Checks if manual indexing is used and returns the argument with
// specified name. // 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. // Parses argument index and returns corresponding argument.
internal::Arg parse_arg_index(const Char *&s); internal::Arg parse_arg_index(const Char *&s);