add filepath check, minimal.py, tdm_reaper.pyx: write_all

This commit is contained in:
2021-01-26 17:35:07 +01:00
parent a3b78f5ae2
commit 0db972c2f5
7 changed files with 56 additions and 4 deletions

View File

@@ -610,6 +610,9 @@ std::vector<tdmdatatype> tdm_reaper::get_channel(std::string& id)
void tdm_reaper::print_channel(std::string &id, const char* filename, bool include_meta)
{
// check required path
this->check_filename_path(filename);
// check for channel id
if ( this->tdmchannels_.count(id) != 1 )
{
@@ -652,6 +655,9 @@ void tdm_reaper::print_channel(std::string &id, const char* filename, bool inclu
void tdm_reaper::print_group(std::string &id, const char* filename, bool include_meta, char sep)
{
// check required path
this->check_filename_path(filename);
// check for group id
if ( this->tdmchannelgroups_.count(id) != 1 )
{
@@ -761,6 +767,20 @@ void tdm_reaper::print_group(std::string &id, const char* filename, bool include
}
}
void tdm_reaper::check_filename_path(const char* filename)
{
// declare filesystem path instance from filename
std::filesystem::path pt(filename);
// get pure directory path
pt.remove_filename();
if ( !std::filesystem::is_directory(pt) )
{
throw std::runtime_error(std::string("directory does not exist: ") + pt.c_str() );
}
}
// -------------------------------------------------------------------------- //
void tdm_reaper::check_local_datatypes()

View File

@@ -208,6 +208,7 @@ public:
// dump a single channel/entire group (identified by id) to file
void print_channel(std::string &id, const char* filename, bool include_meta = true);
void print_group(std::string &id, const char* filename, bool include_meta = true, char sep = ' ');
void check_filename_path(const char* filename);
// check machine's datatypes
// https://en.cppreference.com/w/cpp/language/types