1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef CSV_FILE_HXX 25 #define CSV_FILE_HXX 26 27 // USED SERVICES 28 // BASE CLASSES 29 #include <cosv/bstream.hxx> 30 #include <cosv/openclose.hxx> 31 // COMPONENTS 32 #include <stdio.h> 33 #include <cosv/string.hxx> 34 // PARAMETERS 35 #include <cosv/persist.hxx> 36 #include <cosv/ploc.hxx> 37 38 39 class FileStrategy; 40 41 42 namespace csv 43 { 44 45 46 /** @task 47 File is a class representing a file. 48 */ 49 class File : public bstream, 50 public OpenClose, 51 public ploc::Persistent 52 { 53 public: 54 // LIFECYCLE 55 File( 56 uintt i_nMode = CFM_RW ); 57 File( 58 const ::csv::ploc::Path & 59 i_rLocation, 60 uintt i_nMode = CFM_RW ); 61 File( 62 const char * i_sLocation, 63 uintt in_nMode = CFM_RW ); 64 File( 65 const String & i_sLocation, 66 uintt in_nMode = CFM_RW ); 67 virtual ~File(); 68 69 // OPERATIONS 70 bool Assign( 71 ploc::Path i_rLocation ); 72 bool Assign( 73 const char * i_sLocation ); 74 bool Assign( 75 const String & i_sLocation ); 76 // INQUIRY 77 uintt Mode() const; 78 79 private: 80 enum E_LastIO 81 { 82 io_none = 0, 83 io_read, 84 io_write 85 }; 86 87 // Interface bistream: 88 virtual uintt do_read( 89 void * out_pDest, 90 uintt i_nNrofBytes); 91 virtual bool inq_eod() const; 92 // Interface bostream: 93 virtual uintt do_write( 94 const void * i_pSrc, 95 uintt i_nNrofBytes); 96 // Interface bstream: 97 virtual uintt do_seek( 98 intt i_nDistance, 99 seek_dir i_eStartPoint = ::csv::beg ); 100 virtual uintt inq_position() const; 101 // Interface OpenClose: 102 virtual bool do_open( 103 uintt in_nOpenModeInfo ); 104 virtual void do_close(); 105 virtual bool inq_is_open() const; 106 // Interface Persistent: 107 virtual const ploc::Path & 108 inq_MyPath() const; 109 // DATA 110 ploc::Path aPath; 111 FILE * pStream; 112 113 uintt nMode; /// RWMode, OpenMode and ShareMode. 114 E_LastIO eLastIO; 115 }; 116 117 118 119 // IMPLEMENTATION 120 121 inline uintt 122 File::Mode() const 123 { return nMode; } 124 125 126 } // namespace csv 127 128 129 130 131 #endif 132