[Saga-devel] saga SVN commit 3259: /trunk/saga/saga/adaptors/utils/

amerzky at cct.lsu.edu amerzky at cct.lsu.edu
Sun Jan 11 02:29:42 CST 2009


User: amerzky
Date: 2009/01/11 02:29 AM

Added:
 /trunk/saga/saga/adaptors/utils/
  utils.cpp

Log:
 add missing file

File Changes:

Directory: /trunk/saga/saga/adaptors/utils/
===========================================

File [added]: utils.cpp
Delta lines: +143 -0
===================================================================
--- trunk/saga/saga/adaptors/utils/utils.cpp	2009-01-11 07:54:12 UTC (rev 3258)
+++ trunk/saga/saga/adaptors/utils/utils.cpp	2009-01-11 08:29:31 UTC (rev 3259)
@@ -0,0 +1,143 @@
+//  Copyright (c) 2005-2006 Andre Merzky (andre at merzky.net)
+// 
+//  Use, modification and distribution is subject to the Boost Software
+//  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+//  http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef SAGA_UTILS_HPP
+#define SAGA_UTILS_HPP
+
+#include <saga/saga/adaptors/utils/ini/ini.hpp>
+#include <saga/saga/adaptors/utils/process/process.hpp>
+ 
+namespace saga
+{
+  namespace adaptors
+  {
+    namespace utils
+    {
+      ///////////////////////////////////////////////////////////////////////////////
+      std::vector <std::string> split (std::string line,
+                                       char        delim)
+      {
+        std::vector <std::string> list;
+        std::string               elem;
+
+        for ( unsigned int i = 0; i < line.length (); i++ )
+        {
+          char c = line[i];
+
+          if ( c == delim )
+          {
+            // store element if there is any content (even if element is empty)
+            list.push_back (elem);
+            elem = "";
+          }
+          else
+          {
+            // save any char which is not the delimiter
+            elem += c;
+          }
+        }
+
+        if ( elem.length () > 0 )
+        {
+          // save remaining content after last delimiter
+          list.push_back (elem);
+        }
+
+        // std::cout << "split '" << line << "'\n";
+        // for ( unsigned int j = 0; j < list.size (); j++ )
+        // {
+        //   std::cout << "  [" << j << "]  " << list[j] << std::endl;
+        // }
+
+        return (list);
+      }
+
+      //////////////////////////////////////////////////////////////////
+      std::vector <std::string> head (int n, 
+                                      std::vector <std::string> in)
+      {
+        std::vector <std::string> out;
+
+        for ( unsigned int i = 0; i < in.size () && i < n; i++ )
+        {
+          out.push_back (in[i]);
+        }
+
+        return out;
+      }
+
+      //////////////////////////////////////////////////////////////////
+      std::vector <std::string> tail (int n, 
+                                      std::vector <std::string> in)
+      {
+        std::vector <std::string> out;
+
+        for ( unsigned int i = in.size () - n; i < in.size () ; i++ )
+        {
+          out.push_back (in[i]);
+        }
+
+        return out;
+      }
+
+      //////////////////////////////////////////////////////////////////
+      // lines should not include newlines
+      std::vector <std::string> rev  (std::vector <std::string> in)
+      {
+        std::vector <std::string> out;
+
+        for ( unsigned int i = 0; i < in.size (); i++ )
+        {
+          std::string line;
+
+          for ( unsigned int j = in[i].length (); j > 0; j-- )
+          {
+            line += in[i][j];
+          }
+
+          out.push_back (line);
+        }
+
+        return out;
+      }
+
+      //////////////////////////////////////////////////////////////////
+      std::vector <std::string> tac  (std::vector <std::string> in)
+      {
+        std::vector <std::string> out;
+
+        for ( unsigned int i = in.size (); i > 0; i-- )
+        {
+          out.push_back (in[i-1]);
+        }
+
+        return out;
+      }
+
+      //////////////////////////////////////////////////////////////////
+      std::vector <std::string> grep (std::string pattern, 
+                                      std::vector <std::string> in)
+      {
+        std::vector <std::string> out;
+
+        for ( unsigned int i = 0; i < in.size (); i++ )
+        {
+          if ( in[i].find (pattern) != std::string::npos )
+          {
+            out.push_back (in[i]);
+          }
+        }
+
+        return out;
+      }
+
+
+    } // namespace utils
+  } // namespace adaptors 
+} // namespace saga
+
+#endif // SAGA_UTILS_HPP
+



More information about the saga-devel mailing list