[Saga-devel] saga SVN commit 3358: /trunk/tools/clutils/context/

amerzky at cct.lsu.edu amerzky at cct.lsu.edu
Fri Jan 23 19:26:33 CST 2009


User: amerzky
Date: 2009/01/23 07:26 PM

Added:
 /trunk/tools/clutils/context/
  Makefile, saga-context.cpp

Log:
 add context checker

File Changes:

Directory: /trunk/tools/clutils/context/
========================================

File [added]: Makefile
Delta lines: +13 -0
===================================================================
--- trunk/tools/clutils/context/Makefile	2009-01-23 18:43:18 UTC (rev 3357)
+++ trunk/tools/clutils/context/Makefile	2009-01-24 01:26:21 UTC (rev 3358)
@@ -0,0 +1,13 @@
+#  Copyright (c) 2005-2006 Andre Merzky (andre at merzky.net)
+# 
+#  Distributed under 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)
+
+SAGA_ROOT        = ../../../
+
+SAGA_SRC         = $(wildcard *.cpp)
+SAGA_ADD_BIN_OBJ = $(SAGA_SRC:%.cpp=%.o)
+SAGA_BIN         = saga-context
+
+include $(SAGA_ROOT)/make/saga.application.mk
+

File [added]: saga-context.cpp
Delta lines: +87 -0
===================================================================
--- trunk/tools/clutils/context/saga-context.cpp	2009-01-23 18:43:18 UTC (rev 3357)
+++ trunk/tools/clutils/context/saga-context.cpp	2009-01-24 01:26:21 UTC (rev 3358)
@@ -0,0 +1,87 @@
+//  Copyright (c) 2005-2007 Andre Merzky <andre at merzky.net>
+//
+//  Distributed under the Boost Software License, Version 1.0.
+//  (See accompanying file LICENSE file or copy at
+//  http://www.boost.org/LICENSE_1_0.txt)
+
+#include <saga/saga.hpp>
+
+#define COUNT 100
+
+void dump_context (saga::context c)
+{
+  std::vector <std::string> attribs = c.list_attributes ();
+
+  std::cout << " ------------------------------ " << std::endl;
+
+  for ( int i = 0; i < attribs.size (); i++ )
+  {
+    std::cout << " " << attribs[i] << " \t: ";
+
+    if ( c.attribute_is_vector (attribs[i]) )
+    {
+      std::vector <std::string> vals = c.get_vector_attribute (attribs[i]);
+
+      for ( int j = 0; j < vals.size (); j++ )
+      {
+        std::cout << vals[j] << " ";
+      }
+    }
+    else
+    {
+      std::string val = c.get_attribute (attribs[i]);
+      std::cout << val << " ";
+    }
+
+    std::cout << std::endl;
+  }
+
+  std::cout << " ------------------------------ " << std::endl;
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// print all contexts of the default session.  If a specific type is given,
+// print only contexts of that type.  If no matching context is found, return an
+// error.
+//
+int main (int argc, char* argv[])
+{
+  std::string type = "";
+
+  if ( argc > 1 )
+  {
+    type = argv[1];
+  }
+
+  try 
+  {
+    int n = 0;
+    saga::session s;
+    std::vector <saga::context> contexts = s.list_contexts ();
+
+    for ( unsigned int i = 0; i < contexts.size (); i++ )
+    {
+      if ( type == "" ||
+           type == contexts[i].get_attribute (saga::attributes::context_type) )
+      {
+        dump_context (contexts[i]);
+        n++;
+      }
+    }
+
+    if ( 0 == n )
+    {
+      return 1;
+    }
+  }
+  catch ( const saga::exception & e )
+  {
+    std::cerr << e.what () << std::endl;
+    return 2;
+  }
+  
+  return 0; 
+}
+



More information about the saga-devel mailing list