Daniele Bartolini 10 years ago
parent
commit
ff8e6e418d

+ 0 - 2
src/core/os.cpp

@@ -69,8 +69,6 @@ namespace os
 	int execute_process(const char* path, const char* args, StringStream& output)
 	int execute_process(const char* path, const char* args, StringStream& output)
 	{
 	{
 #if CROWN_PLATFORM_POSIX
 #if CROWN_PLATFORM_POSIX
-		using namespace string_stream;
-
 		TempAllocator512 ta;
 		TempAllocator512 ta;
 		DynamicString cmd(path, ta);
 		DynamicString cmd(path, ta);
 		cmd += " 2>&1 ";
 		cmd += " 2>&1 ";

+ 49 - 57
src/core/strings/string_stream.h

@@ -16,20 +16,6 @@ namespace crown
 /// @ingroup String
 /// @ingroup String
 namespace string_stream
 namespace string_stream
 {
 {
-	/// Appends @a val to the stream @a s using appropriate formatting.
-	StringStream& operator<<(StringStream& s, char val);
-	StringStream& operator<<(StringStream& s, s16 val);
-	StringStream& operator<<(StringStream& s, u16 val);
-	StringStream& operator<<(StringStream& s, s32 val);
-	StringStream& operator<<(StringStream& s, u32 val);
-	StringStream& operator<<(StringStream& s, s64 val);
-	StringStream& operator<<(StringStream& s, u64 val);
-	StringStream& operator<<(StringStream& s, f32 val);
-	StringStream& operator<<(StringStream& s, f64 val);
-
-	/// Appends the string @a string to the stream @a s.
-	StringStream& operator<<(StringStream& s, const char* string);
-
 	/// Returns the stream as a NUL-terminated string.
 	/// Returns the stream as a NUL-terminated string.
 	const char* c_str(StringStream& s);
 	const char* c_str(StringStream& s);
 
 
@@ -37,60 +23,65 @@ namespace string_stream
 
 
 } // namespace string_stream
 } // namespace string_stream
 
 
-namespace string_stream
+/// @addtogroup String
+/// @{
+/// Appends @a val to the stream @a s using appropriate formatting.
+inline StringStream& operator<<(StringStream& s, char val)
 {
 {
-	inline StringStream& operator<<(StringStream& s, char val)
-	{
-		array::push_back(s, val);
-		return s;
-	}
+	array::push_back(s, val);
+	return s;
+}
 
 
-	inline StringStream& operator<<(StringStream& s, s16 val)
-	{
-		return stream_printf(s, "%hd", val);
-	}
+inline StringStream& operator<<(StringStream& s, s16 val)
+{
+	return string_stream::stream_printf(s, "%hd", val);
+}
 
 
-	inline StringStream& operator<<(StringStream& s, u16 val)
-	{
-		return stream_printf(s, "%hu", val);
-	}
+inline StringStream& operator<<(StringStream& s, u16 val)
+{
+	return string_stream::stream_printf(s, "%hu", val);
+}
 
 
-	inline StringStream& operator<<(StringStream& s, s32 val)
-	{
-		return stream_printf(s, "%d", val);
-	}
+inline StringStream& operator<<(StringStream& s, s32 val)
+{
+	return string_stream::stream_printf(s, "%d", val);
+}
 
 
-	inline StringStream& operator<<(StringStream& s, u32 val)
-	{
-		return stream_printf(s, "%u", val);
-	}
+inline StringStream& operator<<(StringStream& s, u32 val)
+{
+	return string_stream::stream_printf(s, "%u", val);
+}
 
 
-	inline StringStream& operator<<(StringStream& s, s64 val)
-	{
-		return stream_printf(s, "%lld", val);
-	}
+inline StringStream& operator<<(StringStream& s, s64 val)
+{
+	return string_stream::stream_printf(s, "%lld", val);
+}
 
 
-	inline StringStream& operator<<(StringStream& s, u64 val)
-	{
-		return stream_printf(s, "%llu", val);
-	}
+inline StringStream& operator<<(StringStream& s, u64 val)
+{
+	return string_stream::stream_printf(s, "%llu", val);
+}
 
 
-	inline StringStream& operator<<(StringStream& s, f32 val)
-	{
-		return stream_printf(s, "%g", val);
-	}
+inline StringStream& operator<<(StringStream& s, f32 val)
+{
+	return string_stream::stream_printf(s, "%g", val);
+}
 
 
-	inline StringStream& operator<<(StringStream& s, f64 val)
-	{
-		return stream_printf(s, "%g", val);
-	}
+inline StringStream& operator<<(StringStream& s, f64 val)
+{
+	return string_stream::stream_printf(s, "%g", val);
+}
 
 
-	inline StringStream& operator<<(StringStream& s, const char* str)
-	{
-		array::push(s, str, strlen32(str));
-		return s;
-	}
+/// Appends the string @a str to the stream @a s.
+inline StringStream& operator<<(StringStream& s, const char* str)
+{
+	array::push(s, str, strlen32(str));
+	return s;
+}
+/// @}
 
 
+namespace string_stream
+{
 	inline const char* c_str(StringStream& s)
 	inline const char* c_str(StringStream& s)
 	{
 	{
 		array::push_back(s, '\0');
 		array::push_back(s, '\0');
@@ -106,4 +97,5 @@ namespace string_stream
 		return s << buf;
 		return s << buf;
 	}
 	}
 } // namespace string_stream
 } // namespace string_stream
+
 } // namespace crown
 } // namespace crown

+ 2 - 4
src/device/console_server.cpp

@@ -57,20 +57,18 @@ void ConsoleServer::send(TCPSocket client, const char* json)
 
 
 void ConsoleServer::error(TCPSocket client, const char* msg)
 void ConsoleServer::error(TCPSocket client, const char* msg)
 {
 {
-	using namespace string_stream;
 	TempAllocator4096 ta;
 	TempAllocator4096 ta;
 	StringStream ss(ta);
 	StringStream ss(ta);
 	ss << "{\"type\":\"error\",\"message\":\"" << msg << "\"}";
 	ss << "{\"type\":\"error\",\"message\":\"" << msg << "\"}";
-	send(client, c_str(ss));
+	send(client, string_stream::c_str(ss));
 }
 }
 
 
 void ConsoleServer::success(TCPSocket client, const char* msg)
 void ConsoleServer::success(TCPSocket client, const char* msg)
 {
 {
-	using namespace string_stream;
 	TempAllocator4096 ta;
 	TempAllocator4096 ta;
 	StringStream ss(ta);
 	StringStream ss(ta);
 	ss << "{\"type\":\"success\",\"message\":\"" << msg << "\"}";
 	ss << "{\"type\":\"success\",\"message\":\"" << msg << "\"}";
-	send(client, c_str(ss));
+	send(client, string_stream::c_str(ss));
 }
 }
 
 
 void ConsoleServer::send(const char* json)
 void ConsoleServer::send(const char* json)

+ 1 - 2
src/device/device.cpp

@@ -631,7 +631,6 @@ void Device::log(const char* msg, LogSeverity::Enum severity)
 		static const char* stt[] = { "info", "warning", "error", "debug" };
 		static const char* stt[] = { "info", "warning", "error", "debug" };
 		CE_STATIC_ASSERT(CE_COUNTOF(stt) == LogSeverity::COUNT);
 		CE_STATIC_ASSERT(CE_COUNTOF(stt) == LogSeverity::COUNT);
 
 
-		using namespace string_stream;
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		StringStream json(ta);
 		StringStream json(ta);
 
 
@@ -639,7 +638,7 @@ void Device::log(const char* msg, LogSeverity::Enum severity)
 		json << "\"severity\":\"" << stt[severity] << "\",";
 		json << "\"severity\":\"" << stt[severity] << "\",";
 		json << "\"message\":\""; sanitize(json, msg) << "\"}";
 		json << "\"message\":\""; sanitize(json, msg) << "\"}";
 
 
-		_console_server->send(c_str(json));
+		_console_server->send(string_stream::c_str(json));
 	}
 	}
 }
 }
 
 

+ 1 - 2
src/lua/lua_api.cpp

@@ -2512,7 +2512,6 @@ static int device_destroy_resource_package(lua_State* L)
 
 
 static int device_console_send(lua_State* L)
 static int device_console_send(lua_State* L)
 {
 {
-	using namespace string_stream;
 	LuaStack stack(L);
 	LuaStack stack(L);
 
 
 	TempAllocator1024 alloc;
 	TempAllocator1024 alloc;
@@ -2609,7 +2608,7 @@ static int device_console_send(lua_State* L)
 	stack.pop(1);
 	stack.pop(1);
 	json << "}";
 	json << "}";
 
 
-	device()->console_server()->send(c_str(json));
+	device()->console_server()->send(string_stream::c_str(json));
 	return 0;
 	return 0;
 }
 }
 
 

+ 2 - 4
src/resource/lua_resource.cpp

@@ -34,8 +34,6 @@ namespace lua_resource
 {
 {
 	void compile(const char* path, CompileOptions& opts)
 	void compile(const char* path, CompileOptions& opts)
 	{
 	{
-		using namespace string_stream;
-
 		TempAllocator1024 ta;
 		TempAllocator1024 ta;
 		DynamicString luasrc(ta);
 		DynamicString luasrc(ta);
 		DynamicString luabin(ta);
 		DynamicString luabin(ta);
@@ -48,11 +46,11 @@ namespace lua_resource
 		args << " " << luabin.c_str();
 		args << " " << luabin.c_str();
 
 
 		StringStream output(ta);
 		StringStream output(ta);
-		int exitcode = os::execute_process(LUAJIT_EXE, c_str(args), output);
+		int exitcode = os::execute_process(LUAJIT_EXE, string_stream::c_str(args), output);
 		RESOURCE_COMPILER_ASSERT(exitcode == 0
 		RESOURCE_COMPILER_ASSERT(exitcode == 0
 			, opts
 			, opts
 			, "Failed to compile lua:\n%s"
 			, "Failed to compile lua:\n%s"
-			, c_str(output)
+			, string_stream::c_str(output)
 			);
 			);
 
 
 		Buffer blob = opts.read_temporary(luabin.c_str());
 		Buffer blob = opts.read_temporary(luabin.c_str());

+ 3 - 7
src/resource/shader_resource.cpp

@@ -431,8 +431,6 @@ namespace shader_resource
 
 
 	static int run_external_compiler(const char* infile, const char* outfile, const char* varying, const char* type, const char* platform, StringStream& output)
 	static int run_external_compiler(const char* infile, const char* outfile, const char* varying, const char* type, const char* platform, StringStream& output)
 	{
 	{
-		using namespace string_stream;
-
 		TempAllocator512 ta;
 		TempAllocator512 ta;
 		StringStream args(ta);
 		StringStream args(ta);
 		args << " -f " << infile;
 		args << " -f " << infile;
@@ -450,7 +448,7 @@ namespace shader_resource
 			args << ((strcmp(type, "vertex") == 0) ? "vs_3_0" : "ps_3_0");
 			args << ((strcmp(type, "vertex") == 0) ? "vs_3_0" : "ps_3_0");
 		}
 		}
 
 
-		return os::execute_process(SHADERC_PATH, c_str(args), output);
+		return os::execute_process(SHADERC_PATH, string_stream::c_str(args), output);
 	}
 	}
 
 
 	struct RenderState
 	struct RenderState
@@ -1148,8 +1146,6 @@ namespace shader_resource
 				included_code = included._code;
 				included_code = included._code;
 			}
 			}
 
 
-			using namespace string_stream;
-
 			StringStream vs_code(default_allocator());
 			StringStream vs_code(default_allocator());
 			StringStream fs_code(default_allocator());
 			StringStream fs_code(default_allocator());
 			vs_code << shader._vs_input_output.c_str();
 			vs_code << shader._vs_input_output.c_str();
@@ -1189,7 +1185,7 @@ namespace shader_resource
 				RESOURCE_COMPILER_ASSERT(false
 				RESOURCE_COMPILER_ASSERT(false
 					, _opts
 					, _opts
 					, "Failed to compile vertex shader:\n%s"
 					, "Failed to compile vertex shader:\n%s"
-					, c_str(output)
+					, string_stream::c_str(output)
 					);
 					);
 			}
 			}
 
 
@@ -1207,7 +1203,7 @@ namespace shader_resource
 				RESOURCE_COMPILER_ASSERT(false
 				RESOURCE_COMPILER_ASSERT(false
 					, _opts
 					, _opts
 					, "Failed to compile fragment shader:\n%s"
 					, "Failed to compile fragment shader:\n%s"
-					, c_str(output)
+					, string_stream::c_str(output)
 					);
 					);
 			}
 			}
 
 

+ 2 - 3
src/resource/texture_resource.cpp

@@ -55,7 +55,6 @@ namespace texture_resource
 		opts.get_absolute_path(name.c_str(), texsrc);
 		opts.get_absolute_path(name.c_str(), texsrc);
 		opts.get_absolute_path("texture.ktx", texout);
 		opts.get_absolute_path("texture.ktx", texout);
 
 
-		using namespace string_stream;
 		StringStream args(ta);
 		StringStream args(ta);
 		args << " -f " << texsrc.c_str();
 		args << " -f " << texsrc.c_str();
 		args << " -o " << texout.c_str();
 		args << " -o " << texout.c_str();
@@ -63,11 +62,11 @@ namespace texture_resource
 		args << (is_normalmap  ? " -n " : "");
 		args << (is_normalmap  ? " -n " : "");
 
 
 		StringStream output(ta);
 		StringStream output(ta);
-		int exitcode = os::execute_process(TEXTUREC_PATH, c_str(args), output);
+		int exitcode = os::execute_process(TEXTUREC_PATH, string_stream::c_str(args), output);
 		RESOURCE_COMPILER_ASSERT(exitcode == 0
 		RESOURCE_COMPILER_ASSERT(exitcode == 0
 			, opts
 			, opts
 			, "Failed to compile texture:\n%s"
 			, "Failed to compile texture:\n%s"
-			, c_str(output)
+			, string_stream::c_str(output)
 			);
 			);
 
 
 		Buffer blob = opts.read_temporary(texout.c_str());
 		Buffer blob = opts.read_temporary(texout.c_str());