[Bf-blender-cvs] [c7bffc8fa27] master: obj: move parsing utilities out of io_common, since they are fairly obj specific

Aras Pranckevicius noreply at git.blender.org
Fri May 6 13:55:13 CEST 2022


Commit: c7bffc8fa27b4ae2c92e018dc5f8f79e0dfff9b9
Author: Aras Pranckevicius
Date:   Fri May 6 14:53:56 2022 +0300
Branches: master
https://developer.blender.org/rBc7bffc8fa27b4ae2c92e018dc5f8f79e0dfff9b9

obj: move parsing utilities out of io_common, since they are fairly obj specific

As pointed out in https://developer.blender.org/rB213cd39b6db387bd88f12589fd50ff0e6563cf56#341113,
the utilities are quite OBJ specific due to treating backslash as a line
continuation character. It's unlikely that other formats need that.

No functionality changes, just pure code move (and renamed tests so that
their names reflect obj).

Reviewed By: Campbell Barton
Differential Revision: https://developer.blender.org/D14871

===================================================================

M	source/blender/io/common/CMakeLists.txt
M	source/blender/io/wavefront_obj/CMakeLists.txt
M	source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
M	source/blender/io/wavefront_obj/importer/obj_import_mtl.cc
R095	source/blender/io/common/intern/string_utils.cc	source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc
R085	source/blender/io/common/IO_string_utils.hh	source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh
R089	source/blender/io/common/intern/string_utils_test.cc	source/blender/io/wavefront_obj/tests/obj_import_string_utils_tests.cc

===================================================================

diff --git a/source/blender/io/common/CMakeLists.txt b/source/blender/io/common/CMakeLists.txt
index b1add38bf01..02bd5b2b81f 100644
--- a/source/blender/io/common/CMakeLists.txt
+++ b/source/blender/io/common/CMakeLists.txt
@@ -7,8 +7,6 @@ set(INC
   ../../blenlib
   ../../depsgraph
   ../../makesdna
-  ../../../../intern/guardedalloc
-  ../../../../extern/fast_float
 )
 
 set(INC_SYS
@@ -19,11 +17,9 @@ set(SRC
   intern/dupli_parent_finder.cc
   intern/dupli_persistent_id.cc
   intern/object_identifier.cc
-  intern/string_utils.cc
 
   IO_abstract_hierarchy_iterator.h
   IO_dupli_persistent_id.hh
-  IO_string_utils.hh
   IO_types.h
   intern/dupli_parent_finder.hh
 )
@@ -42,7 +38,6 @@ if(WITH_GTESTS)
     intern/abstract_hierarchy_iterator_test.cc
     intern/hierarchy_context_order_test.cc
     intern/object_identifier_test.cc
-    intern/string_utils_test.cc
   )
   set(TEST_INC
     ../../blenloader
diff --git a/source/blender/io/wavefront_obj/CMakeLists.txt b/source/blender/io/wavefront_obj/CMakeLists.txt
index e0fe7ed4992..a7c4253f4d3 100644
--- a/source/blender/io/wavefront_obj/CMakeLists.txt
+++ b/source/blender/io/wavefront_obj/CMakeLists.txt
@@ -4,7 +4,6 @@ set(INC
   .
   ./exporter
   ./importer
-  ../common
   ../../blenkernel
   ../../blenlib
   ../../bmesh
@@ -15,6 +14,7 @@ set(INC
   ../../makesrna
   ../../nodes
   ../../windowmanager
+  ../../../../extern/fast_float
   ../../../../extern/fmtlib/include
   ../../../../intern/guardedalloc
 )
@@ -35,6 +35,7 @@ set(SRC
   importer/obj_import_mesh.cc
   importer/obj_import_mtl.cc
   importer/obj_import_nurbs.cc
+  importer/obj_import_string_utils.cc
   importer/obj_importer.cc
 
   IO_wavefront_obj.h
@@ -50,12 +51,12 @@ set(SRC
   importer/obj_import_mtl.hh
   importer/obj_import_nurbs.hh
   importer/obj_import_objects.hh
+  importer/obj_import_string_utils.hh
   importer/obj_importer.hh
 )
 
 set(LIB
   bf_blenkernel
-  bf_io_common
 )
 
 if(WITH_TBB)
@@ -69,6 +70,7 @@ blender_add_lib(bf_wavefront_obj "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
 if(WITH_GTESTS)
   set(TEST_SRC
     tests/obj_exporter_tests.cc
+    tests/obj_import_string_utils_tests.cc
     tests/obj_importer_tests.cc
     tests/obj_mtl_parser_tests.cc
 
diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
index be322f49840..fa89b49b605 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
@@ -8,9 +8,8 @@
 #include "BLI_string_ref.hh"
 #include "BLI_vector.hh"
 
-#include "IO_string_utils.hh"
-
 #include "obj_import_file_reader.hh"
+#include "obj_import_string_utils.hh"
 
 namespace blender::io::obj {
 
diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc
index c2ecd8a37de..f39def0a4af 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc
@@ -13,13 +13,12 @@
 #include "DNA_material_types.h"
 #include "DNA_node_types.h"
 
-#include "IO_string_utils.hh"
-
 #include "NOD_shader.h"
 
 /* TODO: move eMTLSyntaxElement out of following file into a more neutral place */
 #include "obj_export_io.hh"
 #include "obj_import_mtl.hh"
+#include "obj_import_string_utils.hh"
 
 namespace blender::io::obj {
 
diff --git a/source/blender/io/common/intern/string_utils.cc b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc
similarity index 95%
rename from source/blender/io/common/intern/string_utils.cc
rename to source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc
index 3a12250e14b..c60306c8375 100644
--- a/source/blender/io/common/intern/string_utils.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 
-#include "IO_string_utils.hh"
+#include "obj_import_string_utils.hh"
 
 /* Note: we could use C++17 <charconv> from_chars to parse
  * floats, but even if some compilers claim full support,
@@ -11,7 +11,7 @@
 #include "fast_float.h"
 #include <charconv>
 
-namespace blender::io {
+namespace blender::io::obj {
 
 StringRef read_next_line(StringRef &buffer)
 {
@@ -96,4 +96,4 @@ StringRef parse_int(StringRef str, int fallback, int &dst, bool skip_space)
   return StringRef(res.ptr, str.end());
 }
 
-}  // namespace blender::io
+}  // namespace blender::io::obj
diff --git a/source/blender/io/common/IO_string_utils.hh b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh
similarity index 85%
rename from source/blender/io/common/IO_string_utils.hh
rename to source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh
index 25f1f01c6ed..532224569ac 100644
--- a/source/blender/io/common/IO_string_utils.hh
+++ b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh
@@ -5,10 +5,13 @@
 #include "BLI_string_ref.hh"
 
 /*
- * Various text parsing utilities commonly used by text-based input formats.
+ * Various text parsing utilities used by OBJ importer.
+ * The utilities are not directly usable by other formats, since
+ * they treat backslash (\) as a whitespace character (OBJ format
+ * allows backslashes to function as a line-continuation character).
  */
 
-namespace blender::io {
+namespace blender::io::obj {
 
 /**
  * Fetches next line from an input string buffer.
@@ -18,7 +21,7 @@ namespace blender::io {
  * the input line.
  *
  * Note that backslash (\) character is treated as a line
- * continuation, similar to OBJ file format or a C preprocessor.
+ * continuation.
  */
 StringRef read_next_line(StringRef &buffer);
 
@@ -66,4 +69,4 @@ StringRef parse_float(StringRef str, float fallback, float &dst, bool skip_space
  */
 StringRef parse_floats(StringRef str, float fallback, float *dst, int count);
 
-}  // namespace blender::io
+}  // namespace blender::io::obj
diff --git a/source/blender/io/common/intern/string_utils_test.cc b/source/blender/io/wavefront_obj/tests/obj_import_string_utils_tests.cc
similarity index 89%
rename from source/blender/io/common/intern/string_utils_test.cc
rename to source/blender/io/wavefront_obj/tests/obj_import_string_utils_tests.cc
index a78bd7ab8a3..addb1fa473e 100644
--- a/source/blender/io/common/intern/string_utils_test.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_import_string_utils_tests.cc
@@ -1,14 +1,14 @@
 /* SPDX-License-Identifier: Apache-2.0 */
 
-#include "IO_string_utils.hh"
+#include "obj_import_string_utils.hh"
 
 #include "testing/testing.h"
 
-namespace blender::io {
+namespace blender::io::obj {
 
 #define EXPECT_STRREF_EQ(str1, str2) EXPECT_STREQ(str1, std::string(str2).c_str())
 
-TEST(string_utils, read_next_line)
+TEST(obj_import_string_utils, read_next_line)
 {
   std::string str = "abc\n  \n\nline with \\\ncontinuation\nCRLF ending:\r\na";
   StringRef s = str;
@@ -21,7 +21,7 @@ TEST(string_utils, read_next_line)
   EXPECT_TRUE(s.is_empty());
 }
 
-TEST(string_utils, drop_whitespace)
+TEST(obj_import_string_utils, drop_whitespace)
 {
   /* Empty */
   EXPECT_STRREF_EQ("", drop_whitespace(""));
@@ -39,7 +39,7 @@ TEST(string_utils, drop_whitespace)
   EXPECT_STRREF_EQ("d", drop_whitespace(" \\ d"));
 }
 
-TEST(string_utils, parse_int_valid)
+TEST(obj_import_string_utils, parse_int_valid)
 {
   std::string str = "1 -10 \t  1234 1234567890 +7 123a";
   StringRef s = str;
@@ -59,7 +59,7 @@ TEST(string_utils, parse_int_valid)
   EXPECT_STRREF_EQ("a", s);
 }
 
-TEST(string_utils, parse_int_invalid)
+TEST(obj_import_string_utils, parse_int_invalid)
 {
   int val;
   /* Invalid syntax */
@@ -75,7 +75,7 @@ TEST(string_utils, parse_int_invalid)
   EXPECT_EQ(val, -4);
 }
 
-TEST(string_utils, parse_float_valid)
+TEST(obj_import_string_utils, parse_float_valid)
 {
   std::string str = "1 -10 123.5 -17.125 0.1 1e6 50.0e-1";
   StringRef s = str;
@@ -97,7 +97,7 @@ TEST(string_utils, parse_float_valid)
   EXPECT_TRUE(s.is_empty());
 }
 
-TEST(string_utils, parse_float_invalid)
+TEST(obj_import_string_utils, parse_float_invalid)
 {
   float val;
   /* Invalid syntax */
@@ -115,4 +115,4 @@ TEST(string_utils, parse_float_invalid)
   EXPECT_EQ(val, -4.0f);
 }
 
-}  // namespace blender::io
+}  // namespace blender::io::obj



More information about the Bf-blender-cvs mailing list