📄 osutil.inl
字号:
PINLINE bool PTimeInterval::operator< (long msecs) const
{ return (long)milliseconds < msecs; }
PINLINE bool PTimeInterval::operator<=(long msecs) const
{ return (long)milliseconds <= msecs; }
///////////////////////////////////////////////////////////////////////////////
// PTime
PINLINE PObject * PTime::Clone() const
{ return PNEW PTime(theTime, microseconds); }
PINLINE void PTime::PrintOn(ostream & strm) const
{ strm << AsString(); }
PINLINE BOOL PTime::IsValid() const
{ return theTime > 46800; }
PINLINE PInt64 PTime::GetTimestamp() const
{ return theTime*(PInt64)1000000 + microseconds; }
PINLINE time_t PTime::GetTimeInSeconds() const
{ return theTime; }
PINLINE long PTime::GetMicrosecond() const
{ return microseconds; }
PINLINE int PTime::GetSecond() const
{ struct tm ts; return os_localtime(&theTime, &ts)->tm_sec; }
PINLINE int PTime::GetMinute() const
{ struct tm ts; return os_localtime(&theTime, &ts)->tm_min; }
PINLINE int PTime::GetHour() const
{ struct tm ts; return os_localtime(&theTime, &ts)->tm_hour; }
PINLINE int PTime::GetDay() const
{ struct tm ts; return os_localtime(&theTime, &ts)->tm_mday; }
PINLINE PTime::Months PTime::GetMonth() const
{ struct tm ts; return (Months)(os_localtime(&theTime, &ts)->tm_mon+January); }
PINLINE int PTime::GetYear() const
{ struct tm ts; return os_localtime(&theTime, &ts)->tm_year+1900; }
PINLINE PTime::Weekdays PTime::GetDayOfWeek() const
{ struct tm ts; return (Weekdays)os_localtime(&theTime, &ts)->tm_wday; }
PINLINE int PTime::GetDayOfYear() const
{ struct tm ts; return os_localtime(&theTime, &ts)->tm_yday; }
PINLINE BOOL PTime::IsPast() const
{ return theTime < time(NULL); }
PINLINE BOOL PTime::IsFuture() const
{ return theTime > time(NULL); }
PINLINE PString PTime::AsString(const PString & format, int zone) const
{ return AsString((const char *)format, zone); }
PINLINE int PTime::GetTimeZone()
{ return GetTimeZone(IsDaylightSavings() ? DaylightSavings : StandardTime); }
///////////////////////////////////////////////////////////////////////////////
// PTimer
PINLINE BOOL PTimer::IsRunning() const
{ return state == Starting || state == Running; }
PINLINE BOOL PTimer::IsPaused() const
{ return state == Paused; }
PINLINE const PTimeInterval & PTimer::GetResetTime() const
{ return resetTime; }
PINLINE const PNotifier & PTimer::GetNotifier() const
{ return callback; }
PINLINE void PTimer::SetNotifier(const PNotifier & func)
{ callback = func; }
///////////////////////////////////////////////////////////////////////////////
PINLINE PChannelStreamBuffer::PChannelStreamBuffer(const PChannelStreamBuffer & sbuf)
: channel(sbuf.channel) { }
PINLINE PChannelStreamBuffer &
PChannelStreamBuffer::operator=(const PChannelStreamBuffer & sbuf)
{ channel = sbuf.channel; return *this; }
PINLINE PChannel::PChannel(const PChannel &) : iostream(cout.rdbuf())
{ PAssertAlways("Cannot copy channels"); }
PINLINE PChannel & PChannel::operator=(const PChannel &)
{ PAssertAlways("Cannot assign channels"); return *this; }
PINLINE void PChannel::SetReadTimeout(const PTimeInterval & time)
{ readTimeout = time; }
PINLINE PTimeInterval PChannel::GetReadTimeout() const
{ return readTimeout; }
PINLINE void PChannel::SetWriteTimeout(const PTimeInterval & time)
{ writeTimeout = time; }
PINLINE PTimeInterval PChannel::GetWriteTimeout() const
{ return writeTimeout; }
PINLINE int PChannel::GetHandle() const
{ return os_handle; }
PINLINE PChannel::Errors PChannel::GetErrorCode(ErrorGroup group) const
{ return lastErrorCode[group]; }
PINLINE int PChannel::GetErrorNumber(ErrorGroup group) const
{ return lastErrorNumber[group]; }
PINLINE void PChannel::AbortCommandString()
{ abortCommandString = TRUE; }
///////////////////////////////////////////////////////////////////////////////
// PIndirectChannel
PINLINE PIndirectChannel::~PIndirectChannel()
{ Close(); }
PINLINE PChannel * PIndirectChannel::GetReadChannel() const
{ return readChannel; }
PINLINE PChannel * PIndirectChannel::GetWriteChannel() const
{ return writeChannel; }
///////////////////////////////////////////////////////////////////////////////
// PDirectory
PINLINE PDirectory::PDirectory()
: PFilePathString(".") { Construct(); }
PINLINE PDirectory::PDirectory(const char * cpathname)
: PFilePathString(cpathname) { Construct(); }
PINLINE PDirectory::PDirectory(const PString & pathname)
: PFilePathString(pathname) { Construct(); }
PINLINE PDirectory & PDirectory::operator=(const PString & str)
{ AssignContents(PDirectory(str)); return *this; }
PINLINE PDirectory & PDirectory::operator=(const char * cstr)
{ AssignContents(PDirectory(cstr)); return *this; }
PINLINE void PDirectory::DestroyContents()
{ Close(); PFilePathString::DestroyContents(); }
PINLINE BOOL PDirectory::Exists() const
{ return Exists(*this); }
PINLINE BOOL PDirectory::Change() const
{ return Change(*this); }
PINLINE BOOL PDirectory::Create(int perm) const
{ return Create(*this, perm); }
PINLINE BOOL PDirectory::Remove()
{ Close(); return Remove(*this); }
///////////////////////////////////////////////////////////////////////////////
PINLINE PFilePath::PFilePath()
{ }
PINLINE PFilePath::PFilePath(const PFilePath & path)
: PFilePathString(path) { }
PINLINE PFilePath & PFilePath::operator=(const PFilePath & path)
{ AssignContents(path); return *this; }
PINLINE PFilePath & PFilePath::operator=(const PString & str)
{ AssignContents(str); return *this; }
PINLINE PFilePath & PFilePath::operator=(const char * cstr)
{ AssignContents(PString(cstr)); return *this; }
PINLINE PFilePath & PFilePath::operator+=(const PString & str)
{ AssignContents(*this + str); return *this; }
PINLINE PFilePath & PFilePath::operator+=(const char * cstr)
{ AssignContents(*this + cstr); return *this; }
///////////////////////////////////////////////////////////////////////////////
PINLINE PFile::PFile()
{ os_handle = -1; removeOnClose = FALSE; }
PINLINE PFile::PFile(OpenMode mode, int opts)
{ os_handle = -1; removeOnClose = FALSE; Open(mode, opts); }
PINLINE PFile::PFile(const PFilePath & name, OpenMode mode, int opts)
{ os_handle = -1; removeOnClose = FALSE; Open(name, mode, opts); }
PINLINE BOOL PFile::Exists() const
{ return Exists(path); }
PINLINE BOOL PFile::Access(OpenMode mode)
{ return ConvertOSError(Access(path, mode) ? 0 : -1); }
PINLINE BOOL PFile::Remove(BOOL force)
{ Close(); return ConvertOSError(Remove(path, force) ? 0 : -1); }
PINLINE BOOL PFile::Copy(const PFilePath & newname, BOOL force)
{ return ConvertOSError(Copy(path, newname, force) ? 0 : -1); }
PINLINE BOOL PFile::GetInfo(PFileInfo & info)
{ return ConvertOSError(GetInfo(path, info) ? 0 : -1); }
PINLINE BOOL PFile::SetPermissions(int permissions)
{ return ConvertOSError(SetPermissions(path, permissions) ? 0 : -1); }
PINLINE const PFilePath & PFile::GetFilePath() const
{ return path; }
PINLINE PString PFile::GetName() const
{ return path; }
PINLINE off_t PFile::GetPosition() const
{ return _lseek(GetHandle(), 0, SEEK_CUR); }
///////////////////////////////////////////////////////////////////////////////
PINLINE PTextFile::PTextFile()
{ }
PINLINE PTextFile::PTextFile(OpenMode mode, int opts)
{ Open(mode, opts); }
PINLINE PTextFile::PTextFile(const PFilePath & name, OpenMode mode, int opts)
{ Open(name, mode, opts); }
///////////////////////////////////////////////////////////////////////////////
// PConfig
#ifdef P_CONFIG_FILE
PINLINE PConfig::PConfig(Source src)
: defaultSection("Options") { Construct(src, "", ""); }
PINLINE PConfig::PConfig(Source src, const PString & appname)
: defaultSection("Options") { Construct(src, appname, ""); }
PINLINE PConfig::PConfig(Source src, const PString & appname, const PString & manuf)
: defaultSection("Options") { Construct(src, appname, manuf); }
PINLINE PConfig::PConfig(const PString & section, Source src)
: defaultSection(section) { Construct(src, "", ""); }
PINLINE PConfig::PConfig(const PString & section, Source src, const PString & appname)
: defaultSection(section) { Construct(src, appname, ""); }
PINLINE PConfig::PConfig(const PString & section,
Source src,
const PString & appname,
const PString & manuf)
: defaultSection(section) { Construct(src, appname, manuf); }
PINLINE PConfig::PConfig(const PFilePath & filename, const PString & section)
: defaultSection(section) { Construct(filename); }
PINLINE void PConfig::SetDefaultSection(const PString & section)
{ defaultSection = section; }
PINLINE PString PConfig::GetDefaultSection() const
{ return defaultSection; }
PINLINE PStringList PConfig::GetKeys() const
{ return GetKeys(defaultSection); }
PINLINE PStringToString PConfig::GetAllKeyValues() const
{ return GetAllKeyValues(defaultSection); }
PINLINE void PConfig::DeleteSection()
{ DeleteSection(defaultSection); }
PINLINE void PConfig::DeleteKey(const PString & key)
{ DeleteKey(defaultSection, key); }
PINLINE BOOL PConfig::HasKey(const PString & key) const
{ return HasKey(defaultSection, key); }
PINLINE PString PConfig::GetString(const PString & key) const
{ return GetString(defaultSection, key, PString()); }
PINLINE PString PConfig::GetString(const PString & key, const PString & dflt) const
{ return GetString(defaultSection, key, dflt); }
PINLINE void PConfig::SetString(const PString & key, const PString & value)
{ SetString(defaultSection, key, value); }
PINLINE BOOL PConfig::GetBoolean(const PString & key, BOOL dflt) const
{ return GetBoolean(defaultSection, key, dflt); }
PINLINE void PConfig::SetBoolean(const PString & key, BOOL value)
{ SetBoolean(defaultSection, key, value); }
PINLINE long PConfig::GetInteger(const PString & key, long dflt) const
{ return GetInteger(defaultSection, key, dflt); }
PINLINE void PConfig::SetInteger(const PString & key, long value)
{ SetInteger(defaultSection, key, value); }
PINLINE PInt64 PConfig::GetInt64(const PString & key, PInt64 dflt) const
{ return GetInt64(defaultSection, key, dflt); }
PINLINE void PConfig::SetInt64(const PString & key, PInt64 value)
{ SetInt64(defaultSection, key, value); }
PINLINE double PConfig::GetReal(const PString & key, double dflt) const
{ return GetReal(defaultSection, key, dflt); }
PINLINE void PConfig::SetReal(const PString & key, double value)
{ SetReal(defaultSection, key, value); }
PINLINE PTime PConfig::GetTime(const PString & key) const
{ return GetTime(defaultSection, key); }
PINLINE PTime PConfig::GetTime(const PString & key, const PTime & dflt) const
{ return GetTime(defaultSection, key, dflt); }
PINLINE void PConfig::SetTime(const PString & key, const PTime & value)
{ SetTime(defaultSection, key, value); }
#endif // P_CONFIG_FILE
///////////////////////////////////////////////////////////////////////////////
// PArgList
PINLINE void PArgList::SetArgs(int argc, char ** argv)
{ SetArgs(PStringArray(argc, argv)); }
PINLINE BOOL PArgList::Parse(const PString & theArgumentSpec, BOOL optionsBeforeParams)
{ return Parse((const char *)theArgumentSpec, optionsBeforeParams); }
PINLINE BOOL PArgList::HasOption(char option) const
{ return GetOptionCount(option) != 0; }
PINLINE BOOL PArgList::HasOption(const char * option) const
{ return GetOptionCount(option) != 0; }
PINLINE BOOL PArgList::HasOption(const PString & option) const
{ return GetOptionCount(option) != 0; }
PINLINE PINDEX PArgList::GetCount() const
{ return parameterIndex.GetSize()-shift; }
PINLINE PString PArgList::operator[](PINDEX num) const
{ return GetParameter(num); }
PINLINE PArgList & PArgList::operator<<(int sh)
{ Shift(sh); return *this; }
PINLINE PArgList & PArgList::operator>>(int sh)
{ Shift(-sh); return *this; }
///////////////////////////////////////////////////////////////////////////////
// PProcess
PINLINE PArgList & PProcess::GetArguments()
{ return arguments; }
PINLINE const PString & PProcess::GetManufacturer() const
{ return manufacturer; }
PINLINE const PString & PProcess::GetName() const
{ return productName; }
PINLINE const PFilePath & PProcess::GetFile() const
{ return executableFile; }
PINLINE int PProcess::GetMaxHandles() const
{ return maxHandles; }
PINLINE PTimerList * PProcess::GetTimerList()
{ return &timers; }
PINLINE void PProcess::SetTerminationValue(int value)
{ terminationValue = value; }
PINLINE int PProcess::GetTerminationValue() const
{ return terminationValue; }
// End Of File ///////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -