~zorba-coders/zorba/feature-cloudant

« back to all changes in this revision

Viewing changes to src/api/store_consts.cpp

  • Committer: Zorba Jenkins
  • Author(s): Paul J. Lucas
  • Date: 2013-07-23 20:21:13 UTC
  • mfrom: (10944.1.340 pjl-misc)
  • Revision ID: jenkins@lambda.nu-20130723202113-utnoo9ld8px6arbr
Added operator<< for enums; moved to .cpp.
Approved: Matthias Brantner, Paul J. Lucas

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 */
16
16
 
17
17
#include "stdafx.h"
 
18
 
 
19
#include <sstream>
 
20
 
18
21
#include <zorba/store_consts.h>
19
22
 
20
23
namespace zorba {
76
79
  if ( c >= 0 && c < XS_LAST )
77
80
    o << s[ c ];
78
81
  else
79
 
    o << "[illegal type code: " << (int)c << ']';
80
 
 
 
82
    o << "<unknown SchemaTypeCode: " << (int)c << '>';
81
83
  return o;
82
84
};
83
85
 
84
86
///////////////////////////////////////////////////////////////////////////////
85
87
 
 
88
std::ostream& operator<<( std::ostream &o, StoreConsts::NodeKind k ) {
 
89
  static char const *const s[] = {
 
90
    "anyNode",        // 0
 
91
    "documentNode",   // 1
 
92
    "elementNode",    // 2
 
93
    "attributeNode",  // 3
 
94
    "textNode",       // 4
 
95
    "piNode",         // 5
 
96
    "commentNode",    // 6
 
97
    "namespaceNode"   // 7
 
98
  };
 
99
 
 
100
  if ( k >= 0 && k <= StoreConsts::namespaceNode )
 
101
    o << s[ k ];
 
102
  else
 
103
    o << "<unknown NodeKind: " << (int)k << '>';
 
104
  return o;
 
105
}
 
106
 
 
107
std::string StoreConsts::toString( NodeKind k ) {
 
108
  std::ostringstream oss;
 
109
  oss << k;
 
110
  return oss.str();
 
111
}
 
112
 
 
113
std::string StoreConsts::toSchemaString( NodeKind k ) {
 
114
  static char const *const s[] = {
 
115
    "node",                   // 0
 
116
    "document-node",          // 1
 
117
    "element",                // 2
 
118
    "attribute",              // 3
 
119
    "text",                   // 4
 
120
    "processing-instruction", // 5
 
121
    "comment",                // 6
 
122
    "namespace-node"          // 7
 
123
  };
 
124
 
 
125
  if ( k >= 0 && k <= namespaceNode )
 
126
    return s[ k ];
 
127
  else {
 
128
    std::ostringstream oss;
 
129
    oss << "<unknown NodeKind: " << (int)k << '>';
 
130
    return oss.str();
 
131
  }
 
132
}
 
133
 
 
134
std::ostream& operator<<( std::ostream &o, StoreConsts::JSONItemKind k ) {
 
135
  static char const *const s[] = {
 
136
    "json-item",  // 0
 
137
    "object",     // 1
 
138
    "array"       // 2
 
139
  };
 
140
 
 
141
  if ( k >= 0 && k <= 2 )
 
142
    o << s[ k ];
 
143
  else
 
144
    o << "<unknown JSONItemKind: " << (int)k << '>';
 
145
  return o;
 
146
}
 
147
 
 
148
///////////////////////////////////////////////////////////////////////////////
 
149
 
86
150
} // namespace store
87
151
} // namespace zorba
88
152