Skip to content

Commit 630da6f

Browse files
committed
Style: Integrate new #pragma once syntax
1 parent 0b174c6 commit 630da6f

10 files changed

+23
-78
lines changed

contributing/development/code_style_guidelines.rst

+1-6
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,14 @@ Example:
203203
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
204204
/**************************************************************************/
205205
206-
#ifndef MY_NEW_FILE_H
207-
#define MY_NEW_FILE_H
206+
#pragma once
208207
209208
#include "core/hash_map.h"
210209
#include "core/list.h"
211210
#include "scene/gui/control.h"
212211
213212
#include <png.h>
214213
215-
...
216-
217-
#endif // MY_NEW_FILE_H
218-
219214
.. code-block:: cpp
220215
:caption: my_new_file.cpp
221216

contributing/development/core_and_modules/binding_to_external_libraries.rst

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ Next, you will create a header file with a TTS class:
2222
.. code-block:: cpp
2323
:caption: godot/modules/tts/tts.h
2424
25-
#ifndef GODOT_TTS_H
26-
#define GODOT_TTS_H
25+
#pragma once
2726
2827
#include "core/object/ref_counted.h"
2928
@@ -39,8 +38,6 @@ Next, you will create a header file with a TTS class:
3938
TTS();
4039
};
4140
42-
#endif // GODOT_TTS_H
43-
4441
And then you'll add the cpp file.
4542

4643
.. code-block:: cpp

contributing/development/core_and_modules/custom_godot_servers.rst

+1-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ an initialization state and a cleanup procedure.
4141
.. code-block:: cpp
4242
:caption: hilbert_hotel.h
4343
44-
#ifndef HILBERT_HOTEL_H
45-
#define HILBERT_HOTEL_H
44+
#pragma once
4645
4746
#include "core/object/object.h"
4847
#include "core/os/thread.h"
@@ -91,8 +90,6 @@ an initialization state and a cleanup procedure.
9190
HilbertHotel();
9291
};
9392
94-
#endif
95-
9693
.. code-block:: cpp
9794
:caption: hilbert_hotel.cpp
9895

contributing/development/core_and_modules/custom_modules_in_cpp.rst

+2-8
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ Inside we will create a summator class:
4747
.. code-block:: cpp
4848
:caption: godot/modules/summator/summator.h
4949
50-
#ifndef SUMMATOR_H
51-
#define SUMMATOR_H
50+
#pragma once
5251
5352
#include "core/object/ref_counted.h"
5453
@@ -68,8 +67,6 @@ Inside we will create a summator class:
6867
Summator();
6968
};
7069
71-
#endif // SUMMATOR_H
72-
7370
And then the cpp file.
7471

7572
.. code-block:: cpp
@@ -621,8 +618,7 @@ The procedure is the following:
621618
.. code-block:: cpp
622619
:caption: godot/modules/summator/tests/test_summator.h
623620
624-
#ifndef TEST_SUMMATOR_H
625-
#define TEST_SUMMATOR_H
621+
#pragma once
626622
627623
#include "tests/test_macros.h"
628624
@@ -649,8 +645,6 @@ The procedure is the following:
649645
650646
} // namespace TestSummator
651647
652-
#endif // TEST_SUMMATOR_H
653-
654648
4. Compile the engine with ``scons tests=yes``, and run the tests with the
655649
following command:
656650

contributing/development/core_and_modules/custom_resource_format_loaders.rst

+3-9
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ read and handle data serialization.
5858
.. code-block:: cpp
5959
:caption: resource_loader_json.h
6060
61-
#ifndef RESOURCE_LOADER_JSON_H
62-
#define RESOURCE_LOADER_JSON_H
61+
#pragma once
6362
6463
#include "core/io/resource_loader.h"
6564
@@ -71,7 +70,6 @@ read and handle data serialization.
7170
virtual bool handles_type(const String &p_type) const;
7271
virtual String get_resource_type(const String &p_path) const;
7372
};
74-
#endif // RESOURCE_LOADER_JSON_H
7573
7674
.. code-block:: cpp
7775
:caption: resource_loader_json.cpp
@@ -112,8 +110,7 @@ If you'd like to be able to edit and save a resource, you can implement a
112110
.. code-block:: cpp
113111
:caption: resource_saver_json.h
114112
115-
#ifndef RESOURCE_SAVER_JSON_H
116-
#define RESOURCE_SAVER_JSON_H
113+
#pragma once
117114
118115
#include "core/io/resource_saver.h"
119116
@@ -124,7 +121,6 @@ If you'd like to be able to edit and save a resource, you can implement a
124121
virtual bool recognize(const RES &p_resource) const;
125122
virtual void get_recognized_extensions(const RES &p_resource, List<String> *r_extensions) const;
126123
};
127-
#endif // RESOURCE_SAVER_JSON_H
128124
129125
.. code-block:: cpp
130126
:caption: resource_saver_json.cpp
@@ -162,8 +158,7 @@ Here is an example of creating a custom datatype:
162158
.. code-block:: cpp
163159
:caption: resource_json.h
164160
165-
#ifndef RESOURCE_JSON_H
166-
#define RESOURCE_JSON_H
161+
#pragma once
167162
168163
#include "core/io/json.h"
169164
#include "core/variant_parser.h"
@@ -189,7 +184,6 @@ Here is an example of creating a custom datatype:
189184
void set_dict(const Dictionary &p_dict);
190185
Dictionary get_dict();
191186
};
192-
#endif // RESOURCE_JSON_H
193187
194188
.. code-block:: cpp
195189
:caption: resource_json.cpp

contributing/development/core_and_modules/unit_testing.rst

+1-4
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ Here's a minimal working test suite with a single test case written:
113113

114114
.. code-block:: cpp
115115
116-
#ifndef TEST_STRING_H
117-
#define TEST_STRING_H
116+
#pragma once
118117
119118
#include "tests/test_macros.h"
120119
@@ -127,8 +126,6 @@ Here's a minimal working test suite with a single test case written:
127126
128127
} // namespace TestString
129128
130-
#endif // TEST_STRING_H
131-
132129
.. note::
133130
You can quickly generate new tests using the ``create_test.py`` script found in the ``tests/`` directory.
134131
This script automatically creates a new test file with the required boilerplate code in the appropriate location.

contributing/development/cpp_usage_guidelines.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ Lambdas should be used conservatively when they make code effectively faster or
9494
simpler, and do not impede readability. Please ask before using lambdas in a
9595
pull request.
9696

97-
``#pragma once`` directive
97+
``#ifdef``-based include guards
9898
~~~~~~~~~~~~~~~~~~~~~~~~~~
9999

100-
To follow the existing style, please use standard ``#ifdef``-based include
101-
guards instead of ``#pragma once`` in new files.
100+
Starting with 4.5, all files now use the ``#pragma once`` directive, as they
101+
improve readability and declutter macros. Use of ``#ifdef``-based include
102+
guards are now actively discouraged.
102103

103104
``try``-``catch`` blocks
104105
~~~~~~~~~~~~~~~~~~~~~~~~

tutorials/performance/using_multiple_threads.rst

+3-12
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ To create a thread, use the following code:
4949

5050
.. code-tab:: cpp C++ .H File
5151

52-
#ifndef MULTITHREADING_DEMO_H
53-
#define MULTITHREADING_DEMO_H
52+
#pragma once
5453

5554
#include <godot_cpp/classes/node.hpp>
5655
#include <godot_cpp/classes/thread.hpp>
@@ -74,8 +73,6 @@ To create a thread, use the following code:
7473
};
7574
} // namespace godot
7675

77-
#endif // MULTITHREADING_DEMO_H
78-
7976
.. code-tab:: cpp C++ .CPP File
8077

8178
#include "multithreading_demo.h"
@@ -209,8 +206,7 @@ Here is an example of using a Mutex:
209206

210207
.. code-tab:: cpp C++ .H File
211208

212-
#ifndef MUTEX_DEMO_H
213-
#define MUTEX_DEMO_H
209+
#pragma once
214210

215211
#include <godot_cpp/classes/mutex.hpp>
216212
#include <godot_cpp/classes/node.hpp>
@@ -237,8 +233,6 @@ Here is an example of using a Mutex:
237233
};
238234
} // namespace godot
239235

240-
#endif // MUTEX_DEMO_H
241-
242236
.. code-tab:: cpp C++ .CPP File
243237

244238
#include "mutex_demo.h"
@@ -379,8 +373,7 @@ ready to be processed:
379373

380374
.. code-tab:: cpp C++ .H File
381375

382-
#ifndef SEMAPHORE_DEMO_H
383-
#define SEMAPHORE_DEMO_H
376+
#pragma once
384377

385378
#include <godot_cpp/classes/mutex.hpp>
386379
#include <godot_cpp/classes/node.hpp>
@@ -412,8 +405,6 @@ ready to be processed:
412405
};
413406
} // namespace godot
414407

415-
#endif // SEMAPHORE_DEMO_H
416-
417408
.. code-tab:: cpp C++ .CPP File
418409

419410
#include "semaphore_demo.h"

tutorials/scripting/gdextension/gdextension_c_example.rst

+4-18
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ Create the file ``init.h`` in the ``src`` folder, with the following contents:
133133

134134
.. code-block:: c
135135
136-
#ifndef INIT_H
137-
#define INIT_H
136+
#pragma once
138137
139138
#include "defs.h"
140139
@@ -144,8 +143,6 @@ Create the file ``init.h`` in the ``src`` folder, with the following contents:
144143
void deinitialize_gdexample_module(void *p_userdata, GDExtensionInitializationLevel p_level);
145144
GDExtensionBool GDE_EXPORT gdexample_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization);
146145
147-
#endif // INIT_H
148-
149146
The functions declared here have the signatures expected by the GDExtension API.
150147

151148
Note the inclusion of the ``defs.h`` file. This is one of our helpers to
@@ -158,8 +155,7 @@ Create the ``defs.h`` file in the ``src`` folder with the following contents:
158155

159156
.. code-block:: c
160157
161-
#ifndef DEFS_H
162-
#define DEFS_H
158+
#pragma once
163159
164160
#include <stdbool.h>
165161
#include <stddef.h>
@@ -175,8 +171,6 @@ Create the ``defs.h`` file in the ``src`` folder with the following contents:
175171
#endif
176172
#endif // ! GDE_EXPORT
177173
178-
#endif // DEFS_H
179-
180174
We also include some standard headers to make things easier. Now we only have to
181175
include ``defs.h`` and those will come as a bonus.
182176

@@ -224,8 +218,7 @@ contents:
224218

225219
.. code-block:: c
226220
227-
#ifndef GDEXAMPLE_H
228-
#define GDEXAMPLE_H
221+
#pragma once
229222
230223
#include "gdextension_interface.h"
231224
@@ -247,8 +240,6 @@ contents:
247240
// Bindings.
248241
void gdexample_class_bind_methods();
249242
250-
#endif // GDEXAMPLE_H
251-
252243
Noteworthy here is the ``object`` field, which holds a pointer to
253244
the Godot object, and the ``gdexample_class_bind_methods()`` function, which will
254245
register the metadata of our custom class (properties, methods, and signals).
@@ -299,8 +290,7 @@ We'll start by creating an ``api.h`` file in the ``src`` folder:
299290

300291
.. code-block:: c
301292
302-
#ifndef API_H
303-
#define API_H
293+
#pragma once
304294
305295
/*
306296
This file works as a collection of helpers to call the GDExtension API
@@ -333,10 +323,6 @@ We'll start by creating an ``api.h`` file in the ``src`` folder:
333323
334324
void load_api(GDExtensionInterfaceGetProcAddress p_get_proc_address);
335325
336-
337-
338-
#endif // API_H
339-
340326
This file will include many other helpers as we fill our extension with
341327
something useful. For now it only has a pointer to a function that creates a
342328
StringName from a C string (in Latin-1 encoding) and another to destruct a

tutorials/scripting/gdextension/gdextension_cpp_example.rst

+3-10
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ GDExtension node we'll be creating. We will name it ``gdexample.h``:
164164
.. code-block:: cpp
165165
:caption: gdextension_cpp_example/src/gdexample.h
166166
167-
#ifndef GDEXAMPLE_H
168-
#define GDEXAMPLE_H
167+
#pragma once
169168
170169
#include <godot_cpp/classes/sprite2d.hpp>
171170
@@ -187,9 +186,7 @@ GDExtension node we'll be creating. We will name it ``gdexample.h``:
187186
void _process(double delta) override;
188187
};
189188
190-
}
191-
192-
#endif
189+
} // namespace godot
193190
194191
There are a few things of note to the above. We include ``sprite2d.hpp`` which
195192
contains bindings to the Sprite2D class. We'll be extending this class in our
@@ -313,8 +310,7 @@ At last, we need the header file for the ``register_types.cpp`` named
313310
.. code-block:: cpp
314311
:caption: gdextension_cpp_example/src/register_types.h
315312
316-
#ifndef GDEXAMPLE_REGISTER_TYPES_H
317-
#define GDEXAMPLE_REGISTER_TYPES_H
313+
#pragma once
318314
319315
#include <godot_cpp/core/class_db.hpp>
320316
@@ -323,9 +319,6 @@ At last, we need the header file for the ``register_types.cpp`` named
323319
void initialize_example_module(ModuleInitializationLevel p_level);
324320
void uninitialize_example_module(ModuleInitializationLevel p_level);
325321
326-
#endif // GDEXAMPLE_REGISTER_TYPES_H
327-
328-
329322
Compiling the plugin
330323
--------------------
331324

0 commit comments

Comments
 (0)