API
 
Loading...
Searching...
No Matches
MagAOX::file Namespace Reference

Classes

struct  compStdFileName
 Sort predicate for stdFileNames. More...
 
class  stdFileName
 Organize and analyze the name of a standard file name. More...
 
class  stdSubDir
 Manage a standard subdirectory. More...
 

Functions

template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t timestamp (std::string &tstamp, const tm &uttime, long ts_nsec)
 Get the filename timestamp from the breakdown for a time.
 
template<typename verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t timestamp (std::string &tstamp, tm &uttime, time_t ts_sec, long ts_nsec)
 Get the filename timestamp and the breakdown for a time.
 
template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t timestamp (std::string &tstamp, time_t ts_sec, long ts_nsec)
 Get the filename timestamp for a time.
 
template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t fileTimeRelPath (std::string &tstamp, std::string &relPath, time_t ts_sec, long ts_nsec)
 Get the timestamp and the relative path based on a time.
 
template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t fileTimeRelPath (std::string &fileName, std::string &relPath, const std::string &devName, const std::string &ext, time_t ts_sec, long ts_nsec)
 Construct the filename and full relative path based on a time and a device name and extension.
 
template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t parseTimestamp (std::string &YYYY, std::string &MM, std::string &DD, std::string &hh, std::string &mm, std::string &ss, std::string &nn, const std::string &tstamp)
 Parse a standard XWCTk timestamp string.
 
template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t parseFilePath (std::string &devName, std::string &YYYY, std::string &MM, std::string &DD, std::string &hh, std::string &mm, std::string &ss, std::string &nn, const std::string &fname)
 Parse a standard XWCTk timestamp filepath.
 

Function Documentation

◆ fileTimeRelPath() [1/2]

template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t MagAOX::file::fileTimeRelPath ( std::string &  fileName,
std::string &  relPath,
const std::string &  devName,
const std::string &  ext,
time_t  ts_sec,
long  ts_nsec 
)

Construct the filename and full relative path based on a time and a device name and extension.

Fills in the fileName string with the timestamp encoded as

*      devName_YYYYMMDDHHMMSSNNNNNNNNN.ext
* 

and the relPath string with the format

*      devName/YYYY_MM_DD
* 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
mx::error_t::noerror on success
errors from fileTimeRelPath(std::string&,std::string&, time_t, long)
mx::error_t::std_exception if an exception other than std::bad_alloc is caught
Exceptions
nestedmx::excpetion if std::bad_alloc is thrown
Parameters
[out]fileNamethe resulting file name
[out]relPaththe resulting relative path
[in]devNamethe device name part of the path. No '/'.
[in]extthe extension part of the filename. No ..
[in]ts_secthe unix time second
[in]ts_nsecthe nanosecond

Definition at line 287 of file fileTimes.hpp.

References fileTimeRelPath().

◆ fileTimeRelPath() [2/2]

template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t MagAOX::file::fileTimeRelPath ( std::string &  tstamp,
std::string &  relPath,
time_t  ts_sec,
long  ts_nsec 
)

Get the timestamp and the relative path based on a time.

Fills in the tstamp string with the timestamp encoded as

*      YYYYMMDDHHMMSSNNNNNNNNN
* 

and the relPath string with the format

*      yyyy_mm_dd
* 
Returns
0 on success
-1 if gmtime_r returns an error (from timestamp)
-2 if snprintf returns an error writing tstamp (from timestamp)
-3 if snprintf does not write enough characters to tstamp (from timestamp)
-4 if snprintf returns an error writing relPath
-5 if snprintf does not write enough characters to relPath
Parameters
[out]tstamp
[out]relPath
[in]ts_secthe unix time second
[in]ts_nsecthe nanosecond

Definition at line 209 of file fileTimes.hpp.

References fileTimeRelPath().

Referenced by MagAOX::logger::logFileRaw< verboseT >::createFile(), libXWCTest::loggerTest::logMapTest::createTestPaths(), MagAOX::app::streamWriter::doEncode(), fileTimeRelPath(), fileTimeRelPath(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), and libXWCTest::fileTest::fileTimesTest::TEST_CASE().

◆ parseFilePath()

template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t MagAOX::file::parseFilePath ( std::string &  devName,
std::string &  YYYY,
std::string &  MM,
std::string &  DD,
std::string &  hh,
std::string &  mm,
std::string &  ss,
std::string &  nn,
const std::string &  fname 
)

Parse a standard XWCTk timestamp filepath.

Extracts the device name and the date components. The only restriction on the input \fname is that it be at least 23 characters long. In this case it contains only the timestamp.

No validity checks are done on the components (i.e. no check that the timestamp is all numeric, no check on device name format).

Examples of valid inputs are:

  • device_20241121063300000000000.txt
  • /path/to/device_20241121063300000000000.txt
  • 20241121063300000000000
Returns
0 on success
-1 on error
Parameters
[out]devNamethe device name
[out]YYYYthe 4 digit year
[out]MMthe 2 digit month
[out]DDthe 2 digit day
[out]hhthe 2 digit hour
[out]mmthe 2 digit minute
[out]ssthe 2 digit second
[out]nnthe 9 digit nanosecond
[in]fnamethe filename, which can include a path

Definition at line 430 of file fileTimes.hpp.

References parseFilePath().

Referenced by logdump::execute(), MagAOX::file::stdFileName< verboseT >::fullName(), parseFilePath(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), and libXWCTest::fileTest::fileTimesTest::TEST_CASE().

◆ parseTimestamp()

template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t MagAOX::file::parseTimestamp ( std::string &  YYYY,
std::string &  MM,
std::string &  DD,
std::string &  hh,
std::string &  mm,
std::string &  ss,
std::string &  nn,
const std::string &  tstamp 
)

Parse a standard XWCTk timestamp string.

Extracts the date components.

The input must be exactly 23 characters long.

No validity checks are done on the components.

Returns
mx::error_t::noerror on success
mx::error_t::invalidarg if timestamp is not 23 characters long
mx::error_t::std_out_of_range if std::out_of_range is thrown by std::substr
mx::error_t::exception if any other exception other than bad_alloc is thrown by std::string::substr
Exceptions
nestedmx::exception if std::bad_alloc is thrown
Parameters
[out]YYYYthe 4 digit year
[out]MMthe 2 digit month
[out]DDthe 2 digit day
[out]hhthe 2 digit hour
[out]mmthe 2 digit minute
[out]ssthe 2 digit second
[out]nnthe 9 digit nanosecond
[in]tstampthe 23-digit timestamp

Definition at line 352 of file fileTimes.hpp.

References parseTimestamp().

Referenced by parseTimestamp(), and libXWCTest::fileTest::fileTimesTest::TEST_CASE().

◆ timestamp() [1/3]

template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t MagAOX::file::timestamp ( std::string &  tstamp,
const tm &  uttime,
long  ts_nsec 
)

Get the filename timestamp from the breakdown for a time.

Fills in the tstamp string with the timestamp encoded as

*      YYYYMMDDHHMMSSNNNNNNNNN
* 
Returns
mx::error_t::noerror on success
mx::error_t::format_error if std::format throws and exception
mx::error_t::std_exception if any other exception other than bad_alloc is caught
throws nested mx::exception if std::bad_alloc is caught from std::format
Parameters
[out]tstampthe timestamp string
[in]uttimethe broken down time
[in]ts_nsecthe nanosecond

Definition at line 44 of file fileTimes.hpp.

References timestamp().

Referenced by libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), libXWCTest::fileTest::fileTimesTest::TEST_CASE(), timestamp(), timestamp(), and timestamp().

◆ timestamp() [2/3]

template<class verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t MagAOX::file::timestamp ( std::string &  tstamp,
time_t  ts_sec,
long  ts_nsec 
)

Get the filename timestamp for a time.

Fills in the tstamp string with the timestamp encoded as

* YYYYMMDDHHMMSSNNNNNNNNN
* 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
mx::error_t::noerror on success
mx::error_t::eoverflow if year is too big for gmtime_r
mx::error_t::error if gmtime_r returns an error without setting errno
mx::error_t::std_exception if an exception other than bad_alloc is caught in timestamp
throws nested mx::exception if an exception is caught from timestamp , which means std::bad_alloc was thrown
Parameters
[out]tstampthe timestamp string
[in]ts_secthe unix time second
[in]ts_nsecthe nanosecond

Definition at line 172 of file fileTimes.hpp.

References timestamp().

◆ timestamp() [3/3]

template<typename verboseT = XWC_DEFAULT_VERBOSITY>
mx::error_t MagAOX::file::timestamp ( std::string &  tstamp,
tm &  uttime,
time_t  ts_sec,
long  ts_nsec 
)

Get the filename timestamp and the breakdown for a time.

Fills in the tstamp string with the timestamp encoded as

*      YYYYMMDDHHMMSSNNNNNNNNN
* 

and the broken down tm structure uttime

Returns
mx::error_t::noerror on success
mx::error_t::eoverflow if year is too big for gmtime_r
mx::error_t::error if gmtime_r returns an error without setting errno
mx::error_t::format_error if std::format throws and exception
mx::error_t::std_exception if any other exception other than bad_alloc is caught in timestamp
throws nested mx::exception if an exception is caught from timestamp , which means std::bad_alloc was thrown
Parameters
[out]tstampthe timestamp string
[out]uttimethe broken down time
[in]ts_secthe unix time second
[in]ts_nsecthe nanosecond

Definition at line 115 of file fileTimes.hpp.

References timestamp().