Merge lp:~hjd/widelands/class-FileSystem into lp:widelands

Proposed by Hans Joachim Desserud
Status: Merged
Merged at revision: 6488
Proposed branch: lp:~hjd/widelands/class-FileSystem
Merge into: lp:widelands
Diff against target: 198 lines (+19/-16)
13 files modified
src/game_io/game_data_packet.h (+1/-1)
src/game_io/game_loader.h (+1/-1)
src/game_io/game_saver.h (+1/-1)
src/graphic/font_handler1.h (+1/-1)
src/io/filesystem/disk_filesystem.h (+2/-1)
src/io/filesystem/filesystem.h (+2/-1)
src/io/filesystem/layered_filesystem.h (+4/-2)
src/io/filesystem/zip_filesystem.h (+2/-3)
src/map_io/widelands_map_data_packet.h (+1/-1)
src/map_io/widelands_map_loader.h (+1/-1)
src/map_io/widelands_map_object_packet.h (+1/-1)
src/map_io/widelands_map_saver.h (+1/-1)
src/profile/profile.h (+1/-1)
To merge this branch: bzr merge lp:~hjd/widelands/class-FileSystem
Reviewer Review Type Date Requested Status
SirVer Approve
Mark Scott Approve
Review via email: mp+142364@code.launchpad.net

Description of the change

From my previous patch I got the impression classes were preferred. Therefore, here is a struct converted to class since it was referred to as both in different places.

To post a comment you must log in.
Revision history for this message
Mark Scott (mxsscott) wrote :

Looks fine.

Here's some information on struct vs class. It is purely a stylistic thing, but almost all code I've seen recently (outside of Widelands) uses class for anything that has methods or is vaguely C++ like. struct is only used for things that might be exchanged with C.

http://www.cplusplus.com/forum/beginner/5980/
http://stackoverflow.com/questions/54585/when-should-you-use-a-class-vs-a-struct-in-c

You could go one further and change LayeredFileSystem, ZipFileSystem and the other derived classes of FileSystem.

(There's another reason - have you ever heard of someone talking about derived structs, or substructing vs subclassing?)

review: Approve
Revision history for this message
SirVer (sirver) wrote :

lgtm.

some people do not take offense in a struct with constructor to guarantee a certain state or an operator< to make sure it can be sorted properly. As soon as the struct gets non trivial members it should be converted to a class for the reasons mark mentions.

Some devs in the team have used struct for everything to safe the public: line - i think it is easier to just default to class. So yes, more patches of this kind are very welcome.

review: Approve
Revision history for this message
Hans Joachim Desserud (hjd) wrote :

Thanks for the info. :) Fixed the of the substructs^W subclasses in the same directory now.

I also saw one of them had multiple access qualifier each assigning the same level. Based on what I could find [1] that was redundant so I removed them. One use case for this would be if it grouped methods, members, etc in separate groups, but that did not seem to be the case here since the the same access level appeared twice in a row.

[1] http://stackoverflow.com/questions/2719641/can-there-be-two-public-section-in-a-class-if-yes-then-why-and-in-which-circu

Revision history for this message
SirVer (sirver) wrote :

and thanks again :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/game_io/game_data_packet.h'
2--- src/game_io/game_data_packet.h 2012-02-15 21:25:34 +0000
3+++ src/game_io/game_data_packet.h 2013-01-11 15:01:25 +0000
4@@ -22,7 +22,7 @@
5
6 #include "wexception.h"
7
8-struct FileSystem;
9+class FileSystem;
10
11 namespace Widelands {
12
13
14=== modified file 'src/game_io/game_loader.h'
15--- src/game_io/game_loader.h 2012-02-15 21:25:34 +0000
16+++ src/game_io/game_loader.h 2013-01-11 15:01:25 +0000
17@@ -23,7 +23,7 @@
18 #include <stdint.h>
19 #include <string>
20
21-struct FileSystem;
22+class FileSystem;
23
24 namespace Widelands {
25
26
27=== modified file 'src/game_io/game_saver.h'
28--- src/game_io/game_saver.h 2012-02-15 21:25:34 +0000
29+++ src/game_io/game_saver.h 2013-01-11 15:01:25 +0000
30@@ -22,7 +22,7 @@
31
32 #include "wexception.h"
33
34-struct FileSystem;
35+class FileSystem;
36
37 namespace Widelands {
38
39
40=== modified file 'src/graphic/font_handler1.h'
41--- src/graphic/font_handler1.h 2012-12-31 11:21:15 +0000
42+++ src/graphic/font_handler1.h 2013-01-11 15:01:25 +0000
43@@ -29,7 +29,7 @@
44 #include "ui_basic/align.h"
45
46 class RenderTarget;
47-struct FileSystem;
48+class FileSystem;
49
50 class IPicture;
51 class IGraphic;
52
53=== modified file 'src/io/filesystem/disk_filesystem.h'
54--- src/io/filesystem/disk_filesystem.h 2012-02-15 21:25:34 +0000
55+++ src/io/filesystem/disk_filesystem.h 2013-01-11 15:01:25 +0000
56@@ -26,7 +26,8 @@
57 #include <cstring>
58
59 /// \todo const correctness
60-struct RealFSImpl : public FileSystem {
61+class RealFSImpl : public FileSystem {
62+public:
63 RealFSImpl(std::string const & Directory);
64
65 virtual int32_t FindFiles
66
67=== modified file 'src/io/filesystem/filesystem.h'
68--- src/io/filesystem/filesystem.h 2012-06-06 14:51:03 +0000
69+++ src/io/filesystem/filesystem.h 2013-01-11 15:01:25 +0000
70@@ -42,7 +42,8 @@
71 * operations.
72 * \todo const correctness
73 */
74-struct FileSystem {
75+class FileSystem {
76+public:
77 // TODO This should be unnecessary. Make it so.
78 enum Type {
79 DIR,
80
81=== modified file 'src/io/filesystem/layered_filesystem.h'
82--- src/io/filesystem/layered_filesystem.h 2012-02-15 21:25:34 +0000
83+++ src/io/filesystem/layered_filesystem.h 2013-01-11 15:01:25 +0000
84@@ -41,7 +41,8 @@
85 * $CWD <-- the current-working directory; this is useful for debugging, when
86 * the executable isn't in the root of the game-data directory
87 */
88-struct LayeredFileSystem : public FileSystem {
89+class LayeredFileSystem : public FileSystem {
90+public:
91 LayeredFileSystem();
92 virtual ~LayeredFileSystem();
93
94@@ -102,7 +103,8 @@
95 /// stack and make sure that it is removed when the object goes out of scope.
96 /// This is exception-safe, unlike calling g_fs->AddFileSystem and
97 /// g_fs->RemoveFileSystem directly.
98-struct FileSystemLayer {
99+class FileSystemLayer {
100+public:
101 FileSystemLayer(FileSystem & fs) : m_fs(fs) {g_fs->AddFileSystem(fs);}
102 ~FileSystemLayer() {g_fs->RemoveFileSystem(m_fs);}
103 private:
104
105=== modified file 'src/io/filesystem/zip_filesystem.h'
106--- src/io/filesystem/zip_filesystem.h 2012-05-05 18:50:50 +0000
107+++ src/io/filesystem/zip_filesystem.h 2013-01-11 15:01:25 +0000
108@@ -33,7 +33,8 @@
109 #endif
110 #endif
111
112-struct ZipFilesystem : public FileSystem {
113+class ZipFilesystem : public FileSystem {
114+public:
115 ZipFilesystem(std::string const &);
116 virtual ~ZipFilesystem();
117
118@@ -70,7 +71,6 @@
119
120 virtual unsigned long long DiskSpace();
121
122-public:
123 static FileSystem * CreateFromDirectory(std::string const & directory);
124
125 virtual std::string getBasename() {return m_zipfilename;};
126@@ -81,7 +81,6 @@
127 void m_Close();
128 std::string strip_basename(std::string);
129
130-private:
131 enum State {
132 STATE_IDLE,
133 STATE_ZIPPING,
134
135=== modified file 'src/map_io/widelands_map_data_packet.h'
136--- src/map_io/widelands_map_data_packet.h 2012-02-15 21:25:34 +0000
137+++ src/map_io/widelands_map_data_packet.h 2013-01-11 15:01:25 +0000
138@@ -23,7 +23,7 @@
139 #include "wexception.h"
140 #include "logic/widelands_filewrite.h"
141
142-struct FileSystem;
143+class FileSystem;
144
145 namespace Widelands {
146
147
148=== modified file 'src/map_io/widelands_map_loader.h'
149--- src/map_io/widelands_map_loader.h 2012-02-15 21:25:34 +0000
150+++ src/map_io/widelands_map_loader.h 2013-01-11 15:01:25 +0000
151@@ -24,7 +24,7 @@
152 #include <cstring>
153 #include "map_loader.h"
154
155-struct FileSystem;
156+class FileSystem;
157
158 namespace Widelands {
159
160
161=== modified file 'src/map_io/widelands_map_object_packet.h'
162--- src/map_io/widelands_map_object_packet.h 2012-02-15 21:25:34 +0000
163+++ src/map_io/widelands_map_object_packet.h 2013-01-11 15:01:25 +0000
164@@ -24,7 +24,7 @@
165
166 #include <set>
167
168-struct FileSystem;
169+class FileSystem;
170
171 namespace Widelands {
172
173
174=== modified file 'src/map_io/widelands_map_saver.h'
175--- src/map_io/widelands_map_saver.h 2012-02-15 21:25:34 +0000
176+++ src/map_io/widelands_map_saver.h 2013-01-11 15:01:25 +0000
177@@ -22,7 +22,7 @@
178
179 #include "wexception.h"
180
181-struct FileSystem;
182+class FileSystem;
183
184 namespace Widelands {
185
186
187=== modified file 'src/profile/profile.h'
188--- src/profile/profile.h 2012-02-15 21:25:34 +0000
189+++ src/profile/profile.h 2013-01-11 15:01:25 +0000
190@@ -39,7 +39,7 @@
191 };
192
193 extern struct Profile g_options;
194-struct FileSystem;
195+class FileSystem;
196
197 /**
198 * Represents one section inside the .ini-style file, basically as a list of

Subscribers

People subscribed via source and target branches

to status/vote changes: