_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

iolib.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 2000-2005 by Andreas Arens
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 //
29 
30 #ifndef __IOLIB_H__
31 #define __IOLIB_H__
32 
34 
35 /*----------------------------------------------------------------------------
36 -- Includes
37 ----------------------------------------------------------------------------*/
38 
39 #include <vector>
40 #include "SDL.h"
41 
42 /*----------------------------------------------------------------------------
43 -- Definitons
44 ----------------------------------------------------------------------------*/
45 
50 {
51 };
52 
53 
58 {
59 public:
60  virtual ~FileWriter() {}
61 
62  void printf(const char *format, ...) PRINTF_VAARG_ATTRIBUTE(2, 3); // Don't forget to count this
63 
64  virtual int write(const char *data, unsigned int size) = 0;
65 };
66 
67 
74 FileWriter *CreateFileWriter(const std::string &filename);
75 
79 class FileList
80 {
81 public:
82  FileList() : type(0) {}
83 
84  bool operator < (const FileList &rhs) const
85  {
86  if (type != rhs.type) {
87  return type < rhs.type;
88  }
89  return name < rhs.name;
90  }
91 public:
92  std::string name;
93  int type;
94 };
95 
96 
102 class CFile
103 {
104 public:
105  CFile();
106  ~CFile();
107 
108  int open(const char *name, long flags);
109  int close();
110  void flush();
111  int read(void *buf, size_t len);
112  int seek(long offset, int whence);
113  long tell();
114  SDL_RWops * as_SDL_RWops();
115 
116  int printf(const char *format, ...) PRINTF_VAARG_ATTRIBUTE(2, 3); // Don't forget to count this
117 private:
118  CFile(const CFile &rhs); // No implementation
119  const CFile &operator = (const CFile &rhs); // No implementation
120 private:
121  class PImpl;
122  PImpl *pimpl;
123 };
124 
125 enum {
130 };
131 
132 #define CL_OPEN_READ 0x1
133 #define CL_OPEN_WRITE 0x2
134 #define CL_WRITE_GZ 0x4
135 #define CL_WRITE_BZ2 0x8
136 
137 /*----------------------------------------------------------------------------
138 -- Functions
139 ----------------------------------------------------------------------------*/
140 
142 extern std::string LibraryFileName(const char *file);
143 
144 extern bool CanAccessFile(const char *filename);
145 
147 extern int ReadDataDirectory(const char *dirname, std::vector<FileList> &flp);
148 
149 extern std::vector<std::string> QuoteArguments(std::vector<std::string> args);
150 
152 
153 #endif // !__IOLIB_H__
FileWriter::write
void virtual int write(const char *data, unsigned int size)=0
FileWriter::printf
void printf(const char *format,...) PRINTF_VAARG_ATTRIBUTE(2
Definition: iolib.cpp:773
FileException
Definition: iolib.h:49
operator<
bool operator<(const Vec2T< T > &lhs, const Vec2T< T > &rhs)
Definition: vec2i.h:60
CLF_TYPE_INVALID
@ CLF_TYPE_INVALID
Definition: iolib.h:126
FileList
Definition: iolib.h:79
FileWriter::~FileWriter
virtual ~FileWriter()
Definition: iolib.h:60
ReadDataDirectory
int ReadDataDirectory(const char *dirname, std::vector< FileList > &flp)
Read the contents of a directory.
Definition: iolib.cpp:711
QuoteArguments
std::vector< std::string > QuoteArguments(std::vector< std::string > args)
Definition: iolib.cpp:854
CFile::PImpl
Definition: iolib.cpp:61
FileList::type
int type
Name of the file.
Definition: iolib.h:93
CanAccessFile
bool CanAccessFile(const char *filename)
Definition: iolib.cpp:692
CLF_TYPE_GZIP
@ CLF_TYPE_GZIP
plain text file handle
Definition: iolib.h:128
CreateFileWriter
FileWriter * CreateFileWriter(const std::string &filename)
Definition: iolib.cpp:840
CLF_TYPE_BZIP2
@ CLF_TYPE_BZIP2
gzip file handle
Definition: iolib.h:129
FileList::name
std::string name
Definition: iolib.h:92
LibraryFileName
std::string LibraryFileName(const char *file)
Build library path name.
Definition: iolib.cpp:677
FileList::FileList
FileList()
Definition: iolib.h:82
CLF_TYPE_PLAIN
@ CLF_TYPE_PLAIN
invalid file handle
Definition: iolib.h:127
PRINTF_VAARG_ATTRIBUTE
#define PRINTF_VAARG_ATTRIBUTE(a, b)
Definition: stratagus.h:108
FileWriter
Definition: iolib.h:57
CFile
Definition: iolib.h:102
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.