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