10 #ifndef __stir_UTILITIES_H__ 11 #define __stir_UTILITIES_H__ 32 template <
class NUMBER>
34 inline NUMBER
ask_num(
const std::string& prompt, NUMBER minimum_value, NUMBER maximum_value, NUMBER default_value);
37 std::string
ask_string(
const std::string& prompt,
const std::string& default_value =
"");
54 bool ask(
const std::string& prompt,
bool default_value);
104 template <
class FSTREAM>
106 FSTREAM& s,
const std::string& prompt,
const std::string& default_extension, std::ios::openmode mode,
bool abort_if_failed);
109 template <
class FSTREAM>
111 const std::string& prompt,
112 const std::string& default_extension,
113 std::ios::openmode mode)
149 template <
class IFSTREAM>
160 template <
class OFSTREAM>
173 template <
class FSTREAM>
213 extern const char*
find_filename(
const char*
const filename_with_directory);
228 std::string
get_filename(
const std::string& filename_with_directory);
240 char*
get_directory_name(
char* directory_name,
const char*
const filename_with_directory);
306 const char *
const extension);
310 std::string&
add_extension(std::string& file_in_directory_name,
const std::string& extension);
333 const char *
const extension);
337 std::string&
replace_extension(std::string& file_in_directory_name,
const std::string& extension);
349 inline char*
strupr(
char*
const str);
351 # define strupr _strupr 358 #endif // __UTILITIES_H__ char * prepend_directory_name(char *filename_with_directory, const char *const directory_name)
Prepend directory_name to the filename, but only if !is_absolute_pathname(filename_with_directory) ...
Definition: utilities.cxx:285
streamsize find_remaining_size(istream &input)
Find number of remaining characters in the stream.
Definition: utilities.cxx:379
IFSTREAM & open_read_binary(IFSTREAM &s, const std::string &name)
opens a stream for reading binary data. Calls error() when it does not succeed.
Definition: utilities.inl:53
const char * find_filename(const char *const filename_with_directory)
return a pointer to the start of the filename (i.e. after directory specifications) ...
Definition: utilities.cxx:108
const int max_filename_length
some large value to say how long filenames can be in the (deprecated) function ask_filename_with_exte...
Definition: utilities.h:191
char * get_directory_name(char *directory_name, const char *const filename_with_directory)
Copies the directory part from 'filename_with_directory' into 'directory_name' and returns the 'direc...
Definition: utilities.cxx:167
inline implementations for utility.h
string & add_extension(string &file_in_directory_name, const string &extension)
Append extension if none present.
Definition: utilities.cxx:209
NUMBER ask_num(const std::string &prompt, NUMBER minimum_value, NUMBER maximum_value, NUMBER default_value)
A function to ask a number from the user.
Definition: utilities.inl:33
char * strupr(char *const str)
make C-string uppercase
Definition: utilities.inl:95
string::size_type find_pos_of_filename(const string &filename_with_directory)
return the position of the start of the filename (i.e. after directory specifications) ...
Definition: utilities.cxx:135
void close_file(FSTREAM &s)
closes a stream without error checking.
Definition: utilities.inl:88
string ask_string(const string &str, const string &default_value)
A function to ask a string from the user.
Definition: utilities.cxx:67
string & replace_extension(string &file_in_directory_name, const string &extension)
Replace extension (or append if none present)
Definition: utilities.cxx:236
bool ask(const string &str, bool default_value)
A function to ask a yes/no question from the user.
Definition: utilities.cxx:41
void * read_stream_in_memory(std::istream &input, std::streamsize &file_size)
reads data into memory, returning a pointer to the memory
string::size_type find_pos_of_extension(const string &file_in_directory_name)
find the position of the '.' of the extension
Definition: utilities.cxx:185
basic configuration include file
string get_filename(const string &filename_with_directory)
return a std::string containing only the filename (i.e. after directory specifications) ...
Definition: utilities.cxx:161
string ask_filename_with_extension(const string &prompt, const string &default_extension)
Asks for a filename (appending an extension if none is provided).
Definition: utilities.cxx:332
OFSTREAM & open_write_binary(OFSTREAM &s, const std::string &name)
opens a stream for writing binary data. Calls error() when it does not succeed.
Definition: utilities.inl:75
void ask_filename_and_open(FSTREAM &s, const std::string &prompt, const std::string &default_extension, std::ios::openmode mode)
as above, but with default abort_if_failed = true
Definition: utilities.h:110
bool is_absolute_pathname(const char *const filename_with_directory)
Checks if the filename points to an absolute location, or is a relative (e.g. to current directory) p...
Definition: utilities.cxx:247