Selaa lähdekoodia

src: always use explicit ctors

Daniele Bartolini 3 vuotta sitten
vanhempi
sitoutus
cab33341f3

+ 5 - 5
src/core/containers/types.h

@@ -31,7 +31,7 @@ struct Array
 	u32 _size;
 	T *_data;
 
-	Array(Allocator &a);
+	explicit Array(Allocator &a);
 	Array(const Array<T> &other);
 	~Array();
 	T &operator[](u32 index);
@@ -58,7 +58,7 @@ struct Vector
 	u32 _size;
 	T *_data;
 
-	Vector(Allocator &a);
+	explicit Vector(Allocator &a);
 	Vector(const Vector<T> &other);
 	~Vector();
 	T &operator[](u32 index);
@@ -78,7 +78,7 @@ struct Queue
 	u32 _size;
 	Array<T> _queue;
 
-	Queue(Allocator &a);
+	explicit Queue(Allocator &a);
 	T &operator[](u32 index);
 	const T &operator[](u32 index) const;
 };
@@ -107,7 +107,7 @@ struct HashMap
 	Entry *_data;
 	char *_buffer;
 
-	HashMap(Allocator &a);
+	explicit HashMap(Allocator &a);
 	HashMap(const HashMap &other);
 	~HashMap();
 	HashMap<TKey, TValue, Hash, KeyEqual> &operator=(const HashMap<TKey, TValue, Hash, KeyEqual> &other);
@@ -135,7 +135,7 @@ struct HashSet
 	TKey *_data;
 	char *_buffer;
 
-	HashSet(Allocator &a);
+	explicit HashSet(Allocator &a);
 	HashSet(const HashSet &other);
 	~HashSet();
 	HashSet<TKey, Hash, KeyEqual> &operator=(const HashSet<TKey, Hash, KeyEqual> &other);

+ 1 - 1
src/core/filesystem/file_monitor.h

@@ -38,7 +38,7 @@ struct FileMonitor
 	FileMonitorImpl *_impl;
 
 	///
-	FileMonitor(Allocator &a);
+	explicit FileMonitor(Allocator &a);
 
 	///
 	~FileMonitor();

+ 2 - 1
src/core/filesystem/filesystem_disk.h

@@ -23,7 +23,8 @@ struct FilesystemDisk : public Filesystem
 	Allocator *_allocator;
 	DynamicString _prefix;
 
-	FilesystemDisk(Allocator &a);
+	///
+	explicit FilesystemDisk(Allocator &a);
 
 	/// Sets the root path to the given @a prefix.
 	/// @note

+ 2 - 2
src/core/filesystem/reader_writer.h

@@ -18,7 +18,7 @@ struct BinaryWriter
 	File &_file;
 
 	///
-	BinaryWriter(File &file);
+	explicit BinaryWriter(File &file);
 
 	///
 	void align(const u32 align);
@@ -46,7 +46,7 @@ struct BinaryReader
 	File &_file;
 
 	///
-	BinaryReader(File &file);
+	explicit BinaryReader(File &file);
 
 	///
 	void align(const u32 align);

+ 1 - 1
src/core/json/types.h

@@ -40,7 +40,7 @@ struct JsonObject
 {
 	HashMap<StringView, const char *> _map;
 
-	JsonObject(Allocator &a);
+	explicit JsonObject(Allocator &a);
 
 	const char *operator[](const char *key) const;
 	const char *operator[](const StringView &key) const;

+ 1 - 1
src/core/math/random.h

@@ -17,7 +17,7 @@ struct Random
 	s32 _seed;
 
 	/// Initializes the generator with the given @a seed.
-	Random(s32 seed);
+	explicit Random(s32 seed);
 
 	/// Returns a pseudo-random integer in the range [0, 32767].
 	s32 integer();

+ 3 - 1
src/core/memory/temp_allocator.inl

@@ -35,7 +35,9 @@ struct TempAllocator : public Allocator
 	unsigned _chunk_size;      ///< Chunks to allocate from backing allocator.
 
 	/// Creates a new temporary allocator using the specified backing allocator.
-	TempAllocator(Allocator &backing = default_scratch_allocator());
+	explicit TempAllocator(Allocator &backing = default_scratch_allocator());
+
+	///
 	virtual ~TempAllocator();
 
 	virtual void *allocate(u32 size, u32 align = DEFAULT_ALIGN);

+ 4 - 4
src/core/pair.h

@@ -26,7 +26,7 @@ struct Pair<T1, T2, 0, 0>
 	Pair(T1 &f, T2 &s);
 
 	///
-	Pair(Allocator & /*a*/);
+	explicit Pair(Allocator & /*a*/);
 };
 
 template<typename T1, typename T2>
@@ -41,7 +41,7 @@ struct Pair<T1, T2, 1, 0>
 	Pair(T1 &f, T2 &s);
 
 	///
-	Pair(Allocator &a);
+	explicit Pair(Allocator &a);
 };
 
 template<typename T1, typename T2>
@@ -56,7 +56,7 @@ struct Pair<T1, T2, 0, 1>
 	Pair(T1 &f, T2 &s);
 
 	///
-	Pair(Allocator &a);
+	explicit Pair(Allocator &a);
 };
 
 template<typename T1, typename T2>
@@ -71,7 +71,7 @@ struct Pair<T1, T2, 1, 1>
 	Pair(T1 &f, T2 &s);
 
 	///
-	Pair(Allocator &a);
+	explicit Pair(Allocator &a);
 };
 
 #define PAIR(first, second) Pair<first, second, IS_ALLOCATOR_AWARE(first), IS_ALLOCATOR_AWARE(second)>

+ 1 - 1
src/core/strings/dynamic_string.h

@@ -22,7 +22,7 @@ struct DynamicString
 	Array<char> _data;
 
 	///
-	DynamicString(Allocator &a);
+	explicit DynamicString(Allocator &a);
 
 	///
 	~DynamicString();

+ 4 - 4
src/core/strings/string_id.h

@@ -24,13 +24,13 @@ struct StringId32
 	{
 	}
 
-	StringId32(u32 idx)
+	explicit StringId32(u32 idx)
 		: _id(idx)
 	{
 	}
 
 	explicit StringId32(const char *str);
-	explicit StringId32(const char *str, u32 len);
+	StringId32(const char *str, u32 len);
 
 	void hash(const char *str, u32 len);
 
@@ -55,13 +55,13 @@ struct StringId64
 	{
 	}
 
-	StringId64(u64 idx)
+	explicit StringId64(u64 idx)
 		: _id(idx)
 	{
 	}
 
 	explicit StringId64(const char *str);
-	explicit StringId64(const char *str, u32 len);
+	StringId64(const char *str, u32 len);
 
 	void hash(const char *str, u32 len);
 

+ 1 - 1
src/core/strings/string_view.h

@@ -21,7 +21,7 @@ struct StringView
 	StringView();
 
 	///
-	StringView(const char *str);
+	explicit StringView(const char *str);
 
 	///
 	StringView(const char *str, u32 len);

+ 1 - 1
src/core/thread/scoped_mutex.inl

@@ -17,7 +17,7 @@ struct ScopedMutex
 	Mutex &_mutex;
 
 	/// Locks the mutex @a m.
-	ScopedMutex(Mutex &m)
+	explicit ScopedMutex(Mutex &m)
 		: _mutex(m)
 	{
 		_mutex.lock();

+ 2 - 2
src/core/types.h

@@ -70,8 +70,8 @@ inline bool constexpr is_power_of_2(u32 x)
 u32 STRING_ID_32(const char *str, const u32 id);
 u64 STRING_ID_64(const char *str, const u64 id);
 #else
-	#define STRING_ID_32(str, id) u32(id)
-	#define STRING_ID_64(str, id) u64(id)
+	#define STRING_ID_32(str, id) StringId32(id)
+	#define STRING_ID_64(str, id) StringId64(id)
 #endif
 
 } // namespace crown

+ 4 - 1
src/device/boot_config.h

@@ -25,7 +25,10 @@ struct BootConfig
 	bool vsync;
 	bool fullscreen;
 
-	BootConfig(Allocator &a);
+	///
+	explicit BootConfig(Allocator &a);
+
+	///
 	bool parse(const char *json);
 };
 

+ 1 - 1
src/device/console_server.h

@@ -75,7 +75,7 @@ struct ConsoleServer
 	Semaphore _client_connected;
 
 	///
-	ConsoleServer(Allocator &a);
+	explicit ConsoleServer(Allocator &a);
 
 	/// Listens on the given @a port. If @a wait is true, this function
 	/// blocks until a client is connected.

+ 1 - 1
src/device/input_manager.h

@@ -28,7 +28,7 @@ struct InputManager
 	bool _has_delta_axis_event;
 
 	/// Constructor.
-	InputManager(Allocator &a);
+	explicit InputManager(Allocator &a);
 
 	/// Destructor.
 	~InputManager();

+ 1 - 1
src/lua/lua_stack.h

@@ -43,7 +43,7 @@ struct LuaStack
 	lua_State *L;
 
 	///
-	LuaStack(lua_State *L);
+	explicit LuaStack(lua_State *L);
 
 	/// Returns the number of elements in the stack.
 	/// When called inside a function, it can be used to count

+ 1 - 1
src/resource/mesh_resource.h

@@ -45,7 +45,7 @@ struct MeshResource
 	Array<MeshGeometry *> geometries;
 
 	///
-	MeshResource(Allocator &a);
+	explicit MeshResource(Allocator &a);
 
 	///
 	const MeshGeometry *geometry(StringId32 name) const;

+ 1 - 1
src/resource/package_resource.h

@@ -32,7 +32,7 @@ struct PackageResource
 	Array<Resource> resources;
 
 	///
-	PackageResource(Allocator &a);
+	explicit PackageResource(Allocator &a);
 };
 
 namespace package_resource_internal

+ 1 - 1
src/resource/resource_loader.h

@@ -51,7 +51,7 @@ struct ResourceLoader
 	s32 run();
 
 	/// Read resources from @a data_filesystem.
-	ResourceLoader(Filesystem &data_filesystem);
+	explicit ResourceLoader(Filesystem &data_filesystem);
 
 	///
 	~ResourceLoader();

+ 1 - 1
src/resource/resource_manager.h

@@ -64,7 +64,7 @@ struct ResourceManager
 	void complete_request(StringId64 type, StringId64 name, void *data);
 
 	/// Uses @a rl to load resources.
-	ResourceManager(ResourceLoader &rl);
+	explicit ResourceManager(ResourceLoader &rl);
 
 	///
 	~ResourceManager();

+ 1 - 1
src/resource/shader_resource.h

@@ -18,7 +18,7 @@ namespace crown
 {
 struct ShaderResource
 {
-	ShaderResource(Allocator &a)
+	explicit ShaderResource(Allocator &a)
 		: _data(a)
 	{
 	}

+ 1 - 1
src/world/gui.h

@@ -26,7 +26,7 @@ struct GuiBuffer
 	bgfx::TransientIndexBuffer tib;
 
 	///
-	GuiBuffer(ShaderManager &sm);
+	explicit GuiBuffer(ShaderManager &sm);
 
 	///
 	void *vertex_buffer_end();

+ 1 - 1
src/world/render_world.h

@@ -337,7 +337,7 @@ struct RenderWorld
 		LightInstanceData _data;
 
 		///
-		LightManager(Allocator &a)
+		explicit LightManager(Allocator &a)
 			: _allocator(&a)
 			, _map(a)
 		{

+ 1 - 1
src/world/shader_manager.h

@@ -31,7 +31,7 @@ struct ShaderManager
 	ShaderMap _shader_map;
 
 	///
-	ShaderManager(Allocator &a);
+	explicit ShaderManager(Allocator &a);
 
 	///
 	void *load(File &file, Allocator &a);

+ 1 - 1
src/world/sound_world.h

@@ -25,7 +25,7 @@ struct SoundWorld
 	SoundWorldImpl *_impl;
 
 	///
-	SoundWorld(Allocator &a);
+	explicit SoundWorld(Allocator &a);
 
 	///
 	~SoundWorld();

+ 1 - 1
src/world/unit_manager.h

@@ -22,7 +22,7 @@ struct UnitManager
 	UnitDestroyCallback _callbacks;
 
 	///
-	UnitManager(Allocator &a);
+	explicit UnitManager(Allocator &a);
 
 	///
 	UnitId make_unit(u32 idx, u8 gen);