55 bool m_valid{
false };
72 explicit stdFileName(
const std::string &fullName );
98 mx::error_t fullName(
const std::string &fullName );
105 const std::string &fullName( mx::error_t *errc =
nullptr )
const;
112 const std::string &baseName( mx::error_t *errc =
nullptr )
const;
119 const std::string &extension( mx::error_t *errc =
nullptr )
const;
126 const std::string &appName( mx::error_t *errc =
nullptr )
const;
140 int year( mx::error_t *errc =
nullptr )
const;
147 unsigned month( mx::error_t *errc =
nullptr )
const;
154 unsigned day( mx::error_t *errc =
nullptr )
const;
161 int hour( mx::error_t *errc =
nullptr )
const;
168 int minute( mx::error_t *errc =
nullptr )
const;
175 int second( mx::error_t *errc =
nullptr )
const;
182 int nsec( mx::error_t *errc =
nullptr )
const;
254 #ifdef XWCTEST_STDFILENAME_FULLNAME_BAD_ALLOC
255 throw std::bad_alloc();
258 #ifdef XWCTEST_STDFILENAME_FULLNAME_EXCEPTION
259 throw std::exception();
265 catch(
const std::bad_alloc &e )
267 std::throw_with_nested(
xwcException(
"from std::string" ) );
269 catch(
const std::exception &e )
271 return mx::error_report<verboseT>( mx::error_t::std_exception,
"from std::string" );
277 #ifdef XWCTEST_STDFILENAME_FULLNAME_FS_BAD_ALLOC
278 throw std::bad_alloc();
281 #ifdef XWCTEST_STDFILENAME_FULLNAME_FS_FILESYSTEM_ERROR
282 throw std::filesystem::filesystem_error(
"test", std::error_code(10, std::system_category()));
285 #ifdef XWCTEST_STDFILENAME_FULLNAME_FS_EXCEPTION
286 throw std::exception();
290 std::filesystem::path p( m_fullName );
292 m_baseName = p.filename();
293 m_extension = p.extension();
295 catch(
const std::bad_alloc &e )
297 std::throw_with_nested(
xwcException(
"extracting basename and extension" ) );
299 catch(
const std::filesystem::filesystem_error &e )
301 return mx::error_report<verboseT>( mx::error_t::std_filesystem_error,
302 "extracting basename and extension " + m_fullName );
304 catch(
const std::exception &e )
306 return mx::error_report<verboseT>( mx::error_t::std_exception,
307 "extracting basename and extension from " + m_fullName );
310 if( m_extension ==
"" )
312 return mx::error_report<verboseT>( mx::error_t::invalidarg,
"No extension found in: " + m_fullName );
315 std::string YYYY, MM, DD, hh, mm, ss, nn;
319 mx_error_check(
parseFilePath( m_appName, YYYY, MM, DD, hh, mm, ss, nn, m_baseName ) );
323 std::throw_with_nested(
xwcException(
"parsing filename" ) );
327 int year = mx::ioutils::stoT<int>( YYYY, &errc );
328 mx_error_check_code( errc );
330 unsigned int month = mx::ioutils::stoT<unsigned int>( MM, &errc );
331 mx_error_check_code( errc );
333 unsigned int day = mx::ioutils::stoT<unsigned int>( DD, &errc );
334 mx_error_check_code( errc );
336 m_hour = mx::ioutils::stoT<int>( hh, &errc );
337 mx_error_check_code( errc );
339 m_minute = mx::ioutils::stoT<int>( mm, &errc );
340 mx_error_check_code( errc );
342 m_second = mx::ioutils::stoT<int>( ss, &errc );
343 mx_error_check_code( errc );
345 m_nsec = mx::ioutils::stoT<int>( nn, &errc );
346 mx_error_check_code( errc );
350 mx_error_check( m_subDir.ymd( year, month, day ) );
354 std::throw_with_nested(
xwcException(
"from stdSubDir::ymd" ) );
358 tmst.tm_year = year - 1900;
359 tmst.tm_mon = month - 1;
361 tmst.tm_hour = m_hour;
362 tmst.tm_min = m_minute;
363 tmst.tm_sec = m_second;
366 time_t tgm = timegm( &tmst );
369 #ifdef XWCTEST_STDFILENAME_FULLNAME_TIMEGM
370 tgm =
static_cast<time_t
>( -1 );
373 #ifdef XWCTEST_STDFILENAME_FULLNAME_TIMEGM_OTHER
374 tgm =
static_cast<time_t
>( -1 );
378 if( tgm ==
static_cast<time_t
>( -1 ) )
382 return mx::error_report<verboseT>( mx::errno2error_t( errno ),
"error from timegm" );
385 return mx::error_report<verboseT>( mx::error_t::error,
"error from timegm" );
388 m_timestamp.time_s = tgm;
389 m_timestamp.time_ns = m_nsec;
393 return mx::error_t::noerror;
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.