void Show() { TimePass::ShmMultihashmap<MonthName, int> months(SHM_FILE); if (false == months.Open()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); return; } ToDotPs("hashmap", &months); }
void Clear() { TimePass::ShmMultihashmap<MonthName, int> months(SHM_FILE); if (false == months.Open()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); return; } months.Clear(); }
void Clear() { TimePass::ShmHashlist<Month> months(SHM_FILE); if (false == months.Open()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); return; } months.Clear(); }
void Show() { TimePass::ShmHashlist<Month> months(SHM_FILE); if (false == months.Open()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); return; } ToDotPs("hashlist", &months); }
WDate WDate::addMonths(int nmonths) const { if (valid_) { date d(year_, month_, day_); d += months(nmonths); return WDate(d.year(), d.month(), d.day()); } else return *this; }
void Insert() { TimePass::ShmHashlist<Month> months(SHM_FILE); if (false == months.Open()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); return; } for (int i = 0; i < 12; ++i) { months.Insert(Month(t_month[i], n_month[i])); } }
void Insert() { TimePass::ShmMultihashmap<MonthName, int> months(SHM_FILE); if (false == months.Open()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); return; } for (int i = 0; i < 12; ++i) { months.Insert(SHM_PAIR(MonthName(t_month[i]), n_month[i])); } }
void Remove() { TimePass::ShmMultihashmap<MonthName, int> months(SHM_FILE); if (false == months.Open()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); return; } char name[10]; for (int i = 0; i < len; ++i) { months.Remove(MonthName(t_month[i])); snprintf(name, sizeof(name) - 1, "%02d", i); ToDotPs(name, &months); } }
void Read() { TimePass::ShmHashlist<Month> months(SHM_FILE); if (false == months.Open()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); return; } TimePass::ListNode<Month>* p_beg = months.BeginNode(); while (NULL != p_beg) { printf("<%s, %d> ", p_beg->data.t_month, p_beg->data.n_month); p_beg = months.NextNode(p_beg); } putchar('\n'); }
void Find(const char* t_month) { TimePass::ShmHashlist<Month> months(SHM_FILE); if (false == months.Open()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); return; } TimePass::ListNode<Month>* p_node = months.Find(Month(t_month, 0)); if (NULL == p_node) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); return; } else { printf("%s-%d\n", p_node->data.t_month, p_node->data.n_month); } }
double DateTime::duration(const double& time, double duration, DateTimeUnitOptions unit) { switch (unit) { case DATE_TIME_UNIT_NONE: case DATE_TIME_UNIT_DAY: return days(duration); case DATE_TIME_UNIT_WEEK: return weeks(duration); case DATE_TIME_UNIT_MONTH: return months(time, duration); case DATE_TIME_UNIT_YEAR: return years(time, duration); } return 0; }
// date in english function void dateEnglish(char* date) { // for numbers from 1 to 19 char *digit[] = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; // all tens char *tens[] = { "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; int day = (date[0] - '0') * 10 + (date[1] - '0'); int month = (date[3] - '0') * 10 + (date[4] - '0'); int year = (date[6] - '0') * 1000 + (date[7] - '0') * 100 + ((date[8] - '0') * 10 + date[9] - '0'); if (validation(day,month,year)) { days(day, digit, tens); months(month); printf(" of "); years(year, digit, tens); } else printf("Its not a valid date"); }
int main() { //use functor as hash function std::unordered_map<std::pair<int, int>, int, hash_fun> fun_map; fun_map[std::make_pair(1,2)]++; std::cout<<fun_map[std::pair<int, int>(1, 2)] <<std::endl; //use lambda function std::unordered_map<std::pair<int, int>, int, decltype(hash_lambda)> lambda_map(0, hash_lambda); lambda_map[std::make_pair(1,2)] = 20; std::cout<<lambda_map[std::pair<int, int>(1, 2)] <<std::endl; //use bind function std::unordered_map<std::string, int, decltype(std::bind(&hash, std::placeholders::_1))> months(0, std::bind(&hash, std::placeholders::_1)); months["january"] = 31; months["february"] = 28; months["march"] = 31; months["april"] = 30; months["may"] = 31; months["june"] = 30; months["july"] = 31; months["august"] = 31; months["september"] = 30; months["october"] = 31; months["november"] = 30; months["december"] = 31; std::cout << "june -> " << months["june"] << std::endl; std::cout << "july -> " << months["july"] << std::endl; std::cout << "december -> " << months["december"] << std::endl; std::cout << "february -> " << months["february"] << std::endl; //use function directly, compile error // std::unordered_map<std::string, int, decltype(std::bind(hash)> // months(0, hash); return 0; }
int CssmDate::month() const { return atoi(string(months(), 2).c_str()); }
// // The CssmDate PODwrapper // CssmDate::CssmDate(const char *y, const char *m, const char *d) { assign(years(), 4, y); assign(months(), 2, m); assign(days(), 2, d); }
int confOption::setValueFromFile(QString line) { // Used to set values in confOptions from a file line QString rval = line.section("=",1).trimmed(); qDebug() << "setting " << realName << " to " << rval << " (from file)"; if (type == BOOL) { if (rval == "true" || rval == "on" || rval == "yes") { value = true; return 0; } else if (rval == "false" || rval == "off" || rval == "no") { value = false; return 0; } qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } else if (type == INTEGER) { bool ok; qlonglong rvalToNmbr = rval.toLongLong(&ok); if (ok && rvalToNmbr >= minVal && rvalToNmbr <= maxVal) { value = rvalToNmbr; return 0; } qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } else if (type == STRING) { value = rval; return 0; } else if (type == LIST) { if (realName == "ShowStatus") // ShowStatus needs special treatment { if (rval.toLower() == "true" || rval.toLower() == "on") rval = "yes"; else if (rval.toLower() == "false" || rval.toLower() == "off") rval = "no"; } if (possibleVals.contains(rval)) { value = rval.toLower(); return 0; } qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; value = defVal; return -1; } else if (type == MULTILIST) { QVariantMap map; QStringList readList = rval.split(" ", QString::SkipEmptyParts); for (int i = 0; i < readList.size(); ++i) { if (!possibleVals.contains(readList.at(i))) { qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } } for (int i = 0; i < possibleVals.size(); ++i) { if (readList.contains(possibleVals.at(i))) map[possibleVals.at(i)] = true; else map[possibleVals.at(i)] = false; } value = map; return 0; } else if (type == TIME) { int pos = 0; QRegExp rxValid; // These regex check whether rval is a valid time interval if (hasNsec) rxValid = QRegExp("^(?:\\d*\\.?\\d *(ns|nsec|us|usec|ms|msec|s|sec|second|seconds|m|min|minute|minutes|h|hr|hour|hours|d|day|days|w|week|weeks|month|months|y|year|years)? *)+$"); else rxValid = QRegExp("^(?:\\d*\\.?\\d *(us|usec|ms|msec|s|sec|second|seconds|m|min|minute|minutes|h|hr|hour|hours|d|day|days|w|week|weeks|month|months|y|year|years)? *)+$"); pos = rxValid.indexIn(rval); if (pos > -1) { pos = 0; seconds secs(0); // This regex parses individual elements of the time interval QRegExp rxTimeParse = QRegExp("(\\d*\\.?\\d+) *([a-z]*)"); while ((pos = rxTimeParse.indexIn(rval, pos)) != -1) { if (rxTimeParse.cap(2) == "ns" || rxTimeParse.cap(2) == "nsec" ) { nanoseconds ns(rxTimeParse.cap(1).trimmed().toDouble()); secs += ns; } else if (rxTimeParse.cap(2) == "us" || rxTimeParse.cap(2) == "usec" ) { microseconds us(rxTimeParse.cap(1).trimmed().toDouble()); secs += us; } else if (rxTimeParse.cap(2) == "ms" || rxTimeParse.cap(2) == "msec" ) { milliseconds ms(rxTimeParse.cap(1).trimmed().toDouble()); secs += ms; } else if (rxTimeParse.cap(2) == "s" || rxTimeParse.cap(2) == "sec" || rxTimeParse.cap(2) == "second" || rxTimeParse.cap(2) == "seconds" ) { seconds s(rxTimeParse.cap(1).trimmed().toDouble()); secs += s; } else if (rxTimeParse.cap(2) == "m" || rxTimeParse.cap(2) == "min" || rxTimeParse.cap(2) == "minute" || rxTimeParse.cap(2) == "minutes" ) { minutes min(rxTimeParse.cap(1).trimmed().toDouble()); secs += min; } else if (rxTimeParse.cap(2) == "h" || rxTimeParse.cap(2) == "hr" || rxTimeParse.cap(2) == "hour" || rxTimeParse.cap(2) == "hours" ) { hours hr(rxTimeParse.cap(1).trimmed().toDouble()); secs += hr; } else if (rxTimeParse.cap(2) == "d" || rxTimeParse.cap(2) == "day" || rxTimeParse.cap(2) == "days") { days dy(rxTimeParse.cap(1).trimmed().toDouble()); secs += dy; } else if (rxTimeParse.cap(2) == "w" || rxTimeParse.cap(2) == "week" || rxTimeParse.cap(2) == "weeks") { weeks w(rxTimeParse.cap(1).trimmed().toDouble()); secs += w; } else if (rxTimeParse.cap(2) == "month" || rxTimeParse.cap(2) == "months") { months m(rxTimeParse.cap(1).trimmed().toDouble()); secs += m; } else if (rxTimeParse.cap(2) == "y" || rxTimeParse.cap(2) == "year" || rxTimeParse.cap(2) == "years") { years y(rxTimeParse.cap(1).trimmed().toDouble()); secs += y; } else if (rxTimeParse.cap(2).isEmpty()) { // unitless number, convert it from defReadUnit to seconds seconds tmpSeconds(convertTimeUnit(rxTimeParse.cap(1).trimmed().toDouble(), defReadUnit, timeUnit::s).toDouble()); secs += tmpSeconds; } pos += rxTimeParse.matchedLength(); } // Convert the read value in seconds to defUnit if (defUnit == ns) value = nanoseconds(secs).count(); else if (defUnit == us) value = microseconds(secs).count(); else if (defUnit == ms) value = milliseconds(secs).count(); else if (defUnit == s) value = secs.count(); else if (defUnit == min) value = minutes(secs).count(); else if (defUnit == h) value = hours(secs).count(); else if (defUnit == d) value = days(secs).count(); else if (defUnit == w) value = weeks(secs).count(); else if (defUnit == month) value = months(secs).count(); else if (defUnit == year) value = years(secs).count(); value = value.toULongLong(); // Convert to ulonglong (we don't support float in ui) return 0; } else { qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } } else if (type == RESLIMIT) { bool ok; int nmbr = rval.toUInt(&ok); if (ok) { value = nmbr; return 0; } else if (rval.toLower().trimmed() == "infinity" || rval.trimmed().isEmpty()) { value = -1; return 0; } qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } else if (type == SIZE) { // RegExp to match a number (possibly with decimals) followed by a size unit (or no unit for byte) QRegExp rxSize = QRegExp("(\\b\\d+\\.?\\d*(K|M|G|T|P|E)?\\b)"); int pos = 0; pos = rxSize.indexIn(rval); if (pos > -1 && rxSize.cap(0) == rval.trimmed()) { // convert the specified size unit to megabytes if (rxSize.cap(0).contains("K")) value = rxSize.cap(0).remove("K").toDouble() / 1024; else if (rxSize.cap(0).contains("M")) value = rxSize.cap(0).remove("M").toDouble(); else if (rxSize.cap(0).contains("G")) value = rxSize.cap(0).remove("G").toDouble() * 1024; else if (rxSize.cap(0).contains("T")) value = rxSize.cap(0).remove("T").toDouble() * 1024 * 1024; else if (rxSize.cap(0).contains("P")) value = rxSize.cap(0).remove("P").toDouble() * 1024 * 1024 * 1024; else if (rxSize.cap(0).contains("E")) value = rxSize.cap(0).remove("E").toDouble() * 1024 * 1024 * 1024 * 1024; else value = rxSize.cap(0).toDouble() / 1024 / 1024; // Convert from double to ulonglong (we don't support float in ui) value = value.toULongLong(); return 0; } else { qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } } return -1; }
void Create(off_t len) { TimePass::ShmHashlist<Month> months(SHM_FILE); if (false == months.Create(len)) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); } }
void Destroy() { TimePass::ShmHashlist<Month> months(SHM_FILE); if (false == months.Destroy()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); } }
void Destroy() { TimePass::ShmMultihashmap<MonthName, int> months(SHM_FILE); if (false == months.Destroy()) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); } }
void Create(off_t len) { TimePass::ShmMultihashmap<MonthName, int> months(SHM_FILE); if (false == months.Create(len)) { printf("errmsg = %s\n", TimePass::Error::GetLastErrmsg().c_str()); } }
/** * Returns: *this += -m. */ date& operator-=(months m) { return *this += months(-m.count()); }
const DateTimeField *BaseChronology::monthOfYear() { return UnsupportedDateTimeField::getInstance(DateTimeFieldType::monthOfYear(), months()); }