28 #ifndef L_STDIO_WRAP_H_UOFARIZONA_VISION
29 #define L_STDIO_WRAP_H_UOFARIZONA_VISION
31 #include <l/l_sys_lib.h>
32 #include <l/l_sys_io.h>
33 #include <l/l_error.h>
34 #include <l/l_global.h>
38 #include <boost/scoped_ptr.hpp>
75 +
" with mode " + mode );
82 File_Ptr(
const std::string& pathname,
const char* mode )
83 : m_fp( kjb_c::kjb_fopen( pathname.c_str(), mode ) )
107 int rc = kjb_c::kjb_fclose( m_fp );
119 operator FILE*()
const
183 std::string m_filename;
193 int rc1 = 0, rc2 = 0;
194 if ( m_filename.size() )
197 rc2 = kjb_c::kjb_unlink( m_filename.c_str() );
222 #warning "On non-Unix style systems, class Temporary_File does not work."
249 std::string m_pathname;
261 return kjb_c::kjb_rmdir( m_pathname.c_str() );
266 return kjb_c::kjb_system( (
"rm -rf " + m_pathname).c_str() );
271 const std::string& fail_func
274 using namespace kjb_c;
276 if ( 0 == m_pathname.size() )
return NO_ERROR;
278 int rc = (
this ->* pf_cleaning)();
279 if ( ! is_directory( m_pathname.c_str() ) ) m_pathname.clear();
283 add_error((
"Temporary_Directory::"+ fail_func +
" failed").c_str());
305 return do_the_cleaning( & Temporary_Directory::do_rmdir, __func__ );
311 return do_the_cleaning( & Temporary_Directory::do_rmrf, __func__ );
317 int status =
remove();
320 using namespace kjb_c;
326 #warning "On non-Unix style systems, class Temporary_Directory does not work."
329 int remove() {
return kjb_c::NO_ERROR; }
355 std::swap(m_silence, new_silence_setting);
356 return new_silence_setting;
370 using namespace kjb_c;
375 #warning "class Temporary_Recursively_Removing_Directory unavailable w/o Unix."
415 boost::scoped_ptr< Temporary_File > temp;
417 void attempt_unzip(
const std::string& );
431 attempt_unzip( filename );
444 std::string get_temp_filename()
const
448 return temp -> get_filename();
454 #warning "On non-Unix style systems, class File_Ptr_Smart_Read does not work."
488 int getline( FILE* fp, std::string* line,
char EOL =
'\n' );
File_Ptr_Smart_Read(const std::string &fn)
Definition: l_stdio_wrap.h:456
This class transparently opens gzipped or bzip2-ed files.
Definition: l_stdio_wrap.h:412
File_Ptr_Append(const std::string &pathname)
Definition: l_stdio_wrap.h:141
RAII wrapper on stdio.h FILE pointers (use a derived class though).
Definition: l_stdio_wrap.h:60
File_Ptr_Read_Plus(const std::string &pathname)
Definition: l_stdio_wrap.h:148
File_Ptr_Read(const std::string &pathname)
Definition: l_stdio_wrap.h:127
#define ASSERT(condition, message)
Definition: Assert.h:45
~Temporary_Recursively_Removing_Directory()
Definition: l_stdio_wrap.h:368
int recursively_remove()
Definition: l_stdio_wrap.h:330
int close()
close file before destruction; rarely needed; safe to do twice.
Definition: l_stdio_wrap.h:225
Temporary_Recursively_Removing_Directory()
Definition: l_stdio_wrap.h:364
this class creates a temporary directory under TEMP_DIR (usu. /tmp)
Definition: l_stdio_wrap.h:247
virtual ~File_Ptr()
dtor can simply call close() because closing a null ptr is OK.
Definition: l_stdio_wrap.h:113
Temporary_Directory()
Definition: l_stdio_wrap.h:328
create a temp directory that destroys itself with "rm -rf" command.
Definition: l_stdio_wrap.h:362
File_Ptr(const std::string &pathname, const char *mode)
ctor needs the pathname and a mode; mode is set by derived class
Definition: l_stdio_wrap.h:82
RAII wrapper on FILE* used to append a file (write only at the end).
Definition: l_stdio_wrap.h:140
RAII wrapper on a FILE* used to write to a file.
Definition: l_stdio_wrap.h:133
File_Ptr_Write(const std::string &pathname)
Definition: l_stdio_wrap.h:134
virtual int close()
close file before destruction; rarely needed; safe to do twice.
Definition: l_stdio_wrap.h:105
This class safely opens a temporary file in TEMP_DIR (usually /tmp).
Definition: l_stdio_wrap.h:180
RAII wrapper on FILE* opened with mode "r+" to read and write.
Definition: l_stdio_wrap.h:147
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
RAII wrapper on FILE* used to read a file.
Definition: l_stdio_wrap.h:126
const std::string & get_filename() const
Definition: l_stdio_wrap.h:226
int getline(FILE *fp, std::string *line, char EOL= '\n')
Like C's fgets but with std::string, or C++'s getline but with FILE*.
Temporary_File()
Definition: l_stdio_wrap.h:224
const std::string & get_pathname() const
get the filename of this object (if still valid)
Definition: l_stdio_wrap.h:340
Object thrown when input or output fails.
Definition: l_exception.h:496
Support for error handling exception classes in libKJB.
File_Ptr()
default ctor wraps a null pointer (to set up a later swap maybe)
Definition: l_stdio_wrap.h:92
void swap(File_Ptr &that)
swap the contents of two wrappers
Definition: l_stdio_wrap.h:97
bool set_silence_flag(bool new_silence_setting=true)
By default the dtor prints errors (if any) – you can suppress it.
Definition: l_stdio_wrap.h:353
void throw_io_error(const std::string &pathname, const char *mode)
this is what we do when things go terribly wrong
Definition: l_stdio_wrap.h:72
std::string get_temp_filename() const
Definition: l_stdio_wrap.h:457