Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
StdioFileEx.h
Go to the documentation of this file.
1//! @file StdioFileEx.h
2//! @brief CStdioFileEx is an advanced class for reading / writing text file.
3//!
4// Version 1.1 23 August 2003. Incorporated fixes from Dennis Jeryd.
5// Version 1.3 19 February 2005. Incorporated fixes from Howard J Oh and some of my own.
6// Version 1.4 26 February 2005. Fixed stupid screw-up in code from 1.3.
7// Version 1.5 18 November 2005. - Incorporated fixes from Andy Goodwin.
8// - Allows code page to be specified for reading/writing
9// - Properly calculates multibyte buffer size instead of
10// assuming lstrlen(s).
11// - Should handle UTF8 properly.
12//
13// Copyright David Pritchard 2003-2005. davidpritchard@ctv.es
14//
15// You can use this class freely, but please keep my ego happy
16// by leaving this comment in place.
17//
18//////////////////////////////////////////////////////////////////////
19
20#if !defined(AFX_STDIOFILEEX_H__41AFE3CA_25E0_482F_8B00_C40775BCDB81__INCLUDED_)
21#define AFX_STDIOFILEEX_H__41AFE3CA_25E0_482F_8B00_C40775BCDB81__INCLUDED_
22
23#ifdef _MSC_VER
24#pragma once
25#endif // _MSC_VER
26
27BEGIN_MOOTOOLS_NAMESPACE
28
29#ifndef CStdioFileEx
30
31#define nUNICODE_BOM ((unsigned short)(0xFEFF)) // Unicode "byte order mark" which goes at start of file
32#define sNEWLINE _T("\r\n") // New line characters
33#define sDEFAULT_UNICODE_FILLER_CHAR "#" // Filler char used when no conversion from Unicode to local code page is possible
34
35////////////////////////////////////////////////////////////////////////////////////////////////
36//! @class CStdioFileEx
37//! @brief CStdioFileEx reads or write unicode or ansi / utf8 string and convert them to CXString using string conversion if needed.
38//! @details
39//!
40class DLL_TOOLSFUNCTION CStdioFileEx : public CXStdioFile
41{
42 DECLARE_DYNAMIC_XOBJECT(CStdioFileEx)
43
44 public:
45 CStdioFileEx(bool allowException = true);
47
48 virtual ~CStdioFileEx();
49
50 //! It implements a secured version of fscanf on OS that support it: FcanS(_T("%s", SCANS_TEXT_PARAM(buf, _countof(buf)), SCANS_LAST_PARAM);
51 //! * uses SCANS_TEXT_PARAM for each %s param
52 //! * terminates the list by NULL (SCANS_LAST_PARAM)
53 //! * the function returned the number of argument scanned
54 virtual int FScanfS(const LPCTSTR format, ...);
55
56 virtual bool Open(LPCTSTR lpszFileName, unsigned int nOpenFlags, CXFileException* pError = NULL ); //!< nOpenFlags is a combination of CXFile::OpenFlags
57 virtual bool ReadString(CXString& rString); //!< Read a CXString whatever if the file is encoded in unicode or utf8
58 virtual fileuint Seek(longint lOff, CXFile::SeekPosition nFrom);
59
60 virtual void WriteString( LPCTSTR lpsz ); //!< Write a CXString. The string is converted accordingly is the file is opened using modeWriteUnicode
61 inline bool IsFileUnicodeText() const { return IsStringEncodingUnicode(stringEncoding); }
62 inline bool IsFileUTF8() const { return (stringEncoding == xStringUtf8); }
63 fileuint GetCharCount();
64 void SkipLines(unsigned int lines, unsigned int nFrom);
65
66 //! @enum OpenFlags
67 //! @brief Additional flags to CXFile::OpenFlags
69 {
70 modeWriteUnicode = specificFlags, //!< equivalent to CXFile::typeUnicode
71 };
72
73 void SetCodePage(xStringEncoding codPage); //!< A code page could be provided on Windows
74
75
76 static xStringEncoding GetFileEncoding(const CXString& sFilePath, bool& asBoom); //!< Returns the file encoding and check if there is a boom marker
77
78 protected:
79 void Init();
80 void SkipBoom();
81
82 unsigned int ProcessFlags(const CXString& sFilePath, unsigned int& nOpenFlags);
83 bool CheckCarriageReturn();
84
85 bool skipBoom, asBoom;
86 xStringEncoding stringEncoding;
87 unsigned int fileFlags;
88
89 bool specialCarriage;
90 int specialCarriageTokenPos;
91 CXStringA aString;
92 CXStringW wString;
93 CXString specialCarriageLine; // only used when specialCarriage is set
94
95 //int unicodeStringSize, charStringSize;
96 //wchar_t *unicodeString;
97 //char *charString;
98
99 //wchar_t *AllocUnicodeString(int size);
100 //char *AllocCharString(int size);
101};
102
103#endif // CStdioFileEx
104
105END_MOOTOOLS_NAMESPACE
106
107#endif // !defined(AFX_STDIOFILEEX_H__41AFE3CA_25E0_482F_8B00_C40775BCDB81__INCLUDED_)
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
CStdioFileEx reads or write unicode or ansi / utf8 string and convert them to CXString using string c...
Definition StdioFileEx.h:41
virtual bool ReadString(CXString &rString)
Read a CXString whatever if the file is encoded in unicode or utf8.
void SetCodePage(xStringEncoding codPage)
A code page could be provided on Windows.
virtual void WriteString(LPCTSTR lpsz)
Write a CXString. The string is converted accordingly is the file is opened using modeWriteUnicode.
static xStringEncoding GetFileEncoding(const CXString &sFilePath, bool &asBoom)
Returns the file encoding and check if there is a boom marker.
OpenFlags
Additional flags to CXFile::OpenFlags.
Definition StdioFileEx.h:69
virtual bool Open(LPCTSTR lpszFileName, unsigned int nOpenFlags, CXFileException *pError=NULL)
nOpenFlags is a combination of CXFile::OpenFlags
virtual int FScanfS(const LPCTSTR format,...)
@ specificFlags
Override class mode base flags.
Definition XFile.h:74
CXStdioFile reads or write strings from the file.
Definition XStdioFile.h:24