本文整理汇总了C++中Period::units方法的典型用法代码示例。如果您正苦于以下问题:C++ Period::units方法的具体用法?C++ Period::units怎么用?C++ Period::units使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Period
的用法示例。
在下文中一共展示了Period::units方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
bool operator<(const Period& p1, const Period& p2) {
// special cases
if (p1.length() == 0)
return p2.length() > 0;
if (p2.length() == 0)
return p1.length() < 0;
// exact comparisons
if (p1.units() == p2.units())
return p1.length() < p2.length();
if (p1.units() == Months && p2.units() == Years)
return p1.length() < 12*p2.length();
if (p1.units() == Years && p2.units() == Months)
return 12*p1.length() < p2.length();
if (p1.units() == Days && p2.units() == Weeks)
return p1.length() < 7*p2.length();
if (p1.units() == Weeks && p2.units() == Days)
return 7*p1.length() < p2.length();
// inexact comparisons (handled by converting to days and using limits)
std::pair<Integer, Integer> p1lim = daysMinMax(p1);
std::pair<Integer, Integer> p2lim = daysMinMax(p2);
if (p1lim.second < p2lim.first)
return true;
else if (p1lim.first > p2lim.second)
return false;
else
QL_FAIL("undecidable comparison between " << p1 << " and " << p2);
}
示例2: swapLength
Time SwaptionVolatilityStructure::swapLength(const Period& p) const {
QL_REQUIRE(p.length()>0,
"non-positive swap tenor (" << p << ") given");
switch (p.units()) {
case Months:
return p.length()/12.0;
case Years:
return static_cast<Time>(p.length());
default:
QL_FAIL("invalid Time Unit (" << p.units() << ") for swap length");
}
}
示例3: days
Real days(const Period& p) {
if (p.length()==0) return 0.0;
switch (p.units()) {
case Days:
return p.length();
case Weeks:
return p.length()*7.0;
case Months:
QL_FAIL("cannot convert Months into Days");
case Years:
QL_FAIL("cannot convert Years into Days");
default:
QL_FAIL("unknown time unit (" << Integer(p.units()) << ")");
}
}
示例4: advance
Date Calendar::advance(const Date & d,
const Period & p,
BusinessDayConvention c,
bool endOfMonth) const {
return advance(d, p.length(), p.units(), c, endOfMonth);
}
示例5: advance
inline Date Date::operator-(const Period& p) const {
return advance(*this,-p.length(),p.units());
}