diff --git a/CMakeLists.txt b/CMakeLists.txt index e8114fb..172fa18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,35 +12,50 @@ # See the License for the specific language governing permissions and # limitations under the License.cmake_minimum_required (VERSION 3.1) -cmake_minimum_required (VERSION 3.1) + +cmake_minimum_required(VERSION 3.2) set(PROJECT_NAME libCellML) project(${PROJECT_NAME} CXX) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(common) + # Use the following variables when configuring the build from the command line to # set the corresponding cache variables. # TESTS ==> LIBCELLML_TESTS -set( LIBCELLML_TESTS OFF CACHE BOOL "Enable build of automated LibCellML tests." ) +set(_PARAM_ANNOTATION "Enable build of automated LibCellML tests.") +set( LIBCELLML_TESTS OFF CACHE BOOL ${_PARAM_ANNOTATION} ) if( TESTS ) - set( LIBCELLML_TESTS "${TESTS}" CACHE BOOL "Enable build of automated LibCellML tests." FORCE ) + set( LIBCELLML_TESTS "${TESTS}" CACHE BOOL ${_PARAM_ANNOTATION} FORCE ) +endif() + +# WARNINGS_TREATED_AS_ERRORS ==> LIBCELLML_WARNINGS_TREATED_AS_ERRORS -- Note: This excludes third party code, where warnings are never treated as errors. +set(_PARAM_ANNOTATION "Treat warnings as errors (note: warnings in 3rd party code are never treated as errors)") +set( LIBCELLML_WARNINGS_TREATED_AS_ERRORS OFF CACHE BOOL ${_PARAM_ANNOTATION} ) +if( WARNINGS_TREATED_AS_ERRORS ) + set( LIBCELLML_WARNINGS_TREATED_AS_ERRORS "${WARNINGS_TREATED_AS_ERRORS}" CACHE BOOL ${_PARAM_ANNOTATION} FORCE ) endif() # BUILD_TYPE ==> LIBCELLML_BUILD_TYPE -set( LIBCELLML_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." ) +set(_PARAM_ANNOTATION "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") +set( LIBCELLML_BUILD_TYPE "Release" CACHE STRING ${_PARAM_ANNOTATION} ) if( BUILD_TYPE ) - set( LIBCELLML_BUILD_TYPE ${BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE ) + set( LIBCELLML_BUILD_TYPE ${BUILD_TYPE} CACHE STRING ${_PARAM_ANNOTATION} FORCE ) endif() # INSTALL_PREFIX ==> LIBCELLML_INSTALL_PREFIX -set( LIBCELLML_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "Install path prefix, prepended onto install directories." ) +set(_PARAM_ANNOTATION "Install path prefix, prepended onto install directories.") +set( LIBCELLML_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING ${_PARAM_ANNOTATION} ) if( INSTALL_PREFIX ) - set( LIBCELLML_INSTALL_PREFIX ${INSTALL_PREFIX} CACHE STRING "Install path prefix, prepended onto install directories." FORCE ) + set( LIBCELLML_INSTALL_PREFIX ${INSTALL_PREFIX} CACHE STRING ${_PARAM_ANNOTATION} FORCE ) endif() # BUILD_SHARED ==> LIBCELLML_BUILD_SHARED -set( LIBCELLML_BUILD_SHARED OFF CACHE BOOL "Build shared libraries (so, dylib, DLLs)." ) +set(_PARAM_ANNOTATION "Build shared libraries (so, dylib, DLLs).") +set( LIBCELLML_BUILD_SHARED OFF CACHE BOOL ${_PARAM_ANNOTATION} ) if( BUILD_SHARED ) - set( LIBCELLML_BUILD_SHARED ${BUILD_SHARED} CACHE BOOL "Build shared libraries (so, dylib, DLLs)." FORCE ) + set( LIBCELLML_BUILD_SHARED ${BUILD_SHARED} CACHE BOOL ${_PARAM_ANNOTATION} FORCE ) endif() # internalise some CMake variables diff --git a/cmake/common.cmake b/cmake/common.cmake new file mode 100644 index 0000000..f773f10 --- /dev/null +++ b/cmake/common.cmake @@ -0,0 +1,31 @@ +# Copyright 2015 University of Auckland +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.cmake_minimum_required (VERSION 3.1) + +function(TARGET_WARNINGS_AS_ERRORS _TARGET) + set(_COMPILER_WAE) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(_COMPILER_WAE -Wall -W -Werror) + endif() + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + set(_COMPILER_WAE -Wall -W -Werror) + endif() + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + set(_COMPILER_WAE /W3) + endif() + if(_COMPILER_WAE) + target_compile_options(${_TARGET} PRIVATE ${_COMPILER_WAE}) + endif() + unset(_COMPILER_WAE) +endfunction() + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e30d819..7f5ac6b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,20 +12,25 @@ # See the License for the specific language governing permissions and # limitations under the License.cmake_minimum_required (VERSION 3.1) - set(CELLML_EXPORT_H "${CMAKE_CURRENT_BINARY_DIR}/api/libcellml/libcellml_export.h") set(LIBCELLML_CONFIG_H "${CMAKE_CURRENT_BINARY_DIR}/libcellml_config.h") -configure_file ( +configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/libcellml_config.h.in" ${LIBCELLML_CONFIG_H} ) set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/model.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/xml_serialisation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cellml_1_2.cpp ) set(API_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/version.h + ${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/model.h + ${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/xml_serialisation.h + ${CMAKE_CURRENT_SOURCE_DIR}/cellml_1_2.h ${CELLML_EXPORT_H} ) @@ -33,29 +38,49 @@ set(HEADER_FILES ${LIBCELLML_CONFIG_H} ) -include_directories( - ${CMAKE_CURRENT_BINARY_DIR}/api - ${CMAKE_CURRENT_SOURCE_DIR}/api - ${CMAKE_CURRENT_BINARY_DIR} -) - include(GenerateExportHeader) - add_compiler_export_flags() + add_library(cellml ${SOURCE_FILES} ${HEADER_FILES} ${API_HEADER_FILES} ) -generate_export_header(cellml EXPORT_FILE_NAME ${CELLML_EXPORT_H} BASE_NAME LIBCELLML) -set_source_files_properties(${CELLML_EXPORT_H} PROPERTIES GENERATED TRUE) +target_include_directories(cellml PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/api + ${CMAKE_CURRENT_SOURCE_DIR}/api + ${CMAKE_CURRENT_SOURCE_DIR}/../extdep/libxsd + ${CMAKE_CURRENT_BINARY_DIR} +) -# To work around a bug conditionally set the CXX_STANDARD property -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - set_target_properties(cellml PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) +if(LIBCELLML_WARNINGS_TREATED_AS_ERRORS) + target_warnings_as_errors(cellml) endif() +generate_export_header(cellml EXPORT_FILE_NAME ${CELLML_EXPORT_H} BASE_NAME LIBCELLML) + +set(XercesC_ROOT "${XercesC_ROOT}" CACHE PATH "Location of Xerces-C") +set(BOOST_ROOT "${BOOST_ROOT}" CACHE PATH "Location of Boost") + +set(CMAKE_INCLUDE_PATH "${XercesC_ROOT}/include") +set(CMAKE_LIBRARY_PATH "${XercesC_ROOT}/lib") +find_package (XercesC) +if (XercesC_FOUND) + target_include_directories(cellml PRIVATE ${XercesC_INCLUDE_DIR}) + target_link_libraries (cellml ${XercesC_LIBRARY}) +endif (XercesC_FOUND) + + +find_package (Boost) +if (Boost_FOUND) + target_include_directories(cellml PRIVATE ${Boost_INCLUDE_DIRS}) + target_link_libraries (cellml ${Boost_LIBRARIES}) +endif (Boost_FOUND) + + +set_source_files_properties(${CELLML_EXPORT_H} PROPERTIES GENERATED TRUE) + export(TARGETS cellml FILE libcellml-exports.cmake) install(TARGETS cellml EXPORT libcellml-targets @@ -71,3 +96,4 @@ install(FILES install(EXPORT libcellml-targets DESTINATION lib/cmake) +set_target_properties(cellml PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) diff --git a/src/api/libcellml/model.h b/src/api/libcellml/model.h new file mode 100644 index 0000000..a53a9e1 --- /dev/null +++ b/src/api/libcellml/model.h @@ -0,0 +1,56 @@ +/* +Copyright 2015 University of Auckland + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.Some license of other +*/ + +#ifndef LIBCELLML_LIBCELLML_MODEL_H_ +#define LIBCELLML_LIBCELLML_MODEL_H_ + +#include +#include + +#include "libcellml/libcellml_export.h" + +//! Everything in LibCellML is in this namespace. +namespace libcellml { + +//! In-memory representation of a CellML model. +class LIBCELLML_EXPORT Model { + //! Model name + boost::optional name_; + + public: + /** + * Default constructor. + */ + Model(); + + /** + * Constructor + * \param name The model name + */ + Model(const boost::optional name); + + /** Model name attribute + * \return Model name + */ + boost::optional< std::wstring> getName() const { + return name_; + } + +}; + +} // namespace libcellml + +#endif // LIBCELLML_LIBCELLML_MODEL_H_ diff --git a/src/api/libcellml/version.h b/src/api/libcellml/version.h index 6393747..d1fb06a 100644 --- a/src/api/libcellml/version.h +++ b/src/api/libcellml/version.h @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License.Some license of other */ -#ifndef LIBCELLML_VERSION_H -#define LIBCELLML_VERSION_H +#ifndef LIBCELLML_LIBCELLML_VERSION_H_ +#define LIBCELLML_LIBCELLML_VERSION_H_ #include @@ -28,10 +28,10 @@ namespace libcellml { * Get the version string. * The version string is in the format x.y.z, where the "."s are literal, and x,y and z represent counting numbers, * in which case x is the major version, y the minor version, and z the patch level. - * @return a string to represent the version + * @return a string to represent the version. */ LIBCELLML_EXPORT const std::string getVersion(); -} // namespace libcellml +} // namespace libcellml -#endif /* LIBCELLML_VERSION_H */ +#endif // LIBCELLML_LIBCELLML_VERSION_H_ diff --git a/src/api/libcellml/xml_serialisation.h b/src/api/libcellml/xml_serialisation.h new file mode 100644 index 0000000..5fc8971 --- /dev/null +++ b/src/api/libcellml/xml_serialisation.h @@ -0,0 +1,36 @@ +/* +Copyright 2015 University of Auckland + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.Some license of other +*/ + +#ifndef LIBCELLML_LIBCELLML_XML_SERIALISATION_H_ +#define LIBCELLML_LIBCELLML_XML_SERIALISATION_H_ + +#include "model.h" +#include "libcellml/libcellml_export.h" + +#include + +namespace libcellml { + +/** + Serialise the Model. + \param model The model to be serialised. + \return XML representation. + */ +std::string LIBCELLML_EXPORT createXml(const Model& model); + +} + +#endif // LIBCELLML_LIBCELLML_XML_SERIALISATION_H_ diff --git a/src/cellml_1_2.cpp b/src/cellml_1_2.cpp new file mode 100644 index 0000000..323a910 --- /dev/null +++ b/src/cellml_1_2.cpp @@ -0,0 +1,707 @@ +// Copyright (c) 2005-2014 Code Synthesis Tools CC +// +// This program was generated by CodeSynthesis XSD, an XML Schema to +// C++ data binding compiler. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// +// In addition, as a special exception, Code Synthesis Tools CC gives +// permission to link this program with the Xerces-C++ library (or with +// modified versions of Xerces-C++ that use the same license as Xerces-C++), +// and distribute linked combinations including the two. You must obey +// the GNU General Public License version 2 in all respects for all of +// the code used other than Xerces-C++. If you modify this copy of the +// program, you may extend this exception to your version of the program, +// but you are not obligated to do so. If you do not wish to do so, delete +// this exception statement from your version. +// +// Furthermore, Code Synthesis Tools CC makes a special exception for +// the Free/Libre and Open Source Software (FLOSS) which is described +// in the accompanying FLOSSE file. +// + +// Begin prologue. +// +// +// End prologue. + +#include "cellml_1_2.h" + +#include + + +namespace cellml12 +{ + // Model + // + + const Model::NameOptional& Model:: + getName () const + { + return this->name_; + } + + Model::NameOptional& Model:: + getName () + { + return this->name_; + } + + void Model:: + setName (const NameType& x) + { + this->name_.set (x); + } + + void Model:: + setName (const NameOptional& x) + { + this->name_ = x; + } + + void Model:: + setName (::std::unique_ptr< NameType > x) + { + this->name_.set (std::move (x)); + } + + + // CellMLIdentifier + // +} + +#include + +namespace cellml12 +{ + // Model + // + + Model:: + Model () + : ::xml_schema::Type (), + name_ (this) + { + } + + Model:: + Model (const Model& x, + ::xml_schema::Flags f, + ::xml_schema::Container* c) + : ::xml_schema::Type (x, f, c), + name_ (x.name_, f, this) + { + } + + Model:: + Model (const ::xercesc::DOMElement& e, + ::xml_schema::Flags f, + ::xml_schema::Container* c) + : ::xml_schema::Type (e, f | ::xml_schema::Flags::base, c), + name_ (this) + { + if ((f & ::xml_schema::Flags::base) == 0) + { + ::xsd::cxx::xml::dom::parser< wchar_t > p (e, false, false, true); + this->parse (p, f); + } + } + + void Model:: + parse (::xsd::cxx::xml::dom::parser< wchar_t >& p, + ::xml_schema::Flags f) + { + while (p.more_attributes ()) + { + const ::xercesc::DOMAttr& i (p.next_attribute ()); + const ::xsd::cxx::xml::qualified_name< wchar_t > n ( + ::xsd::cxx::xml::dom::name< wchar_t > (i)); + + if (n.name () == L"name" && n.namespace_ ().empty ()) + { + this->name_.set (NameTraits::create (i, f, this)); + continue; + } + } + } + + Model* Model:: + _clone (::xml_schema::Flags f, + ::xml_schema::Container* c) const + { + return new class Model (*this, f, c); + } + + Model& Model:: + operator= (const Model& x) + { + if (this != &x) + { + static_cast< ::xml_schema::Type& > (*this) = x; + this->name_ = x.name_; + } + + return *this; + } + + Model:: + ~Model () + { + } + + // CellMLIdentifier + // + + CellMLIdentifier:: + CellMLIdentifier () + : ::xml_schema::String () + { + } + + CellMLIdentifier:: + CellMLIdentifier (const wchar_t* _xsd_String_base) + : ::xml_schema::String (_xsd_String_base) + { + } + + CellMLIdentifier:: + CellMLIdentifier (const ::std::wstring& _xsd_String_base) + : ::xml_schema::String (_xsd_String_base) + { + } + + CellMLIdentifier:: + CellMLIdentifier (const ::xml_schema::String& _xsd_String_base) + : ::xml_schema::String (_xsd_String_base) + { + } + + CellMLIdentifier:: + CellMLIdentifier (const CellMLIdentifier& x, + ::xml_schema::Flags f, + ::xml_schema::Container* c) + : ::xml_schema::String (x, f, c) + { + } + + CellMLIdentifier:: + CellMLIdentifier (const ::xercesc::DOMElement& e, + ::xml_schema::Flags f, + ::xml_schema::Container* c) + : ::xml_schema::String (e, f, c) + { + } + + CellMLIdentifier:: + CellMLIdentifier (const ::xercesc::DOMAttr& a, + ::xml_schema::Flags f, + ::xml_schema::Container* c) + : ::xml_schema::String (a, f, c) + { + } + + CellMLIdentifier:: + CellMLIdentifier (const ::std::wstring& s, + const ::xercesc::DOMElement* e, + ::xml_schema::Flags f, + ::xml_schema::Container* c) + : ::xml_schema::String (s, e, f, c) + { + } + + CellMLIdentifier* CellMLIdentifier:: + _clone (::xml_schema::Flags f, + ::xml_schema::Container* c) const + { + return new class CellMLIdentifier (*this, f, c); + } + + CellMLIdentifier:: + ~CellMLIdentifier () + { + } +} + +#include +#include +#include + +namespace cellml12 +{ + ::std::unique_ptr< ::cellml12::Model > + parseModel (const ::std::wstring& u, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xsd::cxx::xml::auto_initializer i ( + (f & ::xml_schema::Flags::dont_initialize) == 0, + (f & ::xml_schema::Flags::keep_dom) == 0); + + ::xsd::cxx::tree::error_handler< wchar_t > h; + + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::xsd::cxx::xml::dom::parse< wchar_t > ( + u, h, p, f)); + + h.throw_if_failed< ::xsd::cxx::tree::parsing< wchar_t > > (); + + return ::std::unique_ptr< ::cellml12::Model > ( + ::cellml12::parseModel ( + std::move (d), f | ::xml_schema::Flags::own_dom, p)); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (const ::std::wstring& u, + ::xml_schema::ErrorHandler& h, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xsd::cxx::xml::auto_initializer i ( + (f & ::xml_schema::Flags::dont_initialize) == 0, + (f & ::xml_schema::Flags::keep_dom) == 0); + + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::xsd::cxx::xml::dom::parse< wchar_t > ( + u, h, p, f)); + + if (!d.get ()) + throw ::xsd::cxx::tree::parsing< wchar_t > (); + + return ::std::unique_ptr< ::cellml12::Model > ( + ::cellml12::parseModel ( + std::move (d), f | ::xml_schema::Flags::own_dom, p)); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (const ::std::wstring& u, + ::xercesc::DOMErrorHandler& h, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::xsd::cxx::xml::dom::parse< wchar_t > ( + u, h, p, f)); + + if (!d.get ()) + throw ::xsd::cxx::tree::parsing< wchar_t > (); + + return ::std::unique_ptr< ::cellml12::Model > ( + ::cellml12::parseModel ( + std::move (d), f | ::xml_schema::Flags::own_dom, p)); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xsd::cxx::xml::auto_initializer i ( + (f & ::xml_schema::Flags::dont_initialize) == 0, + (f & ::xml_schema::Flags::keep_dom) == 0); + + ::xsd::cxx::xml::sax::std_input_source isrc (is); + return ::cellml12::parseModel (isrc, f, p); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + ::xml_schema::ErrorHandler& h, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xsd::cxx::xml::auto_initializer i ( + (f & ::xml_schema::Flags::dont_initialize) == 0, + (f & ::xml_schema::Flags::keep_dom) == 0); + + ::xsd::cxx::xml::sax::std_input_source isrc (is); + return ::cellml12::parseModel (isrc, h, f, p); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + ::xercesc::DOMErrorHandler& h, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xsd::cxx::xml::sax::std_input_source isrc (is); + return ::cellml12::parseModel (isrc, h, f, p); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + const ::std::wstring& sid, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xsd::cxx::xml::auto_initializer i ( + (f & ::xml_schema::Flags::dont_initialize) == 0, + (f & ::xml_schema::Flags::keep_dom) == 0); + + ::xsd::cxx::xml::sax::std_input_source isrc (is, sid); + return ::cellml12::parseModel (isrc, f, p); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + const ::std::wstring& sid, + ::xml_schema::ErrorHandler& h, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xsd::cxx::xml::auto_initializer i ( + (f & ::xml_schema::Flags::dont_initialize) == 0, + (f & ::xml_schema::Flags::keep_dom) == 0); + + ::xsd::cxx::xml::sax::std_input_source isrc (is, sid); + return ::cellml12::parseModel (isrc, h, f, p); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + const ::std::wstring& sid, + ::xercesc::DOMErrorHandler& h, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xsd::cxx::xml::sax::std_input_source isrc (is, sid); + return ::cellml12::parseModel (isrc, h, f, p); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (::xercesc::InputSource& i, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xsd::cxx::tree::error_handler< wchar_t > h; + + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::xsd::cxx::xml::dom::parse< wchar_t > ( + i, h, p, f)); + + h.throw_if_failed< ::xsd::cxx::tree::parsing< wchar_t > > (); + + return ::std::unique_ptr< ::cellml12::Model > ( + ::cellml12::parseModel ( + std::move (d), f | ::xml_schema::Flags::own_dom, p)); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (::xercesc::InputSource& i, + ::xml_schema::ErrorHandler& h, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::xsd::cxx::xml::dom::parse< wchar_t > ( + i, h, p, f)); + + if (!d.get ()) + throw ::xsd::cxx::tree::parsing< wchar_t > (); + + return ::std::unique_ptr< ::cellml12::Model > ( + ::cellml12::parseModel ( + std::move (d), f | ::xml_schema::Flags::own_dom, p)); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (::xercesc::InputSource& i, + ::xercesc::DOMErrorHandler& h, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::xsd::cxx::xml::dom::parse< wchar_t > ( + i, h, p, f)); + + if (!d.get ()) + throw ::xsd::cxx::tree::parsing< wchar_t > (); + + return ::std::unique_ptr< ::cellml12::Model > ( + ::cellml12::parseModel ( + std::move (d), f | ::xml_schema::Flags::own_dom, p)); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (const ::xercesc::DOMDocument& doc, + ::xml_schema::Flags f, + const ::xml_schema::Properties& p) + { + if (f & ::xml_schema::Flags::keep_dom) + { + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + static_cast< ::xercesc::DOMDocument* > (doc.cloneNode (true))); + + return ::std::unique_ptr< ::cellml12::Model > ( + ::cellml12::parseModel ( + std::move (d), f | ::xml_schema::Flags::own_dom, p)); + } + + const ::xercesc::DOMElement& e (*doc.getDocumentElement ()); + const ::xsd::cxx::xml::qualified_name< wchar_t > n ( + ::xsd::cxx::xml::dom::name< wchar_t > (e)); + + if (n.name () == L"model" && + n.namespace_ () == L"http://www.cellml.org/cellml/1.2#") + { + ::std::unique_ptr< ::cellml12::Model > r ( + ::xsd::cxx::tree::traits< ::cellml12::Model, wchar_t >::create ( + e, f, 0)); + return r; + } + + throw ::xsd::cxx::tree::unexpected_element < wchar_t > ( + n.name (), + n.namespace_ (), + L"model", + L"http://www.cellml.org/cellml/1.2#"); + } + + ::std::unique_ptr< ::cellml12::Model > + parseModel (::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d, + ::xml_schema::Flags f, + const ::xml_schema::Properties&) + { + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > c ( + ((f & ::xml_schema::Flags::keep_dom) && + !(f & ::xml_schema::Flags::own_dom)) + ? static_cast< ::xercesc::DOMDocument* > (d->cloneNode (true)) + : 0); + + ::xercesc::DOMDocument& doc (c.get () ? *c : *d); + const ::xercesc::DOMElement& e (*doc.getDocumentElement ()); + + const ::xsd::cxx::xml::qualified_name< wchar_t > n ( + ::xsd::cxx::xml::dom::name< wchar_t > (e)); + + if (f & ::xml_schema::Flags::keep_dom) + doc.setUserData (::xml_schema::dom::treeNodeKey, + (c.get () ? &c : &d), + 0); + + if (n.name () == L"model" && + n.namespace_ () == L"http://www.cellml.org/cellml/1.2#") + { + ::std::unique_ptr< ::cellml12::Model > r ( + ::xsd::cxx::tree::traits< ::cellml12::Model, wchar_t >::create ( + e, f, 0)); + return r; + } + + throw ::xsd::cxx::tree::unexpected_element < wchar_t > ( + n.name (), + n.namespace_ (), + L"model", + L"http://www.cellml.org/cellml/1.2#"); + } +} + +#include +#include +#include + +namespace cellml12 +{ + void + serializeModel (::std::ostream& o, + const ::cellml12::Model& s, + const ::xml_schema::NamespaceInfomap& m, + const ::std::wstring& e, + ::xml_schema::Flags f) + { + ::xsd::cxx::xml::auto_initializer i ( + (f & ::xml_schema::Flags::dont_initialize) == 0); + + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::cellml12::serializeModel (s, m, f)); + + ::xsd::cxx::tree::error_handler< wchar_t > h; + + ::xsd::cxx::xml::dom::ostream_format_target t (o); + if (!::xsd::cxx::xml::dom::serialize (t, *d, e, h, f)) + { + h.throw_if_failed< ::xsd::cxx::tree::serialization< wchar_t > > (); + } + } + + void + serializeModel (::std::ostream& o, + const ::cellml12::Model& s, + ::xml_schema::ErrorHandler& h, + const ::xml_schema::NamespaceInfomap& m, + const ::std::wstring& e, + ::xml_schema::Flags f) + { + ::xsd::cxx::xml::auto_initializer i ( + (f & ::xml_schema::Flags::dont_initialize) == 0); + + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::cellml12::serializeModel (s, m, f)); + ::xsd::cxx::xml::dom::ostream_format_target t (o); + if (!::xsd::cxx::xml::dom::serialize (t, *d, e, h, f)) + { + throw ::xsd::cxx::tree::serialization< wchar_t > (); + } + } + + void + serializeModel (::std::ostream& o, + const ::cellml12::Model& s, + ::xercesc::DOMErrorHandler& h, + const ::xml_schema::NamespaceInfomap& m, + const ::std::wstring& e, + ::xml_schema::Flags f) + { + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::cellml12::serializeModel (s, m, f)); + ::xsd::cxx::xml::dom::ostream_format_target t (o); + if (!::xsd::cxx::xml::dom::serialize (t, *d, e, h, f)) + { + throw ::xsd::cxx::tree::serialization< wchar_t > (); + } + } + + void + serializeModel (::xercesc::XMLFormatTarget& t, + const ::cellml12::Model& s, + const ::xml_schema::NamespaceInfomap& m, + const ::std::wstring& e, + ::xml_schema::Flags f) + { + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::cellml12::serializeModel (s, m, f)); + + ::xsd::cxx::tree::error_handler< wchar_t > h; + + if (!::xsd::cxx::xml::dom::serialize (t, *d, e, h, f)) + { + h.throw_if_failed< ::xsd::cxx::tree::serialization< wchar_t > > (); + } + } + + void + serializeModel (::xercesc::XMLFormatTarget& t, + const ::cellml12::Model& s, + ::xml_schema::ErrorHandler& h, + const ::xml_schema::NamespaceInfomap& m, + const ::std::wstring& e, + ::xml_schema::Flags f) + { + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::cellml12::serializeModel (s, m, f)); + if (!::xsd::cxx::xml::dom::serialize (t, *d, e, h, f)) + { + throw ::xsd::cxx::tree::serialization< wchar_t > (); + } + } + + void + serializeModel (::xercesc::XMLFormatTarget& t, + const ::cellml12::Model& s, + ::xercesc::DOMErrorHandler& h, + const ::xml_schema::NamespaceInfomap& m, + const ::std::wstring& e, + ::xml_schema::Flags f) + { + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::cellml12::serializeModel (s, m, f)); + if (!::xsd::cxx::xml::dom::serialize (t, *d, e, h, f)) + { + throw ::xsd::cxx::tree::serialization< wchar_t > (); + } + } + + void + serializeModel (::xercesc::DOMDocument& d, + const ::cellml12::Model& s, + ::xml_schema::Flags) + { + ::xercesc::DOMElement& e (*d.getDocumentElement ()); + const ::xsd::cxx::xml::qualified_name< wchar_t > n ( + ::xsd::cxx::xml::dom::name< wchar_t > (e)); + + if (n.name () == L"model" && + n.namespace_ () == L"http://www.cellml.org/cellml/1.2#") + { + e << s; + } + else + { + throw ::xsd::cxx::tree::unexpected_element < wchar_t > ( + n.name (), + n.namespace_ (), + L"model", + L"http://www.cellml.org/cellml/1.2#"); + } + } + + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > + serializeModel (const ::cellml12::Model& s, + const ::xml_schema::NamespaceInfomap& m, + ::xml_schema::Flags f) + { + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d ( + ::xsd::cxx::xml::dom::serialize< wchar_t > ( + L"model", + L"http://www.cellml.org/cellml/1.2#", + m, f)); + + ::cellml12::serializeModel (*d, s, f); + return d; + } + + void + operator<< (::xercesc::DOMElement& e, const Model& i) + { + e << static_cast< const ::xml_schema::Type& > (i); + + // name + // + if (i.getName ()) + { + ::xercesc::DOMAttr& a ( + ::xsd::cxx::xml::dom::create_attribute ( + L"name", + e)); + + a << *i.getName (); + } + } + + void + operator<< (::xercesc::DOMElement& e, const CellMLIdentifier& i) + { + e << static_cast< const ::xml_schema::String& > (i); + } + + void + operator<< (::xercesc::DOMAttr& a, const CellMLIdentifier& i) + { + a << static_cast< const ::xml_schema::String& > (i); + } + + void + operator<< (::xml_schema::ListStream& l, + const CellMLIdentifier& i) + { + l << static_cast< const ::xml_schema::String& > (i); + } +} + +#include + +// Begin epilogue. +// +// +// End epilogue. + diff --git a/src/cellml_1_2.h b/src/cellml_1_2.h new file mode 100644 index 0000000..f8270bd --- /dev/null +++ b/src/cellml_1_2.h @@ -0,0 +1,1376 @@ +// Copyright (c) 2005-2014 Code Synthesis Tools CC +// +// This program was generated by CodeSynthesis XSD, an XML Schema to +// C++ data binding compiler. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// +// In addition, as a special exception, Code Synthesis Tools CC gives +// permission to link this program with the Xerces-C++ library (or with +// modified versions of Xerces-C++ that use the same license as Xerces-C++), +// and distribute linked combinations including the two. You must obey +// the GNU General Public License version 2 in all respects for all of +// the code used other than Xerces-C++. If you modify this copy of the +// program, you may extend this exception to your version of the program, +// but you are not obligated to do so. If you do not wish to do so, delete +// this exception statement from your version. +// +// Furthermore, Code Synthesis Tools CC makes a special exception for +// the Free/Libre and Open Source Software (FLOSS) which is described +// in the accompanying FLOSSE file. +// +/** + * @file + * @brief Generated from cellml_1_2.xsd. + */ + +#ifndef CELLML_1_2_H +#define CELLML_1_2_H + +#ifndef XSD_CXX11 +#define XSD_CXX11 +#endif + +#ifndef XSD_USE_WCHAR +#define XSD_USE_WCHAR +#endif + +#ifndef XSD_CXX_TREE_USE_WCHAR +#define XSD_CXX_TREE_USE_WCHAR +#endif + +// Begin prologue. +// +// +// End prologue. + +#include + +#if (XSD_INT_VERSION != 4000000L) +#error XSD runtime version mismatch +#endif + +#include + +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * @brief C++ namespace for the %http://www.w3.org/2001/XMLSchema + * schema namespace. + */ +namespace xml_schema +{ + // anyType and anySimpleType. + // + + /** + * @brief C++ type corresponding to the anyType XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::type Type; + + /** + * @brief C++ type corresponding to the anySimpleType XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::simple_type< wchar_t, Type > SimpleType; + + /** + * @brief Alias for the anyType type. + */ + typedef ::xsd::cxx::tree::type Container; + + + // 8-bit + // + + /** + * @brief C++ type corresponding to the byte XML Schema + * built-in type. + */ + typedef signed char Byte; + + /** + * @brief C++ type corresponding to the unsignedByte XML Schema + * built-in type. + */ + typedef unsigned char UnsignedByte; + + + // 16-bit + // + + /** + * @brief C++ type corresponding to the short XML Schema + * built-in type. + */ + typedef short Short; + + /** + * @brief C++ type corresponding to the unsignedShort XML Schema + * built-in type. + */ + typedef unsigned short UnsignedShort; + + + // 32-bit + // + + /** + * @brief C++ type corresponding to the int XML Schema + * built-in type. + */ + typedef int Int; + + /** + * @brief C++ type corresponding to the unsignedInt XML Schema + * built-in type. + */ + typedef unsigned int UnsignedInt; + + + // 64-bit + // + + /** + * @brief C++ type corresponding to the long XML Schema + * built-in type. + */ + typedef long long Long; + + /** + * @brief C++ type corresponding to the unsignedLong XML Schema + * built-in type. + */ + typedef unsigned long long UnsignedLong; + + + // Supposed to be arbitrary-length integral types. + // + + /** + * @brief C++ type corresponding to the integer XML Schema + * built-in type. + */ + typedef long long Integer; + + /** + * @brief C++ type corresponding to the nonPositiveInteger XML Schema + * built-in type. + */ + typedef long long NonPositiveInteger; + + /** + * @brief C++ type corresponding to the nonNegativeInteger XML Schema + * built-in type. + */ + typedef unsigned long long NonNegativeInteger; + + /** + * @brief C++ type corresponding to the positiveInteger XML Schema + * built-in type. + */ + typedef unsigned long long PositiveInteger; + + /** + * @brief C++ type corresponding to the negativeInteger XML Schema + * built-in type. + */ + typedef long long NegativeInteger; + + + // Boolean. + // + + /** + * @brief C++ type corresponding to the boolean XML Schema + * built-in type. + */ + typedef bool Boolean; + + + // Floating-point types. + // + + /** + * @brief C++ type corresponding to the float XML Schema + * built-in type. + */ + typedef float Float; + + /** + * @brief C++ type corresponding to the double XML Schema + * built-in type. + */ + typedef double Double; + + /** + * @brief C++ type corresponding to the decimal XML Schema + * built-in type. + */ + typedef double Decimal; + + + // String types. + // + + /** + * @brief C++ type corresponding to the string XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::string< wchar_t, SimpleType > String; + + /** + * @brief C++ type corresponding to the normalizedString XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::normalized_string< wchar_t, String > NormalizedString; + + /** + * @brief C++ type corresponding to the token XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::token< wchar_t, NormalizedString > Token; + + /** + * @brief C++ type corresponding to the Name XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::name< wchar_t, Token > Name; + + /** + * @brief C++ type corresponding to the NMTOKEN XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::nmtoken< wchar_t, Token > Nmtoken; + + /** + * @brief C++ type corresponding to the NMTOKENS XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::nmtokens< wchar_t, SimpleType, Nmtoken > Nmtokens; + + /** + * @brief C++ type corresponding to the NCName XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::ncname< wchar_t, Name > Ncname; + + /** + * @brief C++ type corresponding to the language XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::language< wchar_t, Token > Language; + + + // ID/IDREF. + // + + /** + * @brief C++ type corresponding to the ID XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::id< wchar_t, Ncname > Id; + + /** + * @brief C++ type corresponding to the IDREF XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::idref< wchar_t, Ncname, Type > Idref; + + /** + * @brief C++ type corresponding to the IDREFS XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::idrefs< wchar_t, SimpleType, Idref > Idrefs; + + + // URI. + // + + /** + * @brief C++ type corresponding to the anyURI XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::uri< wchar_t, SimpleType > Uri; + + + // Qualified name. + // + + /** + * @brief C++ type corresponding to the QName XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::qname< wchar_t, SimpleType, Uri, Ncname > Qname; + + + // Binary. + // + + /** + * @brief Binary buffer type. + */ + typedef ::xsd::cxx::tree::buffer< wchar_t > Buffer; + + /** + * @brief C++ type corresponding to the base64Binary XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::base64_binary< wchar_t, SimpleType > Base64Binary; + + /** + * @brief C++ type corresponding to the hexBinary XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::hex_binary< wchar_t, SimpleType > HexBinary; + + + // Date/time. + // + + /** + * @brief Time zone type. + */ + typedef ::xsd::cxx::tree::time_zone TimeZone; + + /** + * @brief C++ type corresponding to the date XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::date< wchar_t, SimpleType > Date; + + /** + * @brief C++ type corresponding to the dateTime XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::date_time< wchar_t, SimpleType > DateTime; + + /** + * @brief C++ type corresponding to the duration XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::duration< wchar_t, SimpleType > Duration; + + /** + * @brief C++ type corresponding to the gDay XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::gday< wchar_t, SimpleType > Gday; + + /** + * @brief C++ type corresponding to the gMonth XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::gmonth< wchar_t, SimpleType > Gmonth; + + /** + * @brief C++ type corresponding to the gMonthDay XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::gmonth_day< wchar_t, SimpleType > GmonthDay; + + /** + * @brief C++ type corresponding to the gYear XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::gyear< wchar_t, SimpleType > Gyear; + + /** + * @brief C++ type corresponding to the gYearMonth XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::gyear_month< wchar_t, SimpleType > GyearMonth; + + /** + * @brief C++ type corresponding to the time XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::time< wchar_t, SimpleType > Time; + + + // Entity. + // + + /** + * @brief C++ type corresponding to the ENTITY XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::entity< wchar_t, Ncname > Entity; + + /** + * @brief C++ type corresponding to the ENTITIES XML Schema + * built-in type. + */ + typedef ::xsd::cxx::tree::entities< wchar_t, SimpleType, Entity > Entities; + + + + /** + * @brief Content order sequence entry. + */ + typedef ::xsd::cxx::tree::content_order ContentOrder; + // Namespace information and list stream. Used in + // serialization functions. + // + /** + * @brief Namespace serialization information. + */ + typedef ::xsd::cxx::xml::dom::namespace_info< wchar_t > NamespaceInfo; + + /** + * @brief Namespace serialization information map. + */ + typedef ::xsd::cxx::xml::dom::namespace_infomap< wchar_t > NamespaceInfomap; + + /** + * @brief List serialization stream. + */ + typedef ::xsd::cxx::tree::list_stream< wchar_t > ListStream; + + /** + * @brief Serialization wrapper for the %double type. + */ + typedef ::xsd::cxx::tree::as_double< Double > AsDouble; + + /** + * @brief Serialization wrapper for the %decimal type. + */ + typedef ::xsd::cxx::tree::as_decimal< Decimal > AsDecimal; + + /** + * @brief Simple type facet. + */ + typedef ::xsd::cxx::tree::facet Facet; + + // Flags and properties. + // + + /** + * @brief Parsing and serialization flags. + */ + typedef ::xsd::cxx::tree::flags Flags; + + /** + * @brief Parsing properties. + */ + typedef ::xsd::cxx::tree::properties< wchar_t > Properties; + + // Parsing/serialization diagnostics. + // + + /** + * @brief Error severity. + */ + typedef ::xsd::cxx::tree::severity Severity; + + /** + * @brief Error condition. + */ + typedef ::xsd::cxx::tree::error< wchar_t > Error; + + /** + * @brief List of %error conditions. + */ + typedef ::xsd::cxx::tree::diagnostics< wchar_t > Diagnostics; + + // Exceptions. + // + + /** + * @brief Root of the C++/Tree %exception hierarchy. + */ + typedef ::xsd::cxx::tree::exception< wchar_t > Exception; + + /** + * @brief Exception indicating that the size argument exceeds + * the capacity argument. + */ + typedef ::xsd::cxx::tree::bounds< wchar_t > Bounds; + + /** + * @brief Exception indicating that a duplicate ID value + * was encountered in the object model. + */ + typedef ::xsd::cxx::tree::duplicate_id< wchar_t > DuplicateId; + + /** + * @brief Exception indicating a parsing failure. + */ + typedef ::xsd::cxx::tree::parsing< wchar_t > Parsing; + + /** + * @brief Exception indicating that an expected element + * was not encountered. + */ + typedef ::xsd::cxx::tree::expected_element< wchar_t > ExpectedElement; + + /** + * @brief Exception indicating that an unexpected element + * was encountered. + */ + typedef ::xsd::cxx::tree::unexpected_element< wchar_t > UnexpectedElement; + + /** + * @brief Exception indicating that an expected attribute + * was not encountered. + */ + typedef ::xsd::cxx::tree::expected_attribute< wchar_t > ExpectedAttribute; + + /** + * @brief Exception indicating that an unexpected enumerator + * was encountered. + */ + typedef ::xsd::cxx::tree::unexpected_enumerator< wchar_t > UnexpectedEnumerator; + + /** + * @brief Exception indicating that the text content was + * expected for an element. + */ + typedef ::xsd::cxx::tree::expected_text_content< wchar_t > ExpectedTextContent; + + /** + * @brief Exception indicating that a prefix-namespace + * mapping was not provided. + */ + typedef ::xsd::cxx::tree::no_prefix_mapping< wchar_t > NoPrefixMapping; + + /** + * @brief Exception indicating a serialization failure. + */ + typedef ::xsd::cxx::tree::serialization< wchar_t > Serialization; + + /** + * @brief Error handler callback interface. + */ + typedef ::xsd::cxx::xml::error_handler< wchar_t > ErrorHandler; + + /** + * @brief DOM interaction. + */ + namespace dom + { + /** + * @brief Automatic pointer for DOMDocument. + */ + using ::xsd::cxx::xml::dom::unique_ptr; + +#ifndef XSD_CXX_TREE_TREE_NODE_KEY__XML_SCHEMA +#define XSD_CXX_TREE_TREE_NODE_KEY__XML_SCHEMA + /** + * @brief DOM user data key for back pointers to tree nodes. + */ + const XMLCh* const treeNodeKey = ::xsd::cxx::tree::user_data_keys::node; +#endif + } +} + +// Forward declarations. +// +namespace cellml12 +{ + class Model; + class CellMLIdentifier; +} + + +#include // ::std::unique_ptr +#include // std::numeric_limits +#include // std::binary_search +#include // std::move + +#include +#include +#include +#include + +#include + +/** + * @brief C++ namespace for the %http://www.cellml.org/cellml/1.2# + * schema namespace. + */ +namespace cellml12 +{ + /** + * @brief Class corresponding to the %model schema type. + * + * @nosubgrouping + */ + class Model: public ::xml_schema::Type + { + public: + /** + * @name name + * + * @brief Accessor and modifier functions for the %name + * optional attribute. + */ + //@{ + + /** + * @brief Attribute type. + */ + typedef ::cellml12::CellMLIdentifier NameType; + + /** + * @brief Attribute optional container type. + */ + typedef ::xsd::cxx::tree::optional< NameType > NameOptional; + + /** + * @brief Attribute traits type. + */ + typedef ::xsd::cxx::tree::traits< NameType, wchar_t > NameTraits; + + /** + * @brief Return a read-only (constant) reference to the attribute + * container. + * + * @return A constant reference to the optional container. + */ + const NameOptional& + getName () const; + + /** + * @brief Return a read-write reference to the attribute container. + * + * @return A reference to the optional container. + */ + NameOptional& + getName (); + + /** + * @brief Set the attribute value. + * + * @param x A new value to set. + * + * This function makes a copy of its argument and sets it as + * the new value of the attribute. + */ + void + setName (const NameType& x); + + /** + * @brief Set the attribute value. + * + * @param x An optional container with the new value to set. + * + * If the value is present in @a x then this function makes a copy + * of this value and sets it as the new value of the attribute. + * Otherwise the attribute container is set the 'not present' state. + */ + void + setName (const NameOptional& x); + + /** + * @brief Set the attribute value without copying. + * + * @param p A new value to use. + * + * This function will try to use the passed value directly instead + * of making a copy. + */ + void + setName (::std::unique_ptr< NameType > p); + + //@} + + /** + * @name Constructors + */ + //@{ + + /** + * @brief Create an instance from the ultimate base and + * initializers for required elements and attributes. + */ + Model (); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + Model (const ::xercesc::DOMElement& e, + ::xml_schema::Flags f = 0, + ::xml_schema::Container* c = 0); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + Model (const Model& x, + ::xml_schema::Flags f = 0, + ::xml_schema::Container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance is + * used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual Model* + _clone (::xml_schema::Flags f = 0, + ::xml_schema::Container* c = 0) const; + + /** + * @brief Copy assignment operator. + * + * @param x An instance to make a copy of. + * @return A reference to itself. + * + * For polymorphic object models use the @c _clone function instead. + */ + Model& + operator= (const Model& x); + + //@} + + /** + * @brief Destructor. + */ + virtual + ~Model (); + + // Implementation. + // + + //@cond + + protected: + void + parse (::xsd::cxx::xml::dom::parser< wchar_t >&, + ::xml_schema::Flags); + + protected: + NameOptional name_; + + //@endcond + }; + + /** + * @brief Class corresponding to the %cellMLIdentifier schema type. + * + * @nosubgrouping + */ + class CellMLIdentifier: public ::xml_schema::String + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Create an instance from initializers for required + * elements and attributes. + */ + CellMLIdentifier (); + + /** + * @brief Create an instance from a C string and initializers + * for required elements and attributes. + */ + CellMLIdentifier (const wchar_t*); + + /** + * @brief Create an instance from a string andinitializers + * for required elements and attributes. + */ + CellMLIdentifier (const ::std::wstring&); + + /** + * @brief Create an instance from the ultimate base and + * initializers for required elements and attributes. + */ + CellMLIdentifier (const ::xml_schema::String&); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + CellMLIdentifier (const ::xercesc::DOMElement& e, + ::xml_schema::Flags f = 0, + ::xml_schema::Container* c = 0); + + /** + * @brief Create an instance from a DOM attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + CellMLIdentifier (const ::xercesc::DOMAttr& a, + ::xml_schema::Flags f = 0, + ::xml_schema::Container* c = 0); + + /** + * @brief Create an instance from a string fragment. + * + * @param s A string fragment to extract the data from. + * @param e A pointer to DOM element containing the string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + CellMLIdentifier (const ::std::wstring& s, + const ::xercesc::DOMElement* e, + ::xml_schema::Flags f = 0, + ::xml_schema::Container* c = 0); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + CellMLIdentifier (const CellMLIdentifier& x, + ::xml_schema::Flags f = 0, + ::xml_schema::Container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance is + * used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual CellMLIdentifier* + _clone (::xml_schema::Flags f = 0, + ::xml_schema::Container* c = 0) const; + + //@} + + /** + * @brief Destructor. + */ + virtual + ~CellMLIdentifier (); + }; +} + +#include + +#include +#include +#include + +namespace cellml12 +{ + /** + * @name Parsing functions for the %model document root. + */ + //@{ + + /** + * @brief Parse a URI or a local file. + * + * @param uri A URI or a local file name. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * This function uses exceptions to report parsing errors. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (const ::std::wstring& uri, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a URI or a local file with an error handler. + * + * @param uri A URI or a local file name. + * @param eh An error handler. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * This function reports parsing errors by calling the error handler. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (const ::std::wstring& uri, + ::xml_schema::ErrorHandler& eh, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a URI or a local file with a Xerces-C++ DOM error + * handler. + * + * @param uri A URI or a local file name. + * @param eh A Xerces-C++ DOM error handler. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * This function reports parsing errors by calling the error handler. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (const ::std::wstring& uri, + ::xercesc::DOMErrorHandler& eh, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a standard input stream. + * + * @param is A standrad input stream. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * This function uses exceptions to report parsing errors. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a standard input stream with an error handler. + * + * @param is A standrad input stream. + * @param eh An error handler. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * This function reports parsing errors by calling the error handler. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + ::xml_schema::ErrorHandler& eh, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a standard input stream with a Xerces-C++ DOM error + * handler. + * + * @param is A standrad input stream. + * @param eh A Xerces-C++ DOM error handler. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * This function reports parsing errors by calling the error handler. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + ::xercesc::DOMErrorHandler& eh, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a standard input stream with a resource id. + * + * @param is A standrad input stream. + * @param id A resource id. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * The resource id is used to identify the document being parsed in + * diagnostics as well as to resolve relative paths. + * + * This function uses exceptions to report parsing errors. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + const ::std::wstring& id, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a standard input stream with a resource id and an + * error handler. + * + * @param is A standrad input stream. + * @param id A resource id. + * @param eh An error handler. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * The resource id is used to identify the document being parsed in + * diagnostics as well as to resolve relative paths. + * + * This function reports parsing errors by calling the error handler. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + const ::std::wstring& id, + ::xml_schema::ErrorHandler& eh, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a standard input stream with a resource id and a + * Xerces-C++ DOM error handler. + * + * @param is A standrad input stream. + * @param id A resource id. + * @param eh A Xerces-C++ DOM error handler. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * The resource id is used to identify the document being parsed in + * diagnostics as well as to resolve relative paths. + * + * This function reports parsing errors by calling the error handler. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (::std::istream& is, + const ::std::wstring& id, + ::xercesc::DOMErrorHandler& eh, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a Xerces-C++ input source. + * + * @param is A Xerces-C++ input source. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * This function uses exceptions to report parsing errors. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (::xercesc::InputSource& is, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a Xerces-C++ input source with an error handler. + * + * @param is A Xerces-C++ input source. + * @param eh An error handler. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * This function reports parsing errors by calling the error handler. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (::xercesc::InputSource& is, + ::xml_schema::ErrorHandler& eh, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a Xerces-C++ input source with a Xerces-C++ DOM + * error handler. + * + * @param is A Xerces-C++ input source. + * @param eh A Xerces-C++ DOM error handler. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * This function reports parsing errors by calling the error handler. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (::xercesc::InputSource& is, + ::xercesc::DOMErrorHandler& eh, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a Xerces-C++ DOM document. + * + * @param d A Xerces-C++ DOM document. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (const ::xercesc::DOMDocument& d, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + /** + * @brief Parse a Xerces-C++ DOM document. + * + * @param d A pointer to the Xerces-C++ DOM document. + * @param f Parsing flags. + * @param p Parsing properties. + * @return A pointer to the root of the object model. + * + * This function is normally used together with the keep_dom and + * own_dom parsing flags to assign ownership of the DOM document + * to the object model. + */ + ::std::unique_ptr< ::cellml12::Model > + parseModel (::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > d, + ::xml_schema::Flags f = 0, + const ::xml_schema::Properties& p = ::xml_schema::Properties ()); + + //@} +} + +#include + +#include +#include +#include + +#include + +namespace cellml12 +{ + /** + * @name Serialization functions for the %model document root. + */ + //@{ + + /** + * @brief Serialize to a standard output stream. + * + * @param os A standrad output stream. + * @param x An object model to serialize. + * @param m A namespace information map. + * @param e A character encoding to produce XML in. + * @param f Serialization flags. + * + * This function uses exceptions to report serialization errors. + */ + void + serializeModel (::std::ostream& os, + const ::cellml12::Model& x, + const ::xml_schema::NamespaceInfomap& m = ::xml_schema::NamespaceInfomap (), + const ::std::wstring& e = L"UTF-8", + ::xml_schema::Flags f = 0); + + /** + * @brief Serialize to a standard output stream with an error handler. + * + * @param os A standrad output stream. + * @param x An object model to serialize. + * @param eh An error handler. + * @param m A namespace information map. + * @param e A character encoding to produce XML in. + * @param f Serialization flags. + * + * This function reports serialization errors by calling the error + * handler. + */ + void + serializeModel (::std::ostream& os, + const ::cellml12::Model& x, + ::xml_schema::ErrorHandler& eh, + const ::xml_schema::NamespaceInfomap& m = ::xml_schema::NamespaceInfomap (), + const ::std::wstring& e = L"UTF-8", + ::xml_schema::Flags f = 0); + + /** + * @brief Serialize to a standard output stream with a Xerces-C++ DOM + * error handler. + * + * @param os A standrad output stream. + * @param x An object model to serialize. + * @param eh A Xerces-C++ DOM error handler. + * @param m A namespace information map. + * @param e A character encoding to produce XML in. + * @param f Serialization flags. + * + * This function reports serialization errors by calling the error + * handler. + */ + void + serializeModel (::std::ostream& os, + const ::cellml12::Model& x, + ::xercesc::DOMErrorHandler& eh, + const ::xml_schema::NamespaceInfomap& m = ::xml_schema::NamespaceInfomap (), + const ::std::wstring& e = L"UTF-8", + ::xml_schema::Flags f = 0); + + /** + * @brief Serialize to a Xerces-C++ XML format target. + * + * @param ft A Xerces-C++ XML format target. + * @param x An object model to serialize. + * @param m A namespace information map. + * @param e A character encoding to produce XML in. + * @param f Serialization flags. + * + * This function uses exceptions to report serialization errors. + */ + void + serializeModel (::xercesc::XMLFormatTarget& ft, + const ::cellml12::Model& x, + const ::xml_schema::NamespaceInfomap& m = ::xml_schema::NamespaceInfomap (), + const ::std::wstring& e = L"UTF-8", + ::xml_schema::Flags f = 0); + + /** + * @brief Serialize to a Xerces-C++ XML format target with an error + * handler. + * + * @param ft A Xerces-C++ XML format target. + * @param x An object model to serialize. + * @param eh An error handler. + * @param m A namespace information map. + * @param e A character encoding to produce XML in. + * @param f Serialization flags. + * + * This function reports serialization errors by calling the error + * handler. + */ + void + serializeModel (::xercesc::XMLFormatTarget& ft, + const ::cellml12::Model& x, + ::xml_schema::ErrorHandler& eh, + const ::xml_schema::NamespaceInfomap& m = ::xml_schema::NamespaceInfomap (), + const ::std::wstring& e = L"UTF-8", + ::xml_schema::Flags f = 0); + + /** + * @brief Serialize to a Xerces-C++ XML format target with a + * Xerces-C++ DOM error handler. + * + * @param ft A Xerces-C++ XML format target. + * @param x An object model to serialize. + * @param eh A Xerces-C++ DOM error handler. + * @param m A namespace information map. + * @param e A character encoding to produce XML in. + * @param f Serialization flags. + * + * This function reports serialization errors by calling the error + * handler. + */ + void + serializeModel (::xercesc::XMLFormatTarget& ft, + const ::cellml12::Model& x, + ::xercesc::DOMErrorHandler& eh, + const ::xml_schema::NamespaceInfomap& m = ::xml_schema::NamespaceInfomap (), + const ::std::wstring& e = L"UTF-8", + ::xml_schema::Flags f = 0); + + /** + * @brief Serialize to an existing Xerces-C++ DOM document. + * + * @param d A Xerces-C++ DOM document. + * @param x An object model to serialize. + * @param f Serialization flags. + * + * Note that it is your responsibility to create the DOM document + * with the correct root element as well as set the necessary + * namespace mapping attributes. + */ + void + serializeModel (::xercesc::DOMDocument& d, + const ::cellml12::Model& x, + ::xml_schema::Flags f = 0); + + /** + * @brief Serialize to a new Xerces-C++ DOM document. + * + * @param x An object model to serialize. + * @param m A namespace information map. + * @param f Serialization flags. + * @return A pointer to the new Xerces-C++ DOM document. + */ + ::xml_schema::dom::unique_ptr< ::xercesc::DOMDocument > + serializeModel (const ::cellml12::Model& x, + const ::xml_schema::NamespaceInfomap& m = ::xml_schema::NamespaceInfomap (), + ::xml_schema::Flags f = 0); + + //@} + + void + operator<< (::xercesc::DOMElement&, const Model&); + + void + operator<< (::xercesc::DOMElement&, const CellMLIdentifier&); + + void + operator<< (::xercesc::DOMAttr&, const CellMLIdentifier&); + + void + operator<< (::xml_schema::ListStream&, + const CellMLIdentifier&); +} + +#include + +// Begin epilogue. +// +// +// End epilogue. + +#endif // CELLML_1_2_H diff --git a/src/cellml_1_2.xsd b/src/cellml_1_2.xsd new file mode 100644 index 0000000..80b9fe5 --- /dev/null +++ b/src/cellml_1_2.xsd @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/generate.sh b/src/generate.sh new file mode 100755 index 0000000..89b43b1 --- /dev/null +++ b/src/generate.sh @@ -0,0 +1,2 @@ +./xsdcxx cxx-tree --options-file xsd-options.txt cellml_1_2.xsd + diff --git a/src/model.cpp b/src/model.cpp new file mode 100644 index 0000000..c921659 --- /dev/null +++ b/src/model.cpp @@ -0,0 +1,26 @@ +/* +Copyright 2015 University of Auckland + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.Some license of other +*/ + +#include "libcellml/model.h" + +#include + +libcellml::Model::Model() {} + +libcellml::Model::Model(const boost::optional name) +: + name_(name) +{} diff --git a/src/xml_serialisation.cpp b/src/xml_serialisation.cpp new file mode 100644 index 0000000..eb72e4c --- /dev/null +++ b/src/xml_serialisation.cpp @@ -0,0 +1,36 @@ +/* +Copyright 2015 University of Auckland + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.Some license of other +*/ + +#include "libcellml/xml_serialisation.h" +#include +#include +#include +#include + +#include "cellml_1_2.h" + +namespace libcellml { + +std::string createXml(const libcellml::Model& model) { + cellml12::Model modelXml; + if (model.getName()) modelXml.setName(*model.getName()); + + std::ostringstream oss; + cellml12::serializeModel(oss, modelXml); + return oss.str(); +} + +} // namespace libcellml diff --git a/src/xsd-options.txt b/src/xsd-options.txt new file mode 100644 index 0000000..392aaf2 --- /dev/null +++ b/src/xsd-options.txt @@ -0,0 +1,11 @@ +--location-map http://www.cellml.org/tools/cellml_1_1_schema/common/xlink-href.xsd=xlink-href.xsd +--location-map http://www.cellml.org/tools/cellml_1_1_schema/mathml2.xsd=mathml2/mathml2.xsd +--namespace-map http://www.cellml.org/cellml/1.2#=cellml12 +--std c++11 +--generate-serialization +--generate-doxygen +--type-naming java +--function-naming java +--char-type wchar_t +--hxx-suffix .h +--cxx-suffix .cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3d3e755..bef3033 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,20 +21,32 @@ include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR} "${PROJECT_S add_executable (libcellmlTest ${CMAKE_CURRENT_SOURCE_DIR}/version_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/xml_serialisation_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/model_test.cpp ${HEADER_FILES} ) +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/extdep/libxsd +) + # Standard linking to gtest stuff. target_link_libraries(libcellmlTest gtest gtest_main) +find_package (Boost) +if (Boost_FOUND) + target_include_directories(libcellmlTest PRIVATE ${Boost_INCLUDE_DIRS}) + target_link_libraries(libcellmlTest ${Boost_LIBRARIES}) +endif (Boost_FOUND) + +if(LIBCELLML_WARNINGS_TREATED_AS_ERRORS) + target_warnings_as_errors(libcellmlTest) +endif() + # Extra linking for the project. target_link_libraries(libcellmlTest cellml) # test executable. add_test(libcellmlTest libcellmlTest) -# To work around a bug conditionally set the CXX_STANDARD property -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - set_target_properties(libcellmlTest PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) -endif() - +set_target_properties(libcellmlTest PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) diff --git a/tests/model_test.cpp b/tests/model_test.cpp new file mode 100644 index 0000000..7081797 --- /dev/null +++ b/tests/model_test.cpp @@ -0,0 +1,10 @@ +#include "libcellml/model.h" + +#include "gtest/gtest.h" + +//! Test model has name specified during creation +TEST(Model, ModelWithValidName) { + boost::optional modelName{L"testModel"}; + libcellml::Model m1{modelName}; + ASSERT_EQ(*(m1.getName()), L"testModel"); +} diff --git a/tests/version_test.cpp b/tests/version_test.cpp index ad72495..25edbda 100644 --- a/tests/version_test.cpp +++ b/tests/version_test.cpp @@ -19,11 +19,9 @@ limitations under the License.Some license of other #include "gtest/gtest.h" -using namespace libcellml; - -//! IndependentMethod is a test case - here, we have 2 tests for this 1 test case +//! Test version number is as expected. TEST(Version, Version) { - auto ver = getVersion(); + auto ver = libcellml::getVersion(); EXPECT_EQ("0.1.0", ver); } diff --git a/tests/xml_serialisation_test.cpp b/tests/xml_serialisation_test.cpp new file mode 100644 index 0000000..6888475 --- /dev/null +++ b/tests/xml_serialisation_test.cpp @@ -0,0 +1,59 @@ +/* +Copyright 2015 University of Auckland + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.Some license of other +*/ + +#include +#include +#include + +#include "libcellml/model.h" +#include "libcellml/xml_serialisation.h" + +#include "gtest/gtest.h" + +//! Test serialisation to XML of empty model. +TEST(XmlSerialisation, EmptyNamelessModel) { + using Model = libcellml::Model; + using string = std::string; + + Model m1; + + const string xml = libcellml::createXml(m1); + + string expectedXml{ +R"( + +)"}; + + ASSERT_EQ(expectedXml, xml); +} + +//! Test serialisation to XML of model with a valid name (though no validation is actually done). +TEST(XmlSerialisation, EmptyValidlyNamedModel) { + using Model = libcellml::Model; + using string = std::string; + + boost::optional modelName{L"testModel"}; + Model m1{modelName}; + + const string xml = libcellml::createXml(m1); + + string expectedXml{ +R"( + +)"}; + + ASSERT_EQ(expectedXml, xml); +}