File: LevelDirectoryManager.h

package info (click to toggle)
transcend 0.3.dfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 5,832 kB
  • ctags: 2,912
  • sloc: cpp: 26,890; ansic: 693; sh: 210; makefile: 131; perl: 67
file content (172 lines) | stat: -rw-r--r-- 4,566 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Modification History
 *
 * 2004-June-15   Jason Rohrer
 * Created.
 *
 * 2004-June-17   Jason Rohrer
 * Added function for reading values from level files.
 *
 * 2004-June-21   Jason Rohrer
 * Added function for reading int values.
 */



#ifndef LEVEL_DIRECTORY_MANAGER_INCLUDED
#define LEVEL_DIRECTORY_MANAGER_INCLUDED



#include "minorGems/io/file/File.h"


#include <stdio.h>



/**
 * A wrapper class to ensure destruction of a file object at system exit.
 */
class StaticLevelDirectoryFileWrapper {

    public:

        StaticLevelDirectoryFileWrapper();
        
        ~StaticLevelDirectoryFileWrapper();

        File *mFile;
    };



/**
 * A class with static functions for setting and obtaining the current
 * level directory.
 *
 * @author Jason Rohrer.
 */
class LevelDirectoryManager {


    public:


        
        /**
         * Sets the directory where level files are stored.
         *
         * @param inFile the directory file object, or NULL to switch
         *   back to the default location.
         *   Will be destroyed by this class.
         */
        static void setLevelDirectory( File *inFile );

        

        /**
         * Gets the current level directory.
         *
         * @return the directory file object.
         *   Must be destroyed by caller.
         */
        static File *getLevelDirectory();


        /**
         * Gets a File object for a level file.
         *
         * @param inFileName the name of the file.
         *   Must be destroyed by caller.
         * @param inShowErrorMessage true to automatically print an error
         *   message to std out.  Defaults to false.
         *
         * @return the stream, or NULL if getting the file from the directory
         *   fails. Must be closed by caller.
         */
        static File *getLevelFile( char *inFileName,
                                   char inPrintErrorMessage = false );


        
        /**
         * Gets a std stream for a level file.
         *
         * @param inFileName the name of the file.
         *   Must be destroyed by caller.
         * @param inShowErrorMessage true to automatically print an error
         *   message to std out.  Defaults to false.
         *
         * @return the stream, or NULL if opening the stream fails.
         *   Must be closed by caller.
         */
        static FILE *getStdStream( char *inFileName,
                                   char inPrintErrorMessage = false );


        
        /**
         * Reads the contents of a level file as a string.
         *
         * @param inFileName the name of the file.
         *   Must be destroyed by caller.
         * @param inShowErrorMessage true to automatically print an error
         *   message to std out.  Defaults to false.
         *
         * @return the file contents, or NULL if reading from the file fails.
         *   Must be destroyed by caller.
         */
        static char *readFileContents( char *inFileName,
                                       char inPrintErrorMessage = false );

        

        /**
         * Reads a single double value from a level file.
         *
         * @param inFileName the name of the file.
         *   Must be destroyed by caller.
         * @param outError pointer to where the error flag should be returned.
         *   Will be set to true if reading a double from the file fails.
         * @param inShowErrorMessage true to automatically print an error
         *   message to std out.  Defaults to false.
         *
         * @return the first double value in the file.
         */
        static double readDoubleFileContents(
            char *inFileName,
            char *outError,
            char inPrintErrorMessage = false );



        /**
         * Reads a single int value from a level file.
         *
         * @param inFileName the name of the file.
         *   Must be destroyed by caller.
         * @param outError pointer to where the error flag should be returned.
         *   Will be set to true if reading a double from the file fails.
         * @param inShowErrorMessage true to automatically print an error
         *   message to std out.  Defaults to false.
         *
         * @return the first int value in the file.
         */
        static int readIntFileContents(
            char *inFileName,
            char *outError,
            char inPrintErrorMessage = false );

        
        
    protected:

        static StaticLevelDirectoryFileWrapper mFileWrapper;

        
    };



#endif