xref: /aoo41x/main/cosv/inc/cosv/file.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef CSV_FILE_HXX
29 #define CSV_FILE_HXX
30 
31 // USED SERVICES
32 	// BASE CLASSES
33 #include <cosv/bstream.hxx>
34 #include <cosv/openclose.hxx>
35 	// COMPONENTS
36 #include <stdio.h>
37 #include <cosv/string.hxx>
38 	// PARAMETERS
39 #include <cosv/persist.hxx>
40 #include <cosv/ploc.hxx>
41 
42 
43 class FileStrategy;
44 
45 
46 namespace csv
47 {
48 
49 
50 /**	@task
51 	File is a class representing a file.
52 */
53 class File : public bstream,
54              public OpenClose,
55              public ploc::Persistent
56 {
57   public:
58 	// LIFECYCLE
59 						File(
60 							uintt 			i_nMode = CFM_RW );
61 						File(
62 							const ::csv::ploc::Path &
63                                             i_rLocation,
64 							uintt 			i_nMode = CFM_RW );
65 						File(
66 							const char *	i_sLocation,
67 							uintt 			in_nMode = CFM_RW );
68 						File(
69 							const String &  i_sLocation,
70 							uintt 			in_nMode = CFM_RW );
71     virtual 		    ~File();
72 
73     // OPERATIONS
74     bool			    Assign(
75 							ploc::Path 		i_rLocation );
76 	bool	            Assign(
77 							const char *	i_sLocation );
78 	bool	            Assign(
79 							const String &  i_sLocation );
80     //	INQUIRY
81 	uintt               Mode() const;
82 
83   private:
84     enum E_LastIO
85     {
86         io_none = 0,
87         io_read,
88         io_write
89     };
90 
91     // Interface bistream:
92 	virtual uintt 		do_read(
93 							void *	        out_pDest,
94 							uintt           i_nNrofBytes);
95 	virtual bool		inq_eod() const;
96     // Interface bostream:
97 	virtual uintt 		do_write(
98 							const void *   	i_pSrc,
99 							uintt           i_nNrofBytes);
100     // Interface bstream:
101 	virtual uintt 		do_seek(
102 							intt 			i_nDistance,
103                             seek_dir        i_eStartPoint = ::csv::beg );
104 	virtual uintt 		inq_position() const;
105     // Interface OpenClose:
106     virtual bool   	    do_open(
107 							uintt 			in_nOpenModeInfo );
108     virtual void   	    do_close();
109     virtual bool        inq_is_open() const;
110     // Interface Persistent:
111 	virtual const ploc::Path &
112                         inq_MyPath() const;
113     // DATA
114     ploc::Path          aPath;
115     FILE *              pStream;
116 
117     uintt 			    nMode;		        /// RWMode, OpenMode and ShareMode.
118     E_LastIO            eLastIO;
119 };
120 
121 
122 
123 // IMPLEMENTATION
124 
125 inline uintt
126 File::Mode() const
127     { return nMode; }
128 
129 
130 }   // namespace csv
131 
132 
133 
134 
135 #endif
136 
137 
138