ARTS 2.5.9 (git: 825fa5f2)
file.h
Go to the documentation of this file.
1/* Copyright (C) 2000-2012 Stefan Buehler <sbuehler@ltu.se>
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 USA. */
17
19// File description
21
30#ifndef file_h
31#define file_h
32
33#include <fstream>
34
35#include "double_imanip.h"
36#include "messages.h"
37#include "mystring.h"
38
40// Default file names
42
43void filename_ascii(String& filename, const String& varname);
44
45void filename_bin(String& filename, const std::string_view varname);
46
48// Functions to open and read ASCII files
50
51void open_output_file(std::ofstream& file, const std::string_view name);
52
53void cleanup_output_file(std::ofstream& file, const std::string_view name);
54
55void open_input_file(std::ifstream& file, const std::string_view name);
56
57[[nodiscard]] ArrayOfString read_text_from_stream(std::istream& is);
58
59[[nodiscard]] ArrayOfString read_text_from_file(const std::string_view name);
60
61void replace_all(String& s, const std::string_view what, const std::string_view with);
62
63[[nodiscard]] int check_newline(const std::string_view s);
64
65[[nodiscard]] bool file_exists(const std::string_view filename);
66
67bool find_file(ArrayOfString& matches,
68 const std::string_view filename,
69 const ArrayOfString& paths,
70 const ArrayOfString& extensions = {""});
71
72void find_xml_file(String& filename, const Verbosity& verbosity);
73
74[[nodiscard]] bool find_xml_file_existence(String& filename);
75
76[[nodiscard]] String expand_path(String path);
77
78[[nodiscard]] String add_basedir(const std::string_view path);
79
80[[nodiscard]] String get_dirname(const std::string_view path);
81
82[[nodiscard]] ArrayOfString list_directory(const std::string_view dirname);
83
84[[nodiscard]] String make_filename_unique(const std::string_view filename, const String& extension = "");
85
86#endif
Fast double input stream with support for parsing nan and inf.
ArrayOfString list_directory(const std::string_view dirname)
Return list of files in directory.
Definition: file.cc:487
ArrayOfString read_text_from_file(const std::string_view name)
Reads an ASCII file and appends the contents to the String vector text.
Definition: file.cc:203
void open_output_file(std::ofstream &file, const std::string_view name)
String make_filename_unique(const std::string_view filename, const String &extension="")
Make filename unique.
Definition: file.cc:513
String add_basedir(const std::string_view path)
Definition: file.cc:441
void find_xml_file(String &filename, const Verbosity &verbosity)
Find an xml file.
Definition: file.cc:355
ArrayOfString read_text_from_stream(std::istream &is)
bool find_xml_file_existence(String &filename)
As find_xml_file but does not throw in the main body.
Definition: file.cc:394
String expand_path(String path)
Definition: file.cc:422
void replace_all(String &s, const std::string_view what, const std::string_view with)
Replace all occurances of ‘what’ in ‘s’ with ‘with’.
Definition: file.cc:232
void filename_ascii(String &filename, const String &varname)
Gives the default file name for the ASCII formats.
Definition: file.cc:60
void cleanup_output_file(std::ofstream &file, const std::string_view name)
void filename_bin(String &filename, const std::string_view varname)
bool find_file(ArrayOfString &matches, const std::string_view filename, const ArrayOfString &paths, const ArrayOfString &extensions={""})
Searches through paths for a file with a matching name.
Definition: file.cc:301
void open_input_file(std::ifstream &file, const std::string_view name)
int check_newline(const std::string_view s)
Checks if there is exactly one newline character at the end of the string.
Definition: file.cc:250
bool file_exists(const std::string_view filename)
Checks if the given file exists.
Definition: file.cc:282
String get_dirname(const std::string_view path)
Return the parent directory of a path.
Definition: file.cc:461
Declarations having to do with the four output streams.
This file contains the definition of String, the ARTS string class.