AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
filesystem.cpp
1// Copyright 2024 Robin Müller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "auto_apms_util/filesystem.hpp"
16
17#include <cctype>
18#include <exception>
19#include <fstream>
20
21namespace auto_apms_util
22{
23
24bool isFileEmpty(const std::string & path)
25{
26 std::ifstream file(path);
27 if (!file.is_open()) {
28 throw std::runtime_error("Couldn't open output file '" + path + "' to check if it is empty.");
29 }
30 // Read the file character by character
31 char ch;
32 while (file.get(ch)) {
33 if (!std::isspace(static_cast<unsigned char>(ch))) {
34 // Found a non-whitespace character
35 return false;
36 }
37 }
38 return true;
39}
40
41} // namespace auto_apms_util
bool isFileEmpty(const std::string &path)
Determine if a file is empty.
Fundamental helper classes and utility functions.