You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.7 KiB
C

/**
*
* \section COPYRIGHT
*
* Copyright 2013-2020 Software Radio Systems Limited
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
*
*/
/*! \brief Utility functions for the DUT.
*
*/
#ifndef SRSUE_TTCN3_DUT_UTILS_H
#define SRSUE_TTCN3_DUT_UTILS_H
#include <set>
#include <sstream>
#include <vector>
std::string get_filename_with_tc_name(const std::string& str, const uint32_t run_id, const std::string tc_name)
{
// split base path into components
std::set<char> delims;
delims.insert('/');
std::vector<std::string> result;
char const* pch = str.c_str();
char const* start = pch;
for (; *pch; ++pch) {
if (delims.find(*pch) != delims.end()) {
if (start != pch) {
std::string str(start, pch);
result.push_back(str);
} else {
result.push_back("");
}
start = pch + 1;
}
}
result.push_back(start);
// prepend TC name to last element (the actual filename)
std::stringstream filename_ss;
filename_ss << tc_name << "_"
<< "run" << run_id << "_" << result.back();
std::string final_path;
std::vector<std::string>::iterator path_it;
for (path_it = result.begin() + 1; path_it != --result.end(); ++path_it) {
final_path += "/";
final_path += *path_it;
}
final_path += "/";
final_path += filename_ss.str();
return final_path;
}
std::string get_tc_name(const std::string& str)
{
// split after dot
std::string::size_type pos = str.find('.');
return (pos == str.npos ? str : str.substr(pos + 1, -1));
}
#endif // SRSUE_TTCN3_DUT_UTILS_H