Serializer.h
1 /**************************************************************************************
2 Copyright 2015 Applied Research Associates, Inc.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the License
5 at:
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software distributed under
8 the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9 CONDITIONS OF ANY KIND, either express or implied. See the License for the
10 specific language governing permissions and limitations under the License.
11 **************************************************************************************/
12 
13 #pragma once
14 
15 #include <cstddef> // std::size_t
16 #include <iostream>
17 #include <memory> // std::auto_ptr
18 #include <string>
19 #include <memory>
20 
21 #include <xercesc/util/PlatformUtils.hpp>
22 #include <xercesc/util/XMLString.hpp>
23 #include <xercesc/util/XMLUni.hpp>
24 
25 #include <xercesc/dom/DOM.hpp>
26 
27 #include <xercesc/framework/XMLGrammarPoolImpl.hpp>
28 #include <xercesc/validators/common/Grammar.hpp>
29 
30 #include <biogears/cdm/CommonDataModel.h>
31 #include <biogears/exports.h>
32 
33 CDM_BIND_DECL(ObjectData)
34 namespace biogears {
35 class BIOGEARS_API Serializer {
36 public:
37  static void Destroy() { SAFE_DELETE(m_me); }
38  static std::unique_ptr<CDM::ObjectData> ReadFile(const char* xmlFile, Logger* logger);
39  static std::unique_ptr<CDM::ObjectData> ReadFile(const std::string& xmlFile, Logger* logger);
40 private:
41  Serializer();
42  virtual ~Serializer();
43 
44  bool Initialize(Logger* logger);
45  xercesc::DOMLSParser* CreateParser(Logger* logger) const;
46 
47  static Serializer* m_me;
48 
49  static bool m_Initialized;
50  static std::unique_ptr<xercesc::XMLGrammarPool> m_GrammerPool;
51 };
52 
53 class ErrorHandler : public xercesc::DOMErrorHandler {
54 public:
56  : failed_(false)
57  {
58  }
59 
60  bool failed() const;
61  const char* getError();
62 
63  virtual bool handleError(const xercesc::DOMError& err);
64 
65 private:
66  bool failed_;
67  std::stringstream error_;
68 };
69 }
bool failed_
Definition: Serializer.h:66
Definition: Serializer.h:35
Definition: Serializer.h:53
Definition: Logger.h:75
static bool m_Initialized
Definition: Serializer.h:49
static Serializer * m_me
Definition: Serializer.h:47
ErrorHandler()
Definition: Serializer.h:55
static std::unique_ptr< xercesc::XMLGrammarPool > m_GrammerPool
Definition: Serializer.h:50
std::stringstream error_
Definition: Serializer.h:67
Definition: SEElectricalCircuit.h:18
static void Destroy()
Definition: Serializer.h:37