Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

Commit message:
Added operator<< for enums; moved to .cpp.

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/176445

Added operator<< for enums; moved to .cpp.
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/176445
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/store_consts.h'
--- include/zorba/store_consts.h	2013-06-29 08:38:53 +0000
+++ include/zorba/store_consts.h	2013-07-23 17:37:32 +0000
@@ -20,7 +20,10 @@
 #include <string>
 #include <zorba/config.h>
 
-namespace zorba { namespace store {
+namespace zorba {
+namespace store {
+
+///////////////////////////////////////////////////////////////////////////////
 
 /*******************************************************************************
   !!! ATTENTION: The order of the enum values within SchemaTypeCode is important.
@@ -91,8 +94,10 @@
   XS_LAST
 };
 
+ZORBA_DLL_PUBLIC
 std::ostream& operator<<( std::ostream&, SchemaTypeCode );
 
+///////////////////////////////////////////////////////////////////////////////
 
 class ZORBA_DLL_PUBLIC StoreConsts
 {
@@ -135,74 +140,10 @@
     namespaceNode  = 7
   };
 
-  static std::string toString(NodeKind k)
-  {
-    switch(k)
-    {
-    case anyNode:
-      return "anyNode";
-
-    case documentNode:
-      return "documentNode";
-
-    case elementNode:
-      return "elementNode";
-
-    case attributeNode:
-      return "attributeNode";
-
-    case textNode:
-      return "textNode";
-
-    case piNode:
-      return "piNode";
-
-    case commentNode:
-      return "commentNode";
-
-    case namespaceNode:
-      return "namespaceNode";
-
-    default:
-      return "<unknown NodeKind>";
-    }
-  }
-
-  static std::string toSchemaString(NodeKind k)
-  {
-    switch(k)
-    {
-    case anyNode:
-      return "node";
-
-    case documentNode:
-      return "document-node";
-
-    case elementNode:
-      return "element";
-
-    case attributeNode:
-      return "attribute";
-
-    case textNode:
-      return "text";
-
-    case piNode:
-      return "processing-instruction";
-
-    case commentNode:
-      return "comment";
-
-    case namespaceNode:
-      return "namespace-node";
-
-    default:
-      return "<unknown NodeKind>";
-    }
-  }
-
-
-  /* ATTENTION: the ordering of the enum values is important. Do NOT change it! */
+  static std::string toString(NodeKind);
+  static std::string toSchemaString(NodeKind);
+
+  // ATTENTION: the ordering of the enum values is important. Do NOT change it!
   enum JSONItemKind
   {
     jsonItem       = 0,
@@ -210,26 +151,16 @@
     jsonArray      = 2
   };
 
-
-  static std::string toString(JSONItemKind k)
-  {
-    switch(k)
-    {
-      case jsonItem:
-        return "json-item";
-
-      case jsonObject:
-        return "object";
-
-      case jsonArray:
-        return "array";
-
-      default:
-        return "<unknown JSONItemKind>";
-    }
-  }
 };
 
+ZORBA_DLL_PUBLIC
+std::ostream& operator<<( std::ostream&, StoreConsts::NodeKind );
+
+ZORBA_DLL_PUBLIC
+std::ostream& operator<<( std::ostream&, StoreConsts::JSONItemKind );
+
+///////////////////////////////////////////////////////////////////////////////
+
 } // namespace store
 } // namespace zorba
 #endif

=== modified file 'src/api/store_consts.cpp'
--- src/api/store_consts.cpp	2013-02-26 20:56:33 +0000
+++ src/api/store_consts.cpp	2013-07-23 17:37:32 +0000
@@ -15,6 +15,9 @@
  */
 
 #include "stdafx.h"
+
+#include <sstream>
+
 #include <zorba/store_consts.h>
 
 namespace zorba {
@@ -76,13 +79,74 @@
   if ( c >= 0 && c < XS_LAST )
     o << s[ c ];
   else
-    o << "[illegal type code: " << (int)c << ']';
-
+    o << "<unknown SchemaTypeCode: " << (int)c << '>';
   return o;
 };
 
 ///////////////////////////////////////////////////////////////////////////////
 
+std::ostream& operator<<( std::ostream &o, StoreConsts::NodeKind k ) {
+  static char const *const s[] = {
+    "anyNode",        // 0
+    "documentNode",   // 1
+    "elementNode",    // 2
+    "attributeNode",  // 3
+    "textNode",       // 4
+    "piNode",         // 5
+    "commentNode",    // 6
+    "namespaceNode"   // 7
+  };
+
+  if ( k >= 0 && k <= StoreConsts::namespaceNode )
+    o << s[ k ];
+  else
+    o << "<unknown NodeKind: " << (int)k << '>';
+  return o;
+}
+
+std::string StoreConsts::toString( NodeKind k ) {
+  std::ostringstream oss;
+  oss << k;
+  return oss.str();
+}
+
+std::string StoreConsts::toSchemaString( NodeKind k ) {
+  static char const *const s[] = {
+    "node",                   // 0
+    "document-node",          // 1
+    "element",                // 2
+    "attribute",              // 3
+    "text",                   // 4
+    "processing-instruction", // 5
+    "comment",                // 6
+    "namespace-node"          // 7
+  };
+
+  if ( k >= 0 && k <= namespaceNode )
+    return s[ k ];
+  else {
+    std::ostringstream oss;
+    oss << "<unknown NodeKind: " << (int)k << '>';
+    return oss.str();
+  }
+}
+
+std::ostream& operator<<( std::ostream &o, StoreConsts::JSONItemKind k ) {
+  static char const *const s[] = {
+    "json-item",  // 0
+    "object",     // 1
+    "array"       // 2
+  };
+
+  if ( k >= 0 && k <= 2 )
+    o << s[ k ];
+  else
+    o << "<unknown JSONItemKind: " << (int)k << '>';
+  return o;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
 } // namespace store
 } // namespace zorba
 

=== modified file 'src/compiler/parsetree/parsenode_print_xml_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xml_visitor.cpp	2013-06-07 13:46:26 +0000
+++ src/compiler/parsetree/parsenode_print_xml_visitor.cpp	2013-07-23 17:37:32 +0000
@@ -1093,7 +1093,7 @@
 void* begin_visit(const JSON_Test& n)
 {
   INDENT;
-  os << "<JSON_Test type=\"" << store::StoreConsts::toString(n.get_kind()) << "\"/>";
+  os << "<JSON_Test type=\"" << n.get_kind() << "\"/>";
   INDENT_INC; NL;
   return no_state;
 }

=== modified file 'src/compiler/parsetree/parsenode_print_xquery_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xquery_visitor.cpp	2013-06-07 13:46:26 +0000
+++ src/compiler/parsetree/parsenode_print_xquery_visitor.cpp	2013-07-23 17:37:32 +0000
@@ -2081,7 +2081,7 @@
 
   void* begin_visit(const JSON_Test& n)
   {
-    os << store::StoreConsts::toString(n.get_kind()) << "()";
+    os << n.get_kind() << "()";
     return no_state;
   }
   DEFAULT_END_VISIT (JSON_Test);

=== modified file 'src/types/typeimpl.cpp'
--- src/types/typeimpl.cpp	2013-07-02 21:32:23 +0000
+++ src/types/typeimpl.cpp	2013-07-23 17:37:32 +0000
@@ -744,7 +744,7 @@
 ********************************************************************************/
 std::ostream& JSONXQType::serialize_ostream(std::ostream& os) const
 {
-  os << "[JSONXQType " << store::StoreConsts::toString(theJSONKind)
+  os << "[JSONXQType " << theJSONKind
      << TypeOps::decode_quantifier(get_quantifier());
 
   return os << "]";

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to