feisty meow concerns codebase  2.140
byte_filer.h
Go to the documentation of this file.
1 #ifndef BYTE_FILER_CLASS
2 #define BYTE_FILER_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : byte_filer *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2000-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/astring.h>
19 #include <basis/byte_array.h>
20 #include <basis/definitions.h>
21 
22 #include "filename.h"
23 
24 namespace filesystem {
25 
26 // forward declarations.
27 class file_hider;
28 
30 
32 {
33 public:
34  byte_filer();
36 
38  byte_filer(const basis::astring &fname, const basis::astring &permissions);
40 
52  byte_filer(const char *fname, const char *permissions);
54 
55  byte_filer(bool auto_close, void *opened);
57 
61  ~byte_filer();
62 
63  static size_t file_size_limit();
65 
67  bool open(const basis::astring &fname, const basis::astring &permissions);
69 
71  void close();
73 
75  const basis::astring &name() const;
77 
78  bool good();
80 
81  size_t length();
83 
86  size_t tell();
88 
90  void flush();
92 
93  enum origins {
97  };
98 
99  bool seek(int where, origins origin = FROM_START);
101 
105  bool eof();
107 
108  int read(basis::abyte *buffer, int buffer_size);
110 
112  int write(const basis::abyte *buffer, int buffer_size);
114 
115  int read(basis::byte_array &buffer, int desired_size);
117  int write(const basis::byte_array &buffer);
119 
120  int read(basis::astring &buffer, int desired_size);
122 
128  int write(const basis::astring &buffer, bool add_null = false);
130 
134  int getline(basis::abyte *buffer, int desired_size);
136  int getline(basis::byte_array &buffer, int desired_size);
138  int getline(basis::astring &buffer, int desired_size);
140 
141  bool truncate();
143 
144  void *file_handle();
146 
148 private:
149  file_hider *_handle;
150  filename *_filename;
151  bool _auto_close;
152 
153  // not to be called.
154  byte_filer(const byte_filer &);
155  byte_filer &operator =(const byte_filer &);
156 };
157 
158 } //namespace.
159 
160 #endif
161 
const int buffer_size
Definition: checker.cpp:37
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
Provides file managment services using the standard I/O support.
Definition: byte_filer.h:32
int getline(basis::abyte *buffer, int desired_size)
reads a line of text (terminated by a return) into the "buffer".
Definition: byte_filer.cpp:201
static size_t file_size_limit()
returns the maximum size that seek and length can support.
Definition: byte_filer.cpp:84
int write(const basis::abyte *buffer, int buffer_size)
writes "buffer_size" bytes into the file from "buffer".
Definition: byte_filer.cpp:126
void * file_handle()
provides a hook to get at the operating system's file handle.
Definition: byte_filer.cpp:119
byte_filer()
constructs an object that doesn't access a file yet.
Definition: byte_filer.cpp:52
void close()
shuts down the open file, if any.
Definition: byte_filer.cpp:96
@ FROM_START
offset is from the beginning of the file.
Definition: byte_filer.h:94
@ FROM_CURRENT
offset is from current cursor position.
Definition: byte_filer.h:96
@ FROM_END
offset is from the end of the file.
Definition: byte_filer.h:95
bool seek(int where, origins origin=FROM_START)
places the cursor in the file at "where", based on the "origin".
Definition: byte_filer.cpp:187
const basis::astring & name() const
returns the file name that the object is operating on.
Definition: byte_filer.cpp:82
int read(basis::abyte *buffer, int buffer_size)
reads "buffer_size" bytes from the file into "buffer".
Definition: byte_filer.cpp:123
bool eof()
returns true if the cursor is at (or after) the end of the file.
Definition: byte_filer.cpp:121
size_t tell()
returns the current position within the file, in terms of bytes.
Definition: byte_filer.cpp:105
void flush()
forces any pending writes to actually be saved to the file.
Definition: byte_filer.cpp:165
size_t length()
returns the file's total length, in bytes.
Definition: byte_filer.cpp:140
bool truncate()
truncates the file after the current position.
Definition: byte_filer.cpp:171
bool good()
returns true if the file seems to be in the appropriate desired state.
Definition: byte_filer.cpp:103
bool open(const basis::astring &fname, const basis::astring &permissions)
opens a file with "fname" and "permissions" as in the constructor.
Definition: byte_filer.cpp:86
Provides operations commonly needed on file names.
Definition: filename.h:64
Constants and objects used throughout HOOPLE.
unsigned char abyte
A fairly important unit which is seldom defined...
Definition: definitions.h:51
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37