[glibmm] Extended build_filename() utility function



commit 79509124a9c79d230240f868e4adc6a541fc321a
Author: Fabrício Godoy <skarllot gmail com>
Date:   Sun Nov 29 20:29:57 2009 -0200

    Extended build_filename() utility function
    
    Extended build_filename() to accept up to nine parameters.
    Added a new testcase in tests/glibmm_buildfilename.

 ChangeLog                          |    9 +++
 glib/glibmm/miscutils.cc           |   66 +++++++++++++++++++++-
 glib/glibmm/miscutils.h            |  108 ++++++++++++++++++++++++++++++++++++
 tests/Makefile.am                  |    2 +
 tests/glibmm_buildfilename/main.cc |   37 ++++++++++++
 5 files changed, 221 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 25580aa..ad7578a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-02-21  Fabricio Godoy  <skarllot gmail com>
+
+  Extended build_filename() to accept up to nine parameters.
+  
+  * glib/glibmm/miscutils.[h|cc]: Added build_filename() method overloads that 
+ take more parameters, for convenience.
+  * tests/Makefile.am                  |    2 +
+  * tests/glibmm_buildfilename/main.cc: Added a new testcase.
+
 2.27.94:
 
 2011-02-21  Murray Cumming  <murrayc murrayc com>
diff --git a/glib/glibmm/miscutils.cc b/glib/glibmm/miscutils.cc
index 99f5085..2937ddb 100644
--- a/glib/glibmm/miscutils.cc
+++ b/glib/glibmm/miscutils.cc
@@ -189,7 +189,71 @@ std::string build_filename(const Glib::ArrayHandle<std::string>& elements)
 
 std::string build_filename(const std::string& elem1, const std::string& elem2)
 {
-  return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), elem2.c_str(), static_cast<char*>(0)));
+  return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(),
+    elem2.c_str(), static_cast<char*>(0)));
+}
+
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3)
+{
+  return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(),
+    elem2.c_str(), elem3.c_str(), static_cast<char*>(0)));
+}
+
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4)
+{
+  return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(),
+    elem2.c_str(), elem3.c_str(), elem4.c_str(), static_cast<char*>(0)));
+}
+
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4,
+                           const std::string& elem5)
+{
+  return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(),
+    elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(),
+    static_cast<char*>(0)));
+}
+
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4,
+                           const std::string& elem5, const std::string& elem6)
+{
+  return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(),
+    elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), elem6.c_str(),
+    static_cast<char*>(0)));
+}
+
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4,
+                           const std::string& elem5, const std::string& elem6,
+                           const std::string& elem7)
+{
+  return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(),
+    elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), elem6.c_str(),
+    elem7.c_str(), static_cast<char*>(0)));
+}
+
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4,
+                           const std::string& elem5, const std::string& elem6,
+                           const std::string& elem7, const std::string& elem8)
+{
+  return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(),
+    elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), elem6.c_str(),
+    elem7.c_str(), elem8.c_str(), static_cast<char*>(0)));
+}
+
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4,
+                           const std::string& elem5, const std::string& elem6,
+                           const std::string& elem7, const std::string& elem8,
+                           const std::string& elem9)
+{
+  return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(),
+    elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), elem6.c_str(),
+    elem7.c_str(), elem8.c_str(), elem9.c_str(), static_cast<char*>(0)));
 }
 
 std::string build_path(const std::string& separator, const Glib::ArrayHandle<std::string>& elements)
diff --git a/glib/glibmm/miscutils.h b/glib/glibmm/miscutils.h
index 3e4ae8d..89692ee 100644
--- a/glib/glibmm/miscutils.h
+++ b/glib/glibmm/miscutils.h
@@ -280,6 +280,114 @@ std::string build_filename(const Glib::ArrayHandle<std::string>& elements);
  */
 std::string build_filename(const std::string& elem1, const std::string& elem2);
 
+/** Creates a filename from three elements using the correct separator for filenames.
+ * No attempt is made to force the resulting filename to be an absolute path.
+ * If the first element is a relative path, the result will be a relative path.
+ * @param elem1 First path element.
+ * @param elem2 Second path element.
+ * @param elem3 Third path element.
+ * @return The resulting path.
+ */
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3);
+
+
+/** Creates a filename from four elements using the correct separator for filenames.
+ * No attempt is made to force the resulting filename to be an absolute path.
+ * If the first element is a relative path, the result will be a relative path.
+ * @param elem1 First path element.
+ * @param elem2 Second path element.
+ * @param elem3 Third path element.
+ * @param elem4 Fourth path element.
+ * @return The resulting path.
+ */
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4);
+
+/** Creates a filename from five elements using the correct separator for filenames.
+ * No attempt is made to force the resulting filename to be an absolute path.
+ * If the first element is a relative path, the result will be a relative path.
+ * @param elem1 First path element.
+ * @param elem2 Second path element.
+ * @param elem3 Third path element.
+ * @param elem4 Fourth path element.
+ * @param elem5 Fifth path element.
+ * @return The resulting path.
+ */
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4,
+                           const std::string& elem5);
+
+/** Creates a filename from six elements using the correct separator for filenames.
+ * No attempt is made to force the resulting filename to be an absolute path.
+ * If the first element is a relative path, the result will be a relative path.
+ * @param elem1 First path element.
+ * @param elem2 Second path element.
+ * @param elem3 Third path element.
+ * @param elem4 Fourth path element.
+ * @param elem5 Fifth path element.
+ * @param elem6 Sixth path element.
+ * @return The resulting path.
+ */
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4,
+                           const std::string& elem5, const std::string& elem6);
+
+/** Creates a filename from seven elements using the correct separator for filenames.
+ * No attempt is made to force the resulting filename to be an absolute path.
+ * If the first element is a relative path, the result will be a relative path.
+ * @param elem1 First path element.
+ * @param elem2 Second path element.
+ * @param elem3 Third path element.
+ * @param elem4 Fourth path element.
+ * @param elem5 Fifth path element.
+ * @param elem6 Sixth path element.
+ * @param elem7 Seventh path element.
+ * @return The resulting path.
+ */
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4,
+                           const std::string& elem5, const std::string& elem6,
+                           const std::string& elem7);
+
+/** Creates a filename from eight elements using the correct separator for filenames.
+ * No attempt is made to force the resulting filename to be an absolute path.
+ * If the first element is a relative path, the result will be a relative path.
+ * @param elem1 First path element.
+ * @param elem2 Second path element.
+ * @param elem3 Third path element.
+ * @param elem4 Fourth path element.
+ * @param elem5 Fifth path element.
+ * @param elem6 Sixth path element.
+ * @param elem7 Seventh path element.
+ * @param elem8 Eighth path element.
+ * @return The resulting path.
+ */
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4,
+                           const std::string& elem5, const std::string& elem6,
+                           const std::string& elem7, const std::string& elem8);
+
+/** Creates a filename from nine elements using the correct separator for filenames.
+ * No attempt is made to force the resulting filename to be an absolute path.
+ * If the first element is a relative path, the result will be a relative path.
+ * @param elem1 First path element.
+ * @param elem2 Second path element.
+ * @param elem3 Third path element.
+ * @param elem4 Fourth path element.
+ * @param elem5 Fifth path element.
+ * @param elem6 Sixth path element.
+ * @param elem7 Seventh path element.
+ * @param elem8 Eighth path element.
+ * @param elem9 Ninth path element.
+ * @return The resulting path.
+ */
+std::string build_filename(const std::string& elem1, const std::string& elem2,
+                           const std::string& elem3, const std::string& elem4,
+                           const std::string& elem5, const std::string& elem6,
+                           const std::string& elem7, const std::string& elem8,
+                           const std::string& elem9);
+
 /** Creates a path from a series of elements using @a separator as the
  * separator between elements.
  *
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d20d4a1..9f922b2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,6 +23,7 @@ check_PROGRAMS =				\
 	giomm_asyncresult_sourceobject/test	\
 	glibmm_btree/test			\
 	glibmm_date/test			\
+	glibmm_buildfilename/test	\
 	glibmm_nodetree/test			\
 	glibmm_ustring_compose/test		\
 	glibmm_ustring_format/test		\
@@ -56,6 +57,7 @@ giomm_asyncresult_sourceobject_test_SOURCES  = giomm_asyncresult_sourceobject/ma
 giomm_asyncresult_sourceobject_test_LDADD    = $(giomm_ldadd)
 
 glibmm_btree_test_SOURCES            = glibmm_btree/main.cc
+glibmm_buildfilename_test_SOURCES   = glibmm_buildfilename/main.cc
 glibmm_date_test_SOURCES             = glibmm_date/main.cc
 glibmm_nodetree_test_SOURCES         = glibmm_nodetree/main.cc
 glibmm_ustring_compose_test_SOURCES  = glibmm_ustring_compose/main.cc
diff --git a/tests/glibmm_buildfilename/main.cc b/tests/glibmm_buildfilename/main.cc
new file mode 100644
index 0000000..214a60e
--- /dev/null
+++ b/tests/glibmm_buildfilename/main.cc
@@ -0,0 +1,37 @@
+#include <glibmm.h>
+#include <iostream>
+#include <string.h>
+
+#define DIR "/dir1/dir_2/dir-3"
+#define FILE "dir/file.ext"
+
+int main(int, char**)
+{
+  gchar* dir_1 = g_strdup(DIR);
+  std::string dir_2(DIR);
+  Glib::ustring dir_3(DIR);
+  gchar* file_1 = g_strdup(FILE);
+  std::string file_2(FILE);
+  Glib::ustring file_3(FILE);
+
+  std::string path;
+
+  path = Glib::build_filename(dir_1, file_3);
+  std::cout << "Path 1: " << path << std::endl;
+
+  path = Glib::build_filename(dir_1, dir_2, FILE);
+  std::cout << "Path 2: " << path << std::endl;
+
+  path = Glib::build_filename(dir_1, dir_2, dir_3, FILE);
+  std::cout << "Path 3: " << path << std::endl;
+
+  path = Glib::build_filename(dir_1, dir_2, dir_3, file_1);
+  std::cout << "Path 4: " << path << std::endl;
+
+  path = Glib::build_filename(dir_1, dir_2, dir_1, dir_3, dir_2, dir_3,
+    dir_1, dir_2, file_2);
+  std::cout << "Path 5: " << path << std::endl;
+
+  return 0;
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]