Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
SAXReader.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include <atomic>
7
8#include "Stroika/Foundation/DataExchange/BadFormatException.h"
10#include "Stroika/Foundation/Execution/Common.h"
12#include "Stroika/Foundation/Execution/ProgressMonitor.h"
13#include "Stroika/Foundation/Memory/Common.h"
16
17#include "SAXReader.h"
18
19// Comment this in to turn on aggressive noisy DbgTrace in this module
20//#define USE_NOISY_TRACE_IN_THIS_MODULE_ 1
21
22using std::byte;
23
24using namespace Stroika::Foundation;
25using namespace Stroika::Foundation::Debug;
26using namespace Stroika::Foundation::Execution;
28using namespace Stroika::Foundation::DataExchange::XML;
29using namespace Stroika::Foundation::Streams;
30
31/*
32 ********************************************************************************
33 ************************************* SAXParse *********************************
34 ********************************************************************************
35 */
36#if qStroika_Foundation_DataExchange_XML_SupportParsing
37void XML::SAXParse (const Streams::InputStream::Ptr<byte>& in, StructuredStreamEvents::IConsumer* callback, const Schema::Ptr& schema,
39{
40 static const XML::Providers::ISAXProvider* kDefaultProvider_ = XML::Providers::kDefaultProvider ();
41 return SAXParse (*kDefaultProvider_, in, callback, schema, progress);
42}
43#endif
44
45void XML::SAXParse (const Providers::ISAXProvider& saxProvider, const Streams::InputStream::Ptr<byte>& in,
47{
48 Schema::Ptr useSchema = schema;
49 if (useSchema != nullptr) {
50 if (static_cast<const Providers::IProvider*> (schema.GetRep ()->GetProvider ()) != &saxProvider) {
51 WeakAssertNotReached (); // not necessarily a bug, but if this is done regularly, fix so they match
52 useSchema = useSchema.As<Schema::Ptr> (
53 *dynamic_cast<const Providers::ISchemaProvider*> (static_cast<const Providers::IProvider*> (&saxProvider)));
54 }
55 }
56 if (progress == nullptr) {
57 saxProvider.SAXParse (in, callback, useSchema);
58 }
59 else {
60 // IF progress provided, wrap 'in' in magic to handle progress
61 saxProvider.SAXParse (Execution::MakeInputStreamWithProgress (in, progress), callback, useSchema);
62 }
63}
#define WeakAssertNotReached()
Definition Assertions.h:467
void SAXParse(const Providers::ISAXProvider &saxProvider, const Streams::InputStream::Ptr< byte > &in, StructuredStreamEvents::IConsumer *callback=nullptr, const Schema::Ptr &schema=nullptr, Execution::ProgressMonitor::Updater progress=nullptr)
Definition SAXReader.cpp:45
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
Streams::InputStream::Ptr< T > MakeInputStreamWithProgress(const Streams::InputStream::Ptr< T > &in, ProgressMonitor::Updater progress)