nis-util  1.0.D108
lib/input.h
Go to the documentation of this file.
00001 //
00002 // nis-util - NIS Administration Utilities
00003 // Copyright (C) 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License along
00016 // with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #ifndef LIB_INPUT_H
00020 #define LIB_INPUT_H
00021 
00022 #include <lib/ac/stddef.h>
00023 #include <boost/shared_ptr.hpp>
00024 #include <lib/source_location.h>
00025 
00030 class input
00031 {
00032 public:
00033     typedef boost::shared_ptr<input> pointer;
00034 
00038     virtual ~input();
00039 
00044     static const int eof = -1;
00045 
00054     int
00055     get(void)
00056     {
00057         if (pos >= avail)
00058             return underflow();
00059         unsigned char c = buf[pos++];
00060         if (c == '\n')
00061             ++relative_line_number;
00062         return c;
00063     }
00064 
00075     void unget(int c);
00076 
00085     source_location get_source_location(void);
00086 
00097     bool read_one_line(source_location &line_locn, rcstring &line);
00098 
00099 protected:
00104     input();
00105 
00110     static int count_newlines(const void *data, size_t data_size);
00111 
00112 private:
00117     int underflow(void);
00118 
00127     unsigned char *buf;
00128 
00136     size_t buf_allocated;
00137 
00146     size_t pos;
00147 
00156     size_t avail;
00157 
00164     long relative_line_number;
00165 
00183     virtual size_t read_inner(source_location &data_locn, void *data,
00184         size_t data_size) = 0;
00185 
00192     source_location buf_locn;
00193 
00194     void refill(void);
00195 
00203     input(const input &rhs);
00204 
00212     input &operator=(const input &rhs);
00213 };
00214 
00215 // vim: set ts=8 sw=4 et :
00216 #endif // LIB_INPUT_H