~zorba-coders/zorba/csx-module

« back to all changes in this revision

Viewing changes to src/csx.xq.src/csx.cpp

  • Committer: chillery+launchpad at lambda
  • Date: 2012-04-18 10:51:57 UTC
  • Revision ID: chillery+launchpad@lambda.nu-20120418105157-4nuns9miaru7flur
Mostly hopefully-temporary hacks to enable running some performance
evaluations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
#include "csx.h"
18
18
 
 
19
// QQQ
 
20
#include <valgrind/callgrind.h>
 
21
 
19
22
namespace zorba { namespace csx {
20
23
 
21
24
  using namespace std;
199
202
            }
200
203
          }
201
204
 
202
 
          // QQQ Hack necessary at the moment - only way to get typed value is
203
 
          // via getAtomizationValue() (poorly named), but it also throws an
204
 
          // exception if there is element-only content.
205
205
          bool has_atomic_values = false;
206
 
          try {
207
 
            children = item.getAtomizationValue();
208
 
            has_atomic_values = traverse(children, handler, false);
209
 
          }
210
 
          catch (ZorbaException &e) {
211
 
            //cout << e << endl;
 
206
          // QQQ There should be a better way to do this, but: We need to use the
 
207
          // actual text nodes for unvalidated content (only way to treat mixed
 
208
          // content correctly), but we need to get the typed-value for validated
 
209
          // content.
 
210
          Item type = item.getType();
 
211
          if (type.getLocalName().compare("untyped") != 0) {
 
212
            try {
 
213
              // QQQ Hack necessary at the moment - only way to get typed value is
 
214
              // via getAtomizationValue() (poorly named), but it also throws an
 
215
              // exception if there is element-only content.
 
216
              children = item.getAtomizationValue();
 
217
              has_atomic_values = traverse(children, handler, false);
 
218
            }
 
219
            catch (ZorbaException &e) {
 
220
              //cout << e << endl;
 
221
            }
212
222
          }
213
223
          children = item.getChildren();
214
224
          if(!children.isNull()){
233
243
          //cout << "text content: " << item.getStringValue() << endl;
234
244
        }
235
245
        else {
 
246
          cout << "Foo: " << getKindAsString(kind);
236
247
          assert(false);
237
248
        }
238
249
      }
255
266
      const zorba::StaticContext* aSctx,
256
267
      const zorba::DynamicContext* aDctx) const 
257
268
  {
 
269
    //CALLGRIND_START_INSTRUMENTATION;
 
270
 
258
271
    // Second argument is URIs to vocab files (optional)
259
272
    theModule->loadVocab(theProcessor, aArgs[1]->getIterator());
260
273
 
261
 
    stringstream theOutputStream;
 
274
    // QQQ hack for performance testing - should have an alternate form of
 
275
    // csx:serialize() that takes an output file
 
276
    ofstream theOutputStream("/tmp/out.csx");
 
277
    //stringstream theOutputStream;
262
278
    opencsx::CSXHandler* csxHandler = theProcessor->createSerializer(theOutputStream);
263
279
 
264
280
    // OpenCSX requires a document to create a CSX section header; might be a bug
273
289
 
274
290
    csxHandler->endDocument();
275
291
 
276
 
    string base64Result = zorba::encoding::Base64::encode(theOutputStream.str()).str();
277
 
    return ItemSequence_t(
278
 
      new SingletonItemSequence(Zorba::getInstance(0)->getItemFactory()->createBase64Binary(base64Result.c_str(),base64Result.length()))
279
 
    );
 
292
    // QQQ continued hack for performance testing; should introduce an alternate
 
293
    // csx:serializeToFile() or something
 
294
    theOutputStream.close();
 
295
    //CALLGRIND_STOP_INSTRUMENTATION;
 
296
//    string base64Result = zorba::encoding::Base64::encode(theOutputStream.str()).str();
 
297
//    return ItemSequence_t(
 
298
//          new SingletonItemSequence(
 
299
//            Zorba::getInstance(0)->getItemFactory()->
 
300
//            createBase64Binary(base64Result.c_str(),base64Result.length()))
 
301
//          );
280
302
  }
281
303
 
282
304
 
288
310
      const zorba::StaticContext* aSctx,
289
311
      const zorba::DynamicContext* aDctx) const 
290
312
  {
 
313
    //CALLGRIND_START_INSTRUMENTATION;
 
314
 
291
315
    // Second arg is URIs to vocab files (optional)
292
316
    theModule->loadVocab(theProcessor, aArgs[1]->getIterator());
293
317
 
300
324
      iter->open();
301
325
      Item input;
302
326
      if(iter->next(input)){
303
 
        string iString = zorba::encoding::Base64::decode(input.getStringValue()).str();
304
 
        stringstream ss(iString);
 
327
        //string iString = zorba::encoding::Base64::decode(input.getStringValue()).str();
 
328
        //stringstream ss(iString);
 
329
        void *lStore = zorba::StoreManager::getStore();
 
330
        Zorba* lZorba = Zorba::getInstance(lStore);
 
331
        Item input_file = lZorba->getXmlDataManager()->fetch(input.getStringValue());
305
332
        parserHandler->startDocument();
306
 
        theProcessor->parse(ss, parserHandler.get());
 
333
        theProcessor->parse(input_file.getStream(), parserHandler.get());
307
334
        input.close();
308
335
      }
309
336
      iter->close();
314
341
 
315
342
    VectorItemSequence *vSeq = (v.size() > 0)?new VectorItemSequence(v):NULL;
316
343
    parserHandler->endDocument();
 
344
    //CALLGRIND_STOP_INSTRUMENTATION;
317
345
    return ItemSequence_t(vSeq);
318
346
  }
319
347
 
385
413
      m_itemFactory->createTextNode(m_elemStack.back(), value.m_string);
386
414
    }
387
415
    else {
388
 
      // Cache atomics in case the element has a list of them.
 
416
      // Cache atomics in case the element has a list of them, because we can
 
417
      // only call assignElementTypedValue() once.
389
418
      m_atomics.push_back(getAtomicItem(value));
390
419
    }
391
420
  }