ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
helpers.hpp
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (c) 2025 Contributors to the Eclipse Foundation
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information regarding copyright ownership.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * https://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  ********************************************************************************/
13 
14 #pragma once
15 #include <iostream>
16 #include <string>
17 
22 std::string module_name( const char* path )
23 {
24  if( path == nullptr )
25  {
26  return "";
27  }
28  std::string full_path( path );
29  std::string::size_type i = full_path.find_last_of( "/\\" );
30  if( i != std::string::npos )
31  {
32  std::string name( full_path.substr( i + 1 ) );
33  return name;
34 
35  }
36  return full_path;
37 }
38 
44 std::string modified_filename( const std::string filename, const std::string new_end_with_suffix )
45 {
46  std::string str = filename;
47  size_t last_dot_pos = str.find_last_of( '.' );
48  if( last_dot_pos != std::string::npos )
49  {
50  str[ last_dot_pos ] = '_';
51  }
52  std::string modified_filename = str + new_end_with_suffix;
53  return modified_filename;
54 }
55 
61 bool are_identical_files( const std::string& file1, const std::string& file2 )
62 {
63  // If under linux, call diff -a, if under windows, call fc
64  // to compare the two JSON files
65  #ifdef _WIN32
66  std::string command = "fc \"" + file1 + "\" \"" + file2 + "\"";
67  #else
68  std::string command = "diff -a \"" + file1 + "\" \"" + file2 + "\"";
69  #endif
70  int ret = system( command.c_str() );
71  return ret == 0;
72 }
bool are_identical_files(const std::string &file1, const std::string &file2)
Compares two files for identical content.
Definition: helpers.hpp:61
std::string modified_filename(const std::string filename, const std::string new_end_with_suffix)
Modifies a filename by replacing the last dot with an underscore and appending a new end withsuffix.
Definition: helpers.hpp:44
std::string module_name(const char *path)
Helper function to extract module name from the path of the executable.
Definition: helpers.hpp:22
name
Definition: setup.py:6