Add inline to internal linkage helpers.

This commit is contained in:
Sergey Magidovich 2015-11-12 22:00:37 +03:00
parent 18ba3f2b42
commit a8397934df
5 changed files with 31 additions and 31 deletions

View file

@ -35,7 +35,7 @@
namespace
{
template <typename T, typename SeparatorExtractor>
void PrintVector(std::ostream & ost, std::vector<T> const & v,
inline void PrintVector(std::ostream & ost, std::vector<T> const & v,
SeparatorExtractor && sepFunc)
{
auto it = begin(v);
@ -53,12 +53,12 @@ void PrintVector(std::ostream & ost, std::vector<T> const & v,
}
template <typename T>
void PrintVector(std::ostream & ost, std::vector<T> const & v, char const * const sep = ", ")
inline void PrintVector(std::ostream & ost, std::vector<T> const & v, char const * const sep = ", ")
{
PrintVector(ost, v, [&sep](T const &) { return sep; });
}
void PrintOffset(std::ostream & ost, int32_t const offset, bool const space)
inline void PrintOffset(std::ostream & ost, int32_t const offset, bool const space)
{
if (offset == 0)
return;
@ -92,13 +92,15 @@ class StreamFlagsKeeper
std::ios_base::fmtflags m_flags;
};
void PrintPaddedNumber(std::ostream & ost, uint32_t const number, uint32_t const padding = 1)
inline void PrintPaddedNumber(std::ostream & ost,
uint32_t const number,
uint32_t const padding = 1)
{
StreamFlagsKeeper keeper(ost);
ost << std::setw(padding) << std::setfill('0') << number;
}
void PrintHoursMinutes(std::ostream & ost,
inline void PrintHoursMinutes(std::ostream & ost,
std::chrono::hours::rep hours,
std::chrono::minutes::rep minutes)
{
@ -106,12 +108,10 @@ void PrintHoursMinutes(std::ostream & ost,
ost << ':';
PrintPaddedNumber(ost, minutes, 2);
}
} // namespace
namespace osmoh
{
// HourMinutes -------------------------------------------------------------------------------------
HourMinutes::HourMinutes(THours const duration)
{

View file

@ -14,7 +14,7 @@
namespace
{
template <typename T>
std::string ToString(T const & t)
inline std::string ToString(T const & t)
{
std::stringstream sstr;
sstr << t;
@ -22,20 +22,20 @@ std::string ToString(T const & t)
}
template <typename T>
bool HasPeriod(std::vector<T> const & v)
inline bool HasPeriod(std::vector<T> const & v)
{
auto const hasPeriod = [](T const & t) { return t.HasPeriod(); };
return std::any_of(begin(v), end(v), hasPeriod);
}
template <typename T>
bool HasPlus(std::vector<T> const & v)
inline bool HasPlus(std::vector<T> const & v)
{
auto const hasPlus = [](T const & t) { return t.HasPlus(); };
return std::any_of(begin(v), end(v), hasPlus);
}
bool HasExtendedHours(osmoh::TTimespans const & spans)
inline bool HasExtendedHours(osmoh::TTimespans const & spans)
{
auto const hasExtendedHours = [](osmoh::Timespan const & s)
{
@ -44,7 +44,7 @@ bool HasExtendedHours(osmoh::TTimespans const & spans)
return std::any_of(begin(spans), end(spans), hasExtendedHours);
}
bool HasOffset(osmoh::TMonthdayRanges const & mr)
inline bool HasOffset(osmoh::TMonthdayRanges const & mr)
{
auto const hasOffset = [](osmoh::MonthdayRange const & md) {
return
@ -54,14 +54,14 @@ bool HasOffset(osmoh::TMonthdayRanges const & mr)
return std::any_of(begin(mr), end(mr), hasOffset);
}
bool HasOffset(osmoh::Weekdays const & wd)
inline bool HasOffset(osmoh::Weekdays const & wd)
{
auto const hasOffset = [](osmoh::WeekdayRange const & w) { return w.HasOffset(); };
return std::any_of(begin(wd.GetWeekdayRanges()), end(wd.GetWeekdayRanges()), hasOffset);
}
template <typename ParserResult>
bool CompareNormalized(std::string const & original, ParserResult const & pretendent)
inline bool CompareNormalized(std::string const & original, ParserResult const & pretendent)
{
auto originalCopy = original;
auto pretendentCopy = ToString(pretendent);
@ -94,13 +94,13 @@ enum
};
using TRuleFeatures = std::array<bool, Count_>;
std::ostream & operator<<(std::ostream & ost, TRuleFeatures const & f)
inline std::ostream & operator<<(std::ostream & ost, TRuleFeatures const & f)
{
std::copy(begin(f), end(f), std::ostream_iterator<bool>(ost, "\t"));
return ost;
}
TRuleFeatures DescribeRule(osmoh::TRuleSequences const & rule)
inline TRuleFeatures DescribeRule(osmoh::TRuleSequences const & rule)
{
TRuleFeatures features{};
for (auto const & r : rule)

View file

@ -11,7 +11,7 @@ namespace
typedef std::tuple<long, long> LongTimeRange;
int countTests = 0;
LongTimeRange RangeToLong(std::string const & start, std::string const & end)
inline LongTimeRange RangeToLong(std::string const & start, std::string const & end)
{
std::tm when{};
@ -25,9 +25,10 @@ LongTimeRange RangeToLong(std::string const & start, std::string const & end)
}
void TestRanges(std::string const & name, std::initializer_list<std::string> const & strings,
std::string const & rangeStart, std::string const & rangeEnd,
std::initializer_list<std::vector<std::string>> const & ranges)
inline void TestRanges(std::string const & name,
std::initializer_list<std::string> const & strings,
std::string const & rangeStart, std::string const & rangeEnd,
std::initializer_list<std::vector<std::string>> const & ranges)
{
for (std::string const & input : strings)
{
@ -91,7 +92,7 @@ void TestRanges(std::string const & name, std::initializer_list<std::string> con
}
}
void TestShouldFail(std::string const & name, std::initializer_list<std::string> const & strings)
inline void TestShouldFail(std::string const & name, std::initializer_list<std::string> const & strings)
{
for (std::string const & input : strings)
{

View file

@ -47,7 +47,7 @@
namespace
{
template <typename T>
std::string ToString(T const & t)
inline std::string ToString(T const & t)
{
std::stringstream sstr;
sstr << t;
@ -55,7 +55,7 @@ std::string ToString(T const & t)
}
template <typename Parser>
bool Test(std::string const & str, Parser const & p, bool full_match = true)
inline bool Test(std::string const & str, Parser const & p, bool full_match = true)
{
// We don't care about the result of the "what" function.
// We only care that all parsers have it:
@ -67,7 +67,7 @@ bool Test(std::string const & str, Parser const & p, bool full_match = true)
}
template <typename ParseResult>
std::string ParseAndUnparse(std::string const & str)
inline std::string ParseAndUnparse(std::string const & str)
{
ParseResult parseResult;
if (!osmoh::Parse(str, parseResult))
@ -79,7 +79,7 @@ std::string ParseAndUnparse(std::string const & str)
return sstr.str();
}
bool GetTimeTuple(std::string const & strTime, std::string const & fmt, std::tm & tm)
inline bool GetTimeTuple(std::string const & strTime, std::string const & fmt, std::tm & tm)
{
auto const rc = strptime(strTime.data(), fmt.data(), &tm);
return rc != nullptr;
@ -95,7 +95,7 @@ struct GetTimeError: std::exception
std::string const m_message;
};
osmoh::RuleState GetRulesState(osmoh::TRuleSequences const & rules, std::string const & dateTime)
inline osmoh::RuleState GetRulesState(osmoh::TRuleSequences const & rules, std::string const & dateTime)
{
static auto const & fmt = "%Y-%m-%d %H:%M";
std::tm time = {};
@ -110,17 +110,17 @@ osmoh::RuleState GetRulesState(osmoh::TRuleSequences const & rules, std::string
return osmoh::GetState(rules, time);
}
bool IsOpen(osmoh::TRuleSequences const & rules, std::string const & dateTime)
inline bool IsOpen(osmoh::TRuleSequences const & rules, std::string const & dateTime)
{
return GetRulesState(rules, dateTime) == osmoh::RuleState::Open;
}
bool IsClosed(osmoh::TRuleSequences const & rules, std::string const & dateTime)
inline bool IsClosed(osmoh::TRuleSequences const & rules, std::string const & dateTime)
{
return GetRulesState(rules, dateTime) == osmoh::RuleState::Closed;
}
bool IsUnknown(osmoh::TRuleSequences const & rules, std::string const & dateTime)
inline bool IsUnknown(osmoh::TRuleSequences const & rules, std::string const & dateTime)
{
return GetRulesState(rules, dateTime) == osmoh::RuleState::Unknown;
}

View file

@ -36,12 +36,11 @@ template<typename Iterator> struct context_parser<osmoh::TRuleSequences, Iterato
using type = osmoh::parsing::time_domain<Iterator>;
};
template <typename Context, typename Iterator>
using context_parser_t = typename context_parser<Context, Iterator>::type;
template <typename Context>
bool ParseImp(std::string const & str, Context & context)
inline bool ParseImp(std::string const & str, Context & context)
{
using boost::spirit::qi::phrase_parse;
using boost::spirit::standard_wide::space;