CLI  2.9
file_device.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2006-2018, Alexis Royer, http://alexis.royer.free.fr/CLI
3 
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of the CLI library project nor the names of its contributors may be used to endorse or promote products derived from this software
12  without specific prior written permission.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 
31 
32 #ifndef _CLI_FILE_DEVICE_H_
33 #define _CLI_FILE_DEVICE_H_
34 
35 #include <stdio.h>
36 
37 #include "cli/namespace.h"
38 #include "cli/io_device.h"
39 #include "cli/tk.h"
40 
41 
43 
44 
45  class InputFileDevice : public IODevice
46  {
47  public:
49  explicit InputFileDevice(
50  const char* const STR_FileName,
51  OutputDevice& CLI_Out,
52  const bool B_AutoDelete
55  );
56 
58  virtual ~InputFileDevice(void);
59 
60  private:
62  explicit InputFileDevice(void);
66  InputFileDevice& operator=(const InputFileDevice&);
67 
68  public:
71  InputFileDevice& EnableSpecialCharacters(
72  const bool B_EnableSpecialCharacters
73  );
74 
75  protected:
76  // Inherit doxygen comments from cli::OutputDevice interface documentation.
77  virtual const bool OpenDevice(void);
78  // Inherit doxygen comments from cli::OutputDevice interface documentation.
79  virtual const bool CloseDevice(void);
80  public:
81  // Inherit doxygen comments from cli::IODevice interface documentation.
82  virtual const KEY GetKey(void) const;
83  // Inherit doxygen comments from cli::IODevice interface documentation.
84  virtual const ResourceString GetLocation(void) const;
85  // Inherit doxygen comments from cli::OutputDevice interface documentation.
86  virtual void PutString(const char* const STR_Out) const;
87  // Inherit doxygen comments from cli::OutputDevice interface documentation.
88  virtual void Beep(void) const;
89  // Inherit doxygen comments from cli::OutputDevice interface documentation.
90  virtual void CleanScreen(void) const;
91  // Inherit doxygen comments from cli::OutputDevice interface documentation.
92  virtual const bool WouldOutput(const OutputDevice& CLI_Device) const;
93 
94  public:
97  const tk::String GetFileName(void) const;
98 
101  const int GetCurrentLine(void) const;
102 
105  const int GetCurrentColumn(void) const;
106 
107  private:
109  const tk::String m_strFileName;
110 
112  mutable FILE* m_pfFile;
113 
115  bool m_bEnableSpecialCharacters;
116 
118  OutputDevice& m_cliOutput;
119 
121  mutable tk::Queue<char> m_tkInputBuffer;
122 
124  mutable int m_iCurrentLine;
125 
127  mutable int m_iCurrentColumn;
128 
130  mutable int m_iNextLine;
131 
133  mutable int m_iNextColumn;
134  };
135 
138  {
139  public:
141  explicit OutputFileDevice(
142  const char* const STR_OutputFileName,
143  const bool B_AutoDelete
144  );
145 
147  virtual ~OutputFileDevice(void);
148 
149  private:
151  explicit OutputFileDevice(void);
155  OutputFileDevice& operator=(const OutputFileDevice&);
156 
157  protected:
158  // Inherit doxygen comments from cli::OutputDevice interface documentation.
159  virtual const bool OpenDevice(void);
160  // Inherit doxygen comments from cli::OutputDevice interface documentation.
161  virtual const bool CloseDevice(void);
162  public:
163  // Inherit doxygen comments from cli::OutputDevice interface documentation.
164  virtual void PutString(const char* const STR_Out) const;
165  // Inherit doxygen comments from cli::OutputDevice interface documentation.
166  virtual void Beep(void) const;
167 
168  public:
171  const tk::String GetFileName(void) const;
172 
173  private:
175  const tk::String m_strFileName;
176 
178  mutable FILE* m_pfFile;
179  };
180 
182 
183 #endif // _CLI_FILE_DEVICE_H_
virtual void Beep(void) const
Beep handler.
virtual const bool OpenDevice(void)
Device opening handler.
Main namespace of the CLI library.
#define CLI_NS_END(__ns)
End a namespace definition.
Definition: namespace.h:45
ResourceString class.
Namespace management.
const tk::String GetFileName(void) const
File name accessor.
virtual const bool CloseDevice(void)
Device closure handler.
Input file device class.
Definition: file_device.h:45
Generic output device.
Definition: io_device.h:256
enum _KEY KEY
Input keys.
#define CLI_NS_BEGIN(__ns)
Begin a namespace definition.
Definition: namespace.h:38
OutputDevice, IODevice and IOEndl classes defintion.
CLI toolkit definition.
virtual ~OutputFileDevice(void)
Destructor.
virtual void PutString(const char *const STR_Out) const
Output handler.
Output file device.
Definition: file_device.h:137
Generic input/output device.
Definition: io_device.h:581