9#ifndef IMPKERNEL_FILE_H
10#define IMPKERNEL_FILE_H
12#include <IMP/kernel_config.h>
14#include "internal/ifile.h"
26IMPKERNEL_BEGIN_NAMESPACE
28#if !defined(IMP_DOXYGEN)
29template <
class Stream>
32 PointerMember<Object> ptr_;
33 TextProxy(Stream *str, Object *ptr) : str_(str), ptr_(ptr) {}
50class IMPKERNELEXPORT TextOutput :
public InputAdaptor {
51 std::shared_ptr<internal::IOStorage<std::ostream>> out_;
58 TextOutput(
const char *c,
bool append =
false);
59 TextOutput(TextProxy<std::ostream> p);
62 TextOutput(std::string file_name,
bool append =
false);
64 TextOutput(std::ostream &out, std::string name =
"C++ stream");
67#if !defined(SWIG) && !defined(IMP_DOXYGEN)
68 operator std::ostream &() {
return get_stream(); }
70 std::ostream &get_stream() {
71 IMP_USAGE_CHECK(out_,
"Attempting to write to uninitialized text input");
72 return out_->get_stream();
76 std::string get_name()
const {
return out_->get_name(); }
89class IMPKERNELEXPORT TextInput :
public InputAdaptor {
90 std::shared_ptr<internal::IOStorage<std::istream>> in_;
97 TextInput(
const char *c);
98 TextInput(TextProxy<std::istream> p);
101 TextInput(std::string file_name);
103 TextInput(std::istream &out, std::string name =
"C++ stream");
106#if !defined(SWIG) && !defined(IMP_DOXYGEN)
107 operator std::istream &() {
return get_stream(); }
108 std::istream &get_stream() {
110 IMP_THROW(
"Attempting to read from uninitialized text input",
113 return in_->get_stream();
118 std::string get_name()
const {
return in_->get_name(); }
145class SetLogTarget :
public RAII {
168 std::string suffix =
"");
176 std::string suffix =
"");
187 std::string relative);
199IMPKERNEL_END_NAMESPACE
A shared base class to help in debugging and things.
A nullptr-initialized pointer to an IMP Object.
Temporarily change something; undo the change when object destroyed.
Helper macros for throwing and handling exceptions.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
An input/output exception.
void set_binary_open_mode(bool binary)
Control whether to open the file in text or binary mode.
#define IMP_SAFE_BOOL(Name, expr)
Exception definitions and assertions.
std::string create_temporary_file_name(std::string prefix="imp_temp", std::string suffix="")
Create a temporary file.
std::string get_absolute_path(std::string file)
Convert a possibly relative path to an absolute path.
void set_log_target(TextOutput l)
Set the target for the log.
std::string get_relative_path(std::string base, std::string relative)
Return a path to a file relative to another file.
IMP::Vector< TextOutput > TextOutputs
IMP::Vector< TextInput > TextInputs
TextOutput create_temporary_file(std::string prefix="imp_temp", std::string suffix="")
Create a temporary file. The path can be extracted from the TextOutput.
Macros to aid in writing RAII-style classes.
#define IMP_RAII(Name, args, Initialize, Set, Reset, Show)
Declares RAII-style methods in a class.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Macros to help in implementing Value objects.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.