~juan457/+junk/zorba

« back to all changes in this revision

Viewing changes to context/context.cpp

  • Committer: paulped at ETHZ
  • Date: 2007-01-25 19:55:55 UTC
  • Revision ID: svn-v4:8046edc3-af21-0410-8661-ec7318497eea:trunk/zorba:334
added nodeid service to context
added a test data directory 'wordlists'
miscellaneous bug fixes, unit testing improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; indent-tabs-mode: nil -*-
 
1
/** -*- mode: c++; indent-tabs-mode: nil -*-
2
2
 *
3
3
 *  $Id: context.cpp,v 1.1 2006/10/09 07:07:59 Paul Pedersen Exp $
4
4
 *
10
10
 
11
11
#include "context.h"
12
12
 
 
13
#include "../util/xqp_exception.h"
 
14
#include "../values/values.h"
 
15
 
 
16
#include <stdlib.h>
13
17
#include <sstream>
14
18
#include <string>
15
19
 
16
 
#include "../util/xqp_exception.h"
17
 
#include "../values/values.h"
 
20
 
 
21
/*+=========================================+
 
22
        |                                         |
 
23
        |  The context module is still mostly     |
 
24
        |  stubbed out.                           |
 
25
        |                                         |
 
26
        +=========================================+
 
27
*/
 
28
 
18
29
 
19
30
using namespace std;
20
31
namespace xqp {
21
32
 
22
33
#define EMPTY_SEQUENCE(X) item_iterator((X))
23
34
  
24
 
 
25
 
///////////////////////////////
26
 
//  var_binding
27
 
///////////////////////////////
 
35
/*...........................................
 
36
        : default constructor                     :
 
37
        :.........................................:
 
38
*/
 
39
 
 
40
//XXX: seriously missing: context constructor from XML config file.
 
41
 
 
42
context::context()
 
43
:
 
44
        parent_h(NULL),
 
45
        namespaces(),
 
46
        in_scope_schema_types(),
 
47
        in_scope_elem_decls(),
 
48
        in_scope_attr_decls(),
 
49
        in_scope_vars(),
 
50
        collations(),
 
51
        //statically_known_collection_types(32,0.6),
 
52
        signature_map(256,0.6),
 
53
        statically_known_documents(256,0.6),
 
54
        statically_known_collections(64,0.6),
 
55
        context_item_h(NULL),
 
56
        context_position(0),
 
57
        context_size(0),
 
58
        var_values(1024,0.6),
 
59
        function_implementations(1024,0.6),
 
60
        timezone(-8),
 
61
        available_documents(1024,0.6),
 
62
        available_collections(1024,0.6),
 
63
        default_collection("defcol"),
 
64
        nodeid_counter("nodeid",1),
 
65
        string_store(1<<16)
 
66
{
 
67
}
 
68
 
 
69
context::~context()
 
70
{
 
71
}
 
72
 
 
73
 
 
74
/*...........................................
 
75
        : nodeids                                 :
 
76
        :.........................................:
 
77
*/
 
78
 
 
79
        // this is a persistent counter
 
80
nodeid context::next_nodeid()
 
81
{
 
82
        return nodeid(++nodeid_counter[0]);
 
83
}
 
84
 
 
85
nodeid context::context_nodeid()
 
86
{
 
87
        if (!context_item_h->is_node())
 
88
                throw xqp_exception(__FUNCTION__,"nodeid expects node");
 
89
        node* n_p = dynamic_cast<node*>(&*context_item_h);
 
90
        return n_p->get_nodeid();
 
91
}
 
92
 
 
93
 
 
94
/*...........................................
 
95
        : variables                               :
 
96
        :.........................................:
 
97
*/
28
98
 
29
99
var_binding::var_binding()
30
100
:
63
133
{
64
134
}
65
135
 
66
 
 
67
 
 
68
 
///////////////////////////////
69
 
//  context
70
 
///////////////////////////////
71
 
 
72
 
context::context()
73
 
:
74
 
        parent_h(NULL),
75
 
 
76
 
/*
77
 
        namespaces(),
78
 
        in_scope_schema_types(1024),
79
 
        in_scope_elem_decls(1024),
80
 
        in_scope_attr_decls(1024),
81
 
        in_scope_vars(1024),
82
 
        collations(1024),
83
 
        statically_known_collection_types(32,0.6),
84
 
*/
85
 
 
86
 
        signature_map(256,0.6),
87
 
        statically_known_documents(256,0.6),
88
 
        statically_known_collections(64,0.6),
89
 
 
90
 
        context_item(*this),
91
 
        context_position(0),
92
 
        context_size(0),
93
 
        var_values(1024,0.6),
94
 
        function_implementations(1024,0.6),
95
 
        timezone(-8),
96
 
        available_documents(1024,0.6),
97
 
        available_collections(1024,0.6),
98
 
        default_collection("defcol")
99
 
{
100
 
}
101
 
 
102
 
context::~context()
103
 
{
104
 
}
105
 
 
106
 
 
107
136
void context::push_var(
108
137
        rchandle<var_binding> vb_h)
109
138
{
131
160
        }
132
161
}
133
162
 
 
163
 
 
164
/*...........................................
 
165
        : functions                               :
 
166
        :.........................................:
 
167
*/
 
168
 
134
169
string context::get_function_type(
135
170
  QName const& fqname, 
136
171
  uint32_t arity) const 
146
181
  return sig_h;
147
182
}
148
183
        
 
184
function_impl const* context::get_function(
 
185
        signature const& sig) const
 
186
throw (xqp_exception)
 
187
{
 
188
        return NULL;
 
189
}
 
190
 
 
191
 
 
192
/*...........................................
 
193
        : context document                        :
 
194
        :.........................................:
 
195
*/
 
196
 
149
197
item_type context::get_document_type(
150
198
        string const& doc_uri) const
151
199
throw (xqp_exception)
158
206
  return t;
159
207
}
160
208
        
 
209
item_iterator context::get_document(
 
210
        string const& doc_uri) const
 
211
throw (xqp_exception)
 
212
{
 
213
  return EMPTY_SEQUENCE(*this);
 
214
}
 
215
 
 
216
 
 
217
/*...........................................
 
218
        : context collection                      :
 
219
        :.........................................:
 
220
*/
 
221
 
161
222
item_type context::get_collection_type(
162
223
        string const& col_uri) const
163
224
throw (xqp_exception)
170
231
  return t;
171
232
}
172
233
        
173
 
function_impl const* context::get_function(
174
 
        signature const& sig) const
175
 
throw (xqp_exception)
176
 
{
177
 
        return NULL;
178
 
}
179
 
 
180
 
item_iterator context::get_document(
181
 
        string const& doc_uri) const
182
 
throw (xqp_exception)
183
 
{
184
 
  return EMPTY_SEQUENCE(*this);
185
 
}
186
 
 
187
234
item_iterator context::get_collection(
188
235
        string const& col_uri) const
189
236
throw (xqp_exception)