From 45aaaa9c4c54e880d8955a40afb676f9c2d41d97 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Fri, 27 Mar 2015 16:08:41 +1300 Subject: [PATCH 01/30] Use case: Empty, nameless model. Test fail intended. Schema has been used to generate XML serialisation/ deserialisation code, based on Cellml_1_2.xsd. Notes: - CodeSynthesis XSD used as follows: ./generate.sh This creates Cellml_1_2.cpp and .h. - This approach of starting with an essentially blank schema document is not my preferred approach, but I was outvoted. My personal preference would have been to work incrementally, starting with the existing schema for CellML 1.1 and making only the changes that pertain to the differences between CellML 1.1 and the draft for CellML 1.2. A demonstration of that was done as shown here: https://github.com/codecurve/libcellml/blob/04de33845306a6468d389fd8a1be25e7405221e7/src/cellml_1_2.xsd as well as the commits that followed it. --- CMakeLists.txt | 3 +- src/CMakeLists.txt | 28 + src/Cellml_1_2.cpp | 531 ++++++++++++ src/Cellml_1_2.h | 1152 +++++++++++++++++++++++++ src/Cellml_1_2.xsd | 13 + src/api/libcellml/model.h | 36 + src/api/libcellml/version.h | 8 +- src/api/libcellml/xml_serialisation.h | 35 + src/generate.sh | 2 + src/model.cpp | 20 + src/xml_serialisation.cpp | 35 + src/xsd-options.txt | 11 + tests/CMakeLists.txt | 19 +- tests/version_test.cpp | 6 +- tests/xml_serialisation_test.cpp | 46 + 15 files changed, 1931 insertions(+), 14 deletions(-) create mode 100644 src/Cellml_1_2.cpp create mode 100644 src/Cellml_1_2.h create mode 100644 src/Cellml_1_2.xsd create mode 100644 src/api/libcellml/model.h create mode 100644 src/api/libcellml/xml_serialisation.h create mode 100755 src/generate.sh create mode 100644 src/model.cpp create mode 100644 src/xml_serialisation.cpp create mode 100644 src/xsd-options.txt create mode 100644 tests/xml_serialisation_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e8114fb..d319a41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,8 @@ # 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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e30d819..e9dda3e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,10 +22,16 @@ configure_file ( 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} ) @@ -36,6 +42,7 @@ set(HEADER_FILES include_directories( ${CMAKE_CURRENT_BINARY_DIR}/api ${CMAKE_CURRENT_SOURCE_DIR}/api + ${CMAKE_CURRENT_SOURCE_DIR}/../extdep/libxsd ${CMAKE_CURRENT_BINARY_DIR} ) @@ -49,6 +56,25 @@ add_library(cellml ) 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) + include_directories(${XercesC_INCLUDE_DIR}) + target_link_libraries (cellml ${XercesC_LIBRARY}) +endif (XercesC_FOUND) + + +find_package (Boost) +if (Boost_FOUND) + include_directories(${Boost_INCLUDE_DIRS}) + target_link_libraries (cellml ${Boost_LIBRARIES}) +endif (Boost_FOUND) + + set_source_files_properties(${CELLML_EXPORT_H} PROPERTIES GENERATED TRUE) # To work around a bug conditionally set the CXX_STANDARD property @@ -71,3 +97,5 @@ 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/Cellml_1_2.cpp b/src/Cellml_1_2.cpp new file mode 100644 index 0000000..6868a57 --- /dev/null +++ b/src/Cellml_1_2.cpp @@ -0,0 +1,531 @@ +// 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 + +#include "Cellml_1_2.h" + +namespace cellml12 +{ + // Model + // +} + +#include + +namespace cellml12 +{ + // Model + // + + Model:: + Model () + : ::xml_schema::Type () + { + } + + Model:: + Model (const Model& x, + ::xml_schema::Flags f, + ::xml_schema::Container* c) + : ::xml_schema::Type (x, f, c) + { + } + + Model:: + Model (const ::xercesc::DOMElement& e, + ::xml_schema::Flags f, + ::xml_schema::Container* c) + : ::xml_schema::Type (e, f, c) + { + } + + Model* Model:: + _clone (::xml_schema::Flags f, + ::xml_schema::Container* c) const + { + return new class Model (*this, f, c); + } + + Model:: + ~Model () + { + } +} + +#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); + } +} + +#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..e6ddba7 --- /dev/null +++ b/src/Cellml_1_2.h @@ -0,0 +1,1152 @@ +// 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; +} + + +#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 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 Destructor. + */ + virtual + ~Model (); + }; +} + +#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&); +} + +#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..df0646b --- /dev/null +++ b/src/Cellml_1_2.xsd @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/src/api/libcellml/model.h b/src/api/libcellml/model.h new file mode 100644 index 0000000..73ddab2 --- /dev/null +++ b/src/api/libcellml/model.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 SRC_API_LIBCELLML_MODEL_H_ +#define SRC_API_LIBCELLML_MODEL_H_ + +#include + +//! Everything in LibCellML is in this namespace. +namespace libcellml { + +//! In-memory representation of a CellML model +class Model { + public: + /** + * Default constructor + */ + Model(); +}; + +} // namespace libcellml + +#endif // SRC_API_LIBCELLML_MODEL_H_ diff --git a/src/api/libcellml/version.h b/src/api/libcellml/version.h index 6393747..85e3785 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 SRC_API_LIBCELLML_VERSION_H_ +#define SRC_API_LIBCELLML_VERSION_H_ #include @@ -32,6 +32,6 @@ namespace libcellml { */ LIBCELLML_EXPORT const std::string getVersion(); -} // namespace libcellml +} // namespace libcellml -#endif /* LIBCELLML_VERSION_H */ +#endif // SRC_API_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..871fb2a --- /dev/null +++ b/src/api/libcellml/xml_serialisation.h @@ -0,0 +1,35 @@ +/* +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 SRC_API_LIBCELLML_XML_SERIALISATION_H_ +#define SRC_API_LIBCELLML_XML_SERIALISATION_H_ + +#include "model.h" + +#include + +namespace libcellml { + +/** + Serialise the Model + \param model The model to be serialised. + \return XML representation + */ +std::string createXml(const Model& model); + +} + +#endif // SRC_API_LIBCELLML_XML_SERIALISATION_H_ diff --git a/src/generate.sh b/src/generate.sh new file mode 100755 index 0000000..511b5de --- /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..473f7db --- /dev/null +++ b/src/model.cpp @@ -0,0 +1,20 @@ +/* +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" + +libcellml::Model::Model() {} + diff --git a/src/xml_serialisation.cpp b/src/xml_serialisation.cpp new file mode 100644 index 0000000..b7dec3e --- /dev/null +++ b/src/xml_serialisation.cpp @@ -0,0 +1,35 @@ +/* +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; + + 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..8ef12a1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,20 +21,29 @@ 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 ${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) + include_directories(${Boost_INCLUDE_DIRS}) + target_link_libraries (libcellmlTest ${Boost_LIBRARIES}) +endif (Boost_FOUND) + + + # 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/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..0628264 --- /dev/null +++ b/tests/xml_serialisation_test.cpp @@ -0,0 +1,46 @@ +/* +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 "libcellml/model.h" + +#include "libcellml/xml_serialisation.h" + +#include "gtest/gtest.h" + +using namespace std; +using namespace libcellml; + +//! Test serialisation to XML of empty model. +TEST(XmlSerialisation, simpleXmlOutput) { + shared_ptr m1 = make_shared(); + + auto xml = createXml(*m1); + + string expectedXml{ +R"( + +)"}; + + ASSERT_EQ(expectedXml, xml); +} + + + + + From 9c4f1176c3fad4a054d8769181f185d7947dbe2b Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Fri, 27 Mar 2015 16:09:40 +1300 Subject: [PATCH 02/30] Fixed implementation code to pass test. Test was previously intended to fail. --- src/xml_serialisation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xml_serialisation.cpp b/src/xml_serialisation.cpp index b7dec3e..6956e58 100644 --- a/src/xml_serialisation.cpp +++ b/src/xml_serialisation.cpp @@ -28,7 +28,7 @@ std::string createXml(const libcellml::Model& model) { cellml12::Model modelXml; std::ostringstream oss; - //cellml12::serializeModel(oss, modelXml); + cellml12::serializeModel(oss, modelXml); return oss.str(); } From 37f26017b1a5d822bc6528572f5d99232357a076 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Fri, 27 Mar 2015 18:32:16 +1300 Subject: [PATCH 03/30] Enabled MSVC exceptions. As per http://stackoverflow.com/a/6847817 Note: this had to be redone, since the CMake refactor, it somehow got lost, see 89c624ba08c57a --- src/CMakeLists.txt | 3 +++ tests/CMakeLists.txt | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e9dda3e..1570d46 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -97,5 +97,8 @@ install(FILES install(EXPORT libcellml-targets DESTINATION lib/cmake) +if (MSVC) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc") +endif() set_target_properties(cellml PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8ef12a1..e329d9b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -46,4 +46,8 @@ target_link_libraries(libcellmlTest cellml) # test executable. add_test(libcellmlTest libcellmlTest) +if (MSVC) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc") +endif() + set_target_properties(libcellmlTest PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) From a3574431a0a2446b9004f7afa84dc2a0f3023de0 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Mon, 30 Mar 2015 10:16:52 +1300 Subject: [PATCH 04/30] Renamed cellml_1_2.* to start with lowercase letter As suggested by @agarny as part of review on #49. --- src/CMakeLists.txt | 4 ++-- src/{Cellml_1_2.cpp => cellml_1_2.cpp} | 2 +- src/{Cellml_1_2.h => cellml_1_2.h} | 2 +- src/{Cellml_1_2.xsd => cellml_1_2.xsd} | 0 src/generate.sh | 2 +- src/xml_serialisation.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename src/{Cellml_1_2.cpp => cellml_1_2.cpp} (99%) rename src/{Cellml_1_2.h => cellml_1_2.h} (99%) rename src/{Cellml_1_2.xsd => cellml_1_2.xsd} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1570d46..56e01cb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,14 +24,14 @@ 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 + ${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 + ${CMAKE_CURRENT_SOURCE_DIR}/cellml_1_2.h ${CELLML_EXPORT_H} ) diff --git a/src/Cellml_1_2.cpp b/src/cellml_1_2.cpp similarity index 99% rename from src/Cellml_1_2.cpp rename to src/cellml_1_2.cpp index 6868a57..42db7b4 100644 --- a/src/Cellml_1_2.cpp +++ b/src/cellml_1_2.cpp @@ -38,7 +38,7 @@ #include -#include "Cellml_1_2.h" +#include "cellml_1_2.h" namespace cellml12 { diff --git a/src/Cellml_1_2.h b/src/cellml_1_2.h similarity index 99% rename from src/Cellml_1_2.h rename to src/cellml_1_2.h index e6ddba7..7434ad0 100644 --- a/src/Cellml_1_2.h +++ b/src/cellml_1_2.h @@ -33,7 +33,7 @@ /** * @file - * @brief Generated from Cellml_1_2.xsd. + * @brief Generated from cellml_1_2.xsd. */ #ifndef CELLML_1_2_H diff --git a/src/Cellml_1_2.xsd b/src/cellml_1_2.xsd similarity index 100% rename from src/Cellml_1_2.xsd rename to src/cellml_1_2.xsd diff --git a/src/generate.sh b/src/generate.sh index 511b5de..89b43b1 100755 --- a/src/generate.sh +++ b/src/generate.sh @@ -1,2 +1,2 @@ -xsdcxx cxx-tree --options-file xsd-options.txt Cellml_1_2.xsd +./xsdcxx cxx-tree --options-file xsd-options.txt cellml_1_2.xsd diff --git a/src/xml_serialisation.cpp b/src/xml_serialisation.cpp index 6956e58..9822e2a 100644 --- a/src/xml_serialisation.cpp +++ b/src/xml_serialisation.cpp @@ -20,7 +20,7 @@ limitations under the License.Some license of other #include #include -#include "Cellml_1_2.h" +#include "cellml_1_2.h" namespace libcellml { From 2154983657bb03e9a7659aa60ad131d2e9483f74 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Mon, 30 Mar 2015 10:35:35 +1300 Subject: [PATCH 05/30] Changed from using auto to explicitly stating type As suggested by @agarny on review comment for #49. --- tests/xml_serialisation_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/xml_serialisation_test.cpp b/tests/xml_serialisation_test.cpp index 0628264..2326429 100644 --- a/tests/xml_serialisation_test.cpp +++ b/tests/xml_serialisation_test.cpp @@ -30,7 +30,7 @@ using namespace libcellml; TEST(XmlSerialisation, simpleXmlOutput) { shared_ptr m1 = make_shared(); - auto xml = createXml(*m1); + const std::string& xml = createXml(*m1); string expectedXml{ R"( From 4b12cc5e78119333da32ecfedb877efb9f50e580 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Mon, 30 Mar 2015 10:48:12 +1300 Subject: [PATCH 06/30] Eliminated `using namespace` as per Google style. As suggested by @agarny on review comment for #49. --- tests/xml_serialisation_test.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/xml_serialisation_test.cpp b/tests/xml_serialisation_test.cpp index 2326429..b91dca4 100644 --- a/tests/xml_serialisation_test.cpp +++ b/tests/xml_serialisation_test.cpp @@ -16,6 +16,7 @@ limitations under the License.Some license of other #include #include +#include #include "libcellml/model.h" @@ -23,14 +24,14 @@ limitations under the License.Some license of other #include "gtest/gtest.h" -using namespace std; -using namespace libcellml; - //! Test serialisation to XML of empty model. TEST(XmlSerialisation, simpleXmlOutput) { - shared_ptr m1 = make_shared(); + using Model = libcellml::Model; + using string = std::string; + + std::shared_ptr m1 = std::make_shared(); - const std::string& xml = createXml(*m1); + const std::string& xml = libcellml::createXml(*m1); string expectedXml{ R"( @@ -39,8 +40,3 @@ R"( ASSERT_EQ(expectedXml, xml); } - - - - - From c4431f006f3692dd3be570edba84ad4248675727 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Mon, 30 Mar 2015 10:52:10 +1300 Subject: [PATCH 07/30] Made use of full stop at end of comments consistent. As suggested by @agarny on review of #49. --- src/api/libcellml/model.h | 4 ++-- src/api/libcellml/version.h | 2 +- src/api/libcellml/xml_serialisation.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/api/libcellml/model.h b/src/api/libcellml/model.h index 73ddab2..dba9e46 100644 --- a/src/api/libcellml/model.h +++ b/src/api/libcellml/model.h @@ -22,11 +22,11 @@ limitations under the License.Some license of other //! Everything in LibCellML is in this namespace. namespace libcellml { -//! In-memory representation of a CellML model +//! In-memory representation of a CellML model. class Model { public: /** - * Default constructor + * Default constructor. */ Model(); }; diff --git a/src/api/libcellml/version.h b/src/api/libcellml/version.h index 85e3785..68eed24 100644 --- a/src/api/libcellml/version.h +++ b/src/api/libcellml/version.h @@ -28,7 +28,7 @@ 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(); diff --git a/src/api/libcellml/xml_serialisation.h b/src/api/libcellml/xml_serialisation.h index 871fb2a..3a3bc77 100644 --- a/src/api/libcellml/xml_serialisation.h +++ b/src/api/libcellml/xml_serialisation.h @@ -24,9 +24,9 @@ limitations under the License.Some license of other namespace libcellml { /** - Serialise the Model + Serialise the Model. \param model The model to be serialised. - \return XML representation + \return XML representation. */ std::string createXml(const Model& model); From cf391bb3ee861cd2ac10bf285051f5608ac4964f Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Mon, 30 Mar 2015 11:35:40 +1300 Subject: [PATCH 08/30] Removed unneeded scope resolution. Also, copy semantics better than reference for std::string in this case, I think, since move constructor will be invoked. --- tests/xml_serialisation_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/xml_serialisation_test.cpp b/tests/xml_serialisation_test.cpp index b91dca4..6dd4fda 100644 --- a/tests/xml_serialisation_test.cpp +++ b/tests/xml_serialisation_test.cpp @@ -31,7 +31,7 @@ TEST(XmlSerialisation, simpleXmlOutput) { std::shared_ptr m1 = std::make_shared(); - const std::string& xml = libcellml::createXml(*m1); + const string xml = libcellml::createXml(*m1); string expectedXml{ R"( From 89b2f09aa08ff33db45ce131a9634369156217f1 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Mon, 30 Mar 2015 12:20:11 +1300 Subject: [PATCH 09/30] Using `version.h`'s technique for exporting symbols --- src/api/libcellml/model.h | 4 +++- src/api/libcellml/xml_serialisation.h | 3 ++- tests/xml_serialisation_test.cpp | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/libcellml/model.h b/src/api/libcellml/model.h index dba9e46..c4dc8f8 100644 --- a/src/api/libcellml/model.h +++ b/src/api/libcellml/model.h @@ -19,11 +19,13 @@ limitations under the License.Some license of other #include +#include "libcellml/libcellml_export.h" + //! Everything in LibCellML is in this namespace. namespace libcellml { //! In-memory representation of a CellML model. -class Model { +class LIBCELLML_EXPORT Model { public: /** * Default constructor. diff --git a/src/api/libcellml/xml_serialisation.h b/src/api/libcellml/xml_serialisation.h index 3a3bc77..a07da26 100644 --- a/src/api/libcellml/xml_serialisation.h +++ b/src/api/libcellml/xml_serialisation.h @@ -18,6 +18,7 @@ limitations under the License.Some license of other #define SRC_API_LIBCELLML_XML_SERIALISATION_H_ #include "model.h" +#include "libcellml/libcellml_export.h" #include @@ -28,7 +29,7 @@ namespace libcellml { \param model The model to be serialised. \return XML representation. */ -std::string createXml(const Model& model); +std::string LIBCELLML_EXPORT createXml(const Model& model); } diff --git a/tests/xml_serialisation_test.cpp b/tests/xml_serialisation_test.cpp index 6dd4fda..d1b8d14 100644 --- a/tests/xml_serialisation_test.cpp +++ b/tests/xml_serialisation_test.cpp @@ -19,7 +19,6 @@ limitations under the License.Some license of other #include #include "libcellml/model.h" - #include "libcellml/xml_serialisation.h" #include "gtest/gtest.h" From 00e7344725a318ded7e5f874e145e4a20ed34bd3 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Mon, 30 Mar 2015 12:29:32 +1300 Subject: [PATCH 10/30] Faking Cmake required version. This is in order to get Ubuntu build slave result. (This will be reverted once cmake update done on build slave). --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d319a41..9dcde6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ # limitations under the License.cmake_minimum_required (VERSION 3.1) -cmake_minimum_required (VERSION 3.2) +cmake_minimum_required (VERSION 3.1) #NB: Actually v3.2 is required. set(PROJECT_NAME libCellML) project(${PROJECT_NAME} CXX) From 799e632bd358ab1301669edff2b80b4c22314548 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Mon, 30 Mar 2015 14:29:08 +1300 Subject: [PATCH 11/30] Used `sstream` instead of deprecated `strstream`. This eliminates the warning on Linux that a deprecated header was included. --- src/xml_serialisation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xml_serialisation.cpp b/src/xml_serialisation.cpp index 9822e2a..77b6889 100644 --- a/src/xml_serialisation.cpp +++ b/src/xml_serialisation.cpp @@ -17,7 +17,7 @@ limitations under the License.Some license of other #include "libcellml/xml_serialisation.h" #include #include -#include +#include #include #include "cellml_1_2.h" From 54de041d5452c10545f7c90522a741b94eba35b1 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Mon, 30 Mar 2015 16:13:49 +1300 Subject: [PATCH 12/30] Refactored common cmake settings. DRY (Don't Repeat Yourself) principle: set flags in one place and reuse from other locations. --- cmake/common.cmake | 12 ++++++++++++ src/CMakeLists.txt | 5 +---- tests/CMakeLists.txt | 6 ++---- 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 cmake/common.cmake diff --git a/cmake/common.cmake b/cmake/common.cmake new file mode 100644 index 0000000..11bd49a --- /dev/null +++ b/cmake/common.cmake @@ -0,0 +1,12 @@ +macro(INITIALISE_PROJECT) + if(WIN32) + set(CMAKE_CXX_FLAGS "/W3") + else() + set(CMAKE_CXX_FLAGS "-Wall -W -Werror") + endif() + + if (MSVC) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc") + endif() + +endmacro() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56e01cb..27f0e48 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License.cmake_minimum_required (VERSION 3.1) +INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake) set(CELLML_EXPORT_H "${CMAKE_CURRENT_BINARY_DIR}/api/libcellml/libcellml_export.h") set(LIBCELLML_CONFIG_H "${CMAKE_CURRENT_BINARY_DIR}/libcellml_config.h") @@ -97,8 +98,4 @@ install(FILES install(EXPORT libcellml-targets DESTINATION lib/cmake) -if (MSVC) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc") -endif() - set_target_properties(cellml PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e329d9b..16d948f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License.cmake_minimum_required (VERSION 3.1) +INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake) + # This adds another subdirectory, which has 'project(gtest)'. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.7.0) @@ -46,8 +48,4 @@ target_link_libraries(libcellmlTest cellml) # test executable. add_test(libcellmlTest libcellmlTest) -if (MSVC) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc") -endif() - set_target_properties(libcellmlTest PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) From 2c6df65983feed1d087ef77842290969b53145ac Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 09:34:08 +1300 Subject: [PATCH 13/30] Actually call the macro defined in cmake common. Thanks @agarny for catching that. Note: Warnings are now treated as errors, and build fails. --- src/CMakeLists.txt | 2 ++ tests/CMakeLists.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 27f0e48..407fec2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,8 @@ INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake) +INITIALISE_PROJECT() + 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 ( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 16d948f..b5e19bb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,6 +14,8 @@ INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake) +INITIALISE_PROJECT() + # This adds another subdirectory, which has 'project(gtest)'. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.7.0) From 357be4794ee921ec740da985c0a744e0cbb2b797 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 09:35:48 +1300 Subject: [PATCH 14/30] Eliminated unused variable. Note that the in-memory representation of the model is unused. I think this is probably OK, since there is only one way of serialising an empty model anyway. --- src/xml_serialisation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xml_serialisation.cpp b/src/xml_serialisation.cpp index 77b6889..f810dbc 100644 --- a/src/xml_serialisation.cpp +++ b/src/xml_serialisation.cpp @@ -24,7 +24,7 @@ limitations under the License.Some license of other namespace libcellml { -std::string createXml(const libcellml::Model& model) { +std::string createXml(const libcellml::Model&) { cellml12::Model modelXml; std::ostringstream oss; From 2461bad93bcbe7b82ab5ffadb718453c79679748 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 11:09:10 +1300 Subject: [PATCH 15/30] Minor refactoring of Cmake: reduce duplication. --- CMakeLists.txt | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9dcde6b..3e71391 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,27 +21,32 @@ project(${PROJECT_NAME} CXX) # 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() 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 From c5aef139546bbe8a43b83a83309115f04eb3cea7 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 11:15:47 +1300 Subject: [PATCH 16/30] Added Cmake flag to control whether warnings=errors. Default is that warnings are not treated as errors, however Buildbots will have this enabled. --- CMakeLists.txt | 6 ++++++ cmake/common.cmake | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e71391..8a45bb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,12 @@ set( LIBCELLML_TESTS OFF CACHE BOOL ${_PARAM_ANNOTATION} ) if( TESTS ) 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 diff --git a/cmake/common.cmake b/cmake/common.cmake index 11bd49a..bdd96f1 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -1,10 +1,12 @@ macro(INITIALISE_PROJECT) - if(WIN32) - set(CMAKE_CXX_FLAGS "/W3") - else() - set(CMAKE_CXX_FLAGS "-Wall -W -Werror") + if(LIBCELLML_WARNINGS_TREATED_AS_ERRORS) + if(WIN32) + set(CMAKE_CXX_FLAGS "/W3") + else() + set(CMAKE_CXX_FLAGS "-Wall -W -Werror") + endif() endif() - + if (MSVC) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc") endif() From ce419087844555bd71551d801a9c8f52a33c5d80 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 11:22:18 +1300 Subject: [PATCH 17/30] Removed unneeded conditional. --- src/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 407fec2..accda5d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -80,11 +80,6 @@ endif (Boost_FOUND) set_source_files_properties(${CELLML_EXPORT_H} PROPERTIES GENERATED TRUE) -# 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) -endif() - export(TARGETS cellml FILE libcellml-exports.cmake) install(TARGETS cellml EXPORT libcellml-targets From d1cba6165e92489940d3256a74b7b3eb04401130 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 11:24:40 +1300 Subject: [PATCH 18/30] Bumped required version. The Ubuntu Buildslave has just been updated to Cmake 3.2. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a45bb5..b8549b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ # limitations under the License.cmake_minimum_required (VERSION 3.1) -cmake_minimum_required (VERSION 3.1) #NB: Actually v3.2 is required. +cmake_minimum_required (VERSION 3.2) set(PROJECT_NAME libCellML) project(${PROJECT_NAME} CXX) From bcbb61b0f902b05adce42bd037a3c03f3ad72ff7 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 11:44:45 +1300 Subject: [PATCH 19/30] Changed include guard name convention for API headers. --- src/api/libcellml/model.h | 6 +++--- src/api/libcellml/version.h | 6 +++--- src/api/libcellml/xml_serialisation.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/api/libcellml/model.h b/src/api/libcellml/model.h index c4dc8f8..d27cde1 100644 --- a/src/api/libcellml/model.h +++ b/src/api/libcellml/model.h @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License.Some license of other */ -#ifndef SRC_API_LIBCELLML_MODEL_H_ -#define SRC_API_LIBCELLML_MODEL_H_ +#ifndef LIBCELLML_LIBCELLML_MODEL_H_ +#define LIBCELLML_LIBCELLML_MODEL_H_ #include @@ -35,4 +35,4 @@ class LIBCELLML_EXPORT Model { } // namespace libcellml -#endif // SRC_API_LIBCELLML_MODEL_H_ +#endif // LIBCELLML_LIBCELLML_MODEL_H_ diff --git a/src/api/libcellml/version.h b/src/api/libcellml/version.h index 68eed24..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 SRC_API_LIBCELLML_VERSION_H_ -#define SRC_API_LIBCELLML_VERSION_H_ +#ifndef LIBCELLML_LIBCELLML_VERSION_H_ +#define LIBCELLML_LIBCELLML_VERSION_H_ #include @@ -34,4 +34,4 @@ LIBCELLML_EXPORT const std::string getVersion(); } // namespace libcellml -#endif // SRC_API_LIBCELLML_VERSION_H_ +#endif // LIBCELLML_LIBCELLML_VERSION_H_ diff --git a/src/api/libcellml/xml_serialisation.h b/src/api/libcellml/xml_serialisation.h index a07da26..5fc8971 100644 --- a/src/api/libcellml/xml_serialisation.h +++ b/src/api/libcellml/xml_serialisation.h @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License.Some license of other */ -#ifndef SRC_API_LIBCELLML_XML_SERIALISATION_H_ -#define SRC_API_LIBCELLML_XML_SERIALISATION_H_ +#ifndef LIBCELLML_LIBCELLML_XML_SERIALISATION_H_ +#define LIBCELLML_LIBCELLML_XML_SERIALISATION_H_ #include "model.h" #include "libcellml/libcellml_export.h" @@ -33,4 +33,4 @@ std::string LIBCELLML_EXPORT createXml(const Model& model); } -#endif // SRC_API_LIBCELLML_XML_SERIALISATION_H_ +#endif // LIBCELLML_LIBCELLML_XML_SERIALISATION_H_ From 867166b566ff9b28b8f66d65ca08ba7aebf35255 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 12:19:37 +1300 Subject: [PATCH 20/30] Made condition compiler dependent. Thanks to @hsorby for pointing out that having it platform dependent was incorrect. Was originally based on similar condition in OpenCOR. --- cmake/common.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/common.cmake b/cmake/common.cmake index bdd96f1..37e2219 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -1,6 +1,6 @@ macro(INITIALISE_PROJECT) if(LIBCELLML_WARNINGS_TREATED_AS_ERRORS) - if(WIN32) + if(MSVC) set(CMAKE_CXX_FLAGS "/W3") else() set(CMAKE_CXX_FLAGS "-Wall -W -Werror") From 7dcbb9b82be1095d4416cfca1b0fdbd138f0ca73 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 12:33:35 +1300 Subject: [PATCH 21/30] Renamed Cmake macro. As suggested by @hsorby. --- cmake/common.cmake | 2 +- src/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/common.cmake b/cmake/common.cmake index 37e2219..e7ef4d5 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -1,4 +1,4 @@ -macro(INITIALISE_PROJECT) +macro(SET_COMPILER_FLAGS) if(LIBCELLML_WARNINGS_TREATED_AS_ERRORS) if(MSVC) set(CMAKE_CXX_FLAGS "/W3") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index accda5d..5a8bfeb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,7 +14,7 @@ INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake) -INITIALISE_PROJECT() +SET_COMPILER_FLAGS() set(CELLML_EXPORT_H "${CMAKE_CURRENT_BINARY_DIR}/api/libcellml/libcellml_export.h") set(LIBCELLML_CONFIG_H "${CMAKE_CURRENT_BINARY_DIR}/libcellml_config.h") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b5e19bb..c456f70 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,7 +14,7 @@ INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake) -INITIALISE_PROJECT() +SET_COMPILER_FLAGS() # This adds another subdirectory, which has 'project(gtest)'. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.7.0) From d86fdc5bd8b802a35361ceccb77848bcb29a4737 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 14:33:02 +1300 Subject: [PATCH 22/30] Using `CMAKE_MODULE_PATH` to specify include location. --- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8549b9..47555b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ cmake_minimum_required (VERSION 3.2) set(PROJECT_NAME libCellML) project(${PROJECT_NAME} CXX) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") + # Use the following variables when configuring the build from the command line to # set the corresponding cache variables. # TESTS ==> LIBCELLML_TESTS diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5a8bfeb..a3c1318 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License.cmake_minimum_required (VERSION 3.1) -INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake) +INCLUDE(${CMAKE_MODULE_PATH}/common.cmake) SET_COMPILER_FLAGS() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c456f70..873928a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License.cmake_minimum_required (VERSION 3.1) -INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake) +INCLUDE(${CMAKE_MODULE_PATH}/common.cmake) SET_COMPILER_FLAGS() From b95c1196ca7f256d5b63b2070593df68e2e51e86 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 14:50:17 +1300 Subject: [PATCH 23/30] For 3rd-party code, warnings are not deemed errors. --- cmake/common.cmake | 8 ++++++++ tests/gtest-1.7.0/CMakeLists.txt | 3 +++ 2 files changed, 11 insertions(+) diff --git a/cmake/common.cmake b/cmake/common.cmake index e7ef4d5..9f0c737 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -12,3 +12,11 @@ macro(SET_COMPILER_FLAGS) endif() endmacro() + +macro(DISABLE_TREATING_WARNINGS_AS_ERRORS) + if(WIN32) + string(REPLACE "/W3 /WX" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + string(REPLACE "-Wall -W -Werror" "-w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + endif() +endmacro() \ No newline at end of file diff --git a/tests/gtest-1.7.0/CMakeLists.txt b/tests/gtest-1.7.0/CMakeLists.txt index 292923d..49c750b 100644 --- a/tests/gtest-1.7.0/CMakeLists.txt +++ b/tests/gtest-1.7.0/CMakeLists.txt @@ -5,6 +5,9 @@ # ctest. You can select which tests to run using 'ctest -R regex'. # For more options, run 'ctest --help'. +# The rest of the libCellML project treats warnings as errors, but we want to disable this for third party code. +DISABLE_TREATING_WARNINGS_AS_ERRORS() + # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to # make it prominent in the GUI. option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) From 7ba287ab5ad1731b4ae4da351cf62b07e54d5265 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 18:20:14 +1300 Subject: [PATCH 24/30] Added and optional model name attribute. Test fail is intended, serialiser just ignores name. --- src/cellml_1_2.cpp | 184 ++++++++++++++++++++++++- src/cellml_1_2.h | 226 ++++++++++++++++++++++++++++++- src/cellml_1_2.xsd | 8 ++ src/model.cpp | 6 + tests/CMakeLists.txt | 1 + tests/model_test.cpp | 10 ++ tests/xml_serialisation_test.cpp | 24 +++- 7 files changed, 451 insertions(+), 8 deletions(-) create mode 100644 tests/model_test.cpp diff --git a/src/cellml_1_2.cpp b/src/cellml_1_2.cpp index 42db7b4..323a910 100644 --- a/src/cellml_1_2.cpp +++ b/src/cellml_1_2.cpp @@ -36,14 +36,49 @@ // // End prologue. +#include "cellml_1_2.h" + #include -#include "cellml_1_2.h" 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 @@ -55,7 +90,8 @@ namespace cellml12 Model:: Model () - : ::xml_schema::Type () + : ::xml_schema::Type (), + name_ (this) { } @@ -63,7 +99,8 @@ namespace cellml12 Model (const Model& x, ::xml_schema::Flags f, ::xml_schema::Container* c) - : ::xml_schema::Type (x, f, c) + : ::xml_schema::Type (x, f, c), + name_ (x.name_, f, this) { } @@ -71,8 +108,32 @@ namespace cellml12 Model (const ::xercesc::DOMElement& e, ::xml_schema::Flags f, ::xml_schema::Container* c) - : ::xml_schema::Type (e, f, 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:: @@ -82,10 +143,94 @@ namespace cellml12 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 @@ -519,6 +664,37 @@ namespace cellml12 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); } } diff --git a/src/cellml_1_2.h b/src/cellml_1_2.h index 7434ad0..f8270bd 100644 --- a/src/cellml_1_2.h +++ b/src/cellml_1_2.h @@ -30,7 +30,6 @@ // the Free/Libre and Open Source Software (FLOSS) which is described // in the accompanying FLOSSE file. // - /** * @file * @brief Generated from cellml_1_2.xsd. @@ -617,6 +616,7 @@ namespace xml_schema namespace cellml12 { class Model; + class CellMLIdentifier; } @@ -646,6 +646,82 @@ namespace cellml12 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 */ @@ -697,6 +773,17 @@ namespace cellml12 _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); + //@} /** @@ -704,6 +791,133 @@ namespace cellml12 */ 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 (); }; } @@ -1140,6 +1354,16 @@ namespace cellml12 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 diff --git a/src/cellml_1_2.xsd b/src/cellml_1_2.xsd index df0646b..80b9fe5 100644 --- a/src/cellml_1_2.xsd +++ b/src/cellml_1_2.xsd @@ -6,8 +6,16 @@ + + + + + + + + diff --git a/src/model.cpp b/src/model.cpp index 473f7db..c921659 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -16,5 +16,11 @@ 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/tests/CMakeLists.txt b/tests/CMakeLists.txt index 873928a..917e3d4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,6 +26,7 @@ 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} ) 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/xml_serialisation_test.cpp b/tests/xml_serialisation_test.cpp index d1b8d14..6888475 100644 --- a/tests/xml_serialisation_test.cpp +++ b/tests/xml_serialisation_test.cpp @@ -24,13 +24,13 @@ limitations under the License.Some license of other #include "gtest/gtest.h" //! Test serialisation to XML of empty model. -TEST(XmlSerialisation, simpleXmlOutput) { +TEST(XmlSerialisation, EmptyNamelessModel) { using Model = libcellml::Model; using string = std::string; - std::shared_ptr m1 = std::make_shared(); + Model m1; - const string xml = libcellml::createXml(*m1); + const string xml = libcellml::createXml(m1); string expectedXml{ R"( @@ -39,3 +39,21 @@ 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); +} From 25f9ce2426a05d1093a795802bf8ae77472277b0 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Tue, 31 Mar 2015 18:20:48 +1300 Subject: [PATCH 25/30] Serialiser uses name when serialising. --- src/xml_serialisation.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/xml_serialisation.cpp b/src/xml_serialisation.cpp index f810dbc..eb72e4c 100644 --- a/src/xml_serialisation.cpp +++ b/src/xml_serialisation.cpp @@ -24,8 +24,9 @@ limitations under the License.Some license of other namespace libcellml { -std::string createXml(const libcellml::Model&) { +std::string createXml(const libcellml::Model& model) { cellml12::Model modelXml; + if (model.getName()) modelXml.setName(*model.getName()); std::ostringstream oss; cellml12::serializeModel(oss, modelXml); From c3f756c48249bb7f5ca62ae912b21f10148f5dbc Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Tue, 31 Mar 2015 20:23:15 +1300 Subject: [PATCH 26/30] Correct conditional statement. --- cmake/common.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/common.cmake b/cmake/common.cmake index 9f0c737..7b99395 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -6,7 +6,7 @@ macro(SET_COMPILER_FLAGS) set(CMAKE_CXX_FLAGS "-Wall -W -Werror") endif() endif() - + if (MSVC) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc") endif() @@ -14,9 +14,9 @@ macro(SET_COMPILER_FLAGS) endmacro() macro(DISABLE_TREATING_WARNINGS_AS_ERRORS) - if(WIN32) + if(MSVC) string(REPLACE "/W3 /WX" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") else() string(REPLACE "-Wall -W -Werror" "-w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif() -endmacro() \ No newline at end of file +endmacro() From 3be776ab6c8518537caa9e835d78a330b4fde276 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Tue, 31 Mar 2015 20:24:57 +1300 Subject: [PATCH 27/30] Show how you use the CMAKE_MODULE_PATH. Set the include directories to be target specific, this helps a lot when using CMake to import libraries that use the CMake config mechanism. --- CMakeLists.txt | 5 +++-- src/CMakeLists.txt | 12 +++++------- tests/CMakeLists.txt | 8 +++----- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47555b3..172fa18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,13 @@ # limitations under the License.cmake_minimum_required (VERSION 3.1) -cmake_minimum_required (VERSION 3.2) +cmake_minimum_required(VERSION 3.2) set(PROJECT_NAME libCellML) project(${PROJECT_NAME} CXX) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") +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. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a3c1318..c5863e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,13 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License.cmake_minimum_required (VERSION 3.1) -INCLUDE(${CMAKE_MODULE_PATH}/common.cmake) - -SET_COMPILER_FLAGS() +set_compiler_flags() 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} ) @@ -27,7 +25,7 @@ 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 + ${CMAKE_CURRENT_SOURCE_DIR}/cellml_1_2.cpp ) set(API_HEADER_FILES @@ -66,14 +64,14 @@ set(CMAKE_INCLUDE_PATH "${XercesC_ROOT}/include") set(CMAKE_LIBRARY_PATH "${XercesC_ROOT}/lib") find_package (XercesC) if (XercesC_FOUND) - include_directories(${XercesC_INCLUDE_DIR}) + target_include_directories(cellml PRIVATE ${XercesC_INCLUDE_DIR}) target_link_libraries (cellml ${XercesC_LIBRARY}) endif (XercesC_FOUND) find_package (Boost) if (Boost_FOUND) - include_directories(${Boost_INCLUDE_DIRS}) + target_include_directories(cellml PRIVATE ${Boost_INCLUDE_DIRS}) target_link_libraries (cellml ${Boost_LIBRARIES}) endif (Boost_FOUND) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 873928a..aaec68d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,9 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License.cmake_minimum_required (VERSION 3.1) -INCLUDE(${CMAKE_MODULE_PATH}/common.cmake) - -SET_COMPILER_FLAGS() +set_compiler_flags() # This adds another subdirectory, which has 'project(gtest)'. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.7.0) @@ -38,8 +36,8 @@ target_link_libraries(libcellmlTest gtest gtest_main) find_package (Boost) if (Boost_FOUND) - include_directories(${Boost_INCLUDE_DIRS}) - target_link_libraries (libcellmlTest ${Boost_LIBRARIES}) + target_include_directories(libcellmlTest PRIVATE ${Boost_INCLUDE_DIRS}) + target_link_libraries(libcellmlTest ${Boost_LIBRARIES}) endif (Boost_FOUND) From 891d2a12e9ae04038b167417feaf9cb7026d65d1 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Tue, 31 Mar 2015 20:45:05 +1300 Subject: [PATCH 28/30] This is how you create a reusable function to set compiler flags per target. --- cmake/common.cmake | 44 ++++++++++++++++++-------------- src/CMakeLists.txt | 23 +++++++++-------- tests/CMakeLists.txt | 6 ++--- tests/gtest-1.7.0/CMakeLists.txt | 3 --- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/cmake/common.cmake b/cmake/common.cmake index 7b99395..de65b51 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -1,22 +1,28 @@ -macro(SET_COMPILER_FLAGS) - if(LIBCELLML_WARNINGS_TREATED_AS_ERRORS) - if(MSVC) - set(CMAKE_CXX_FLAGS "/W3") - else() - set(CMAKE_CXX_FLAGS "-Wall -W -Werror") - endif() - endif() +# 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) - if (MSVC) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc") +function(TARGET_WARNINGS_AS_ERRORS _TARGET) + set(_COMPILER_WAE) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(_COMPILER_WAE -Wall -W -Werror) endif() - -endmacro() - -macro(DISABLE_TREATING_WARNINGS_AS_ERRORS) - if(MSVC) - string(REPLACE "/W3 /WX" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - else() - string(REPLACE "-Wall -W -Werror" "-w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + set(_COMPILER_WAE /W3) endif() -endmacro() + 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 c5863e2..7f5ac6b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License.cmake_minimum_required (VERSION 3.1) -set_compiler_flags() - 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( @@ -40,21 +38,26 @@ set(HEADER_FILES ${LIBCELLML_CONFIG_H} ) -include_directories( - ${CMAKE_CURRENT_BINARY_DIR}/api - ${CMAKE_CURRENT_SOURCE_DIR}/api - ${CMAKE_CURRENT_SOURCE_DIR}/../extdep/libxsd - ${CMAKE_CURRENT_BINARY_DIR} -) - include(GenerateExportHeader) - add_compiler_export_flags() + add_library(cellml ${SOURCE_FILES} ${HEADER_FILES} ${API_HEADER_FILES} ) + +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} +) + +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") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index aaec68d..2ff5749 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License.cmake_minimum_required (VERSION 3.1) -set_compiler_flags() - # This adds another subdirectory, which has 'project(gtest)'. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.7.0) @@ -40,7 +38,9 @@ if (Boost_FOUND) 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) diff --git a/tests/gtest-1.7.0/CMakeLists.txt b/tests/gtest-1.7.0/CMakeLists.txt index 49c750b..292923d 100644 --- a/tests/gtest-1.7.0/CMakeLists.txt +++ b/tests/gtest-1.7.0/CMakeLists.txt @@ -5,9 +5,6 @@ # ctest. You can select which tests to run using 'ctest -R regex'. # For more options, run 'ctest --help'. -# The rest of the libCellML project treats warnings as errors, but we want to disable this for third party code. -DISABLE_TREATING_WARNINGS_AS_ERRORS() - # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to # make it prominent in the GUI. option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) From 4017ed0ce4bae5722e0ca498346ed28c63b42778 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Wed, 1 Apr 2015 15:00:20 +1300 Subject: [PATCH 29/30] Added "AppleClang" condition for warnings-as-errors --- cmake/common.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/common.cmake b/cmake/common.cmake index de65b51..f773f10 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -17,6 +17,9 @@ function(TARGET_WARNINGS_AS_ERRORS _TARGET) 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() From 99f11b02ad27375d612801401bc02fbf74286057 Mon Sep 17 00:00:00 2001 From: Randall Britten Date: Wed, 1 Apr 2015 15:03:51 +1300 Subject: [PATCH 30/30] Forgot to commit this as part of 7ba287ab5a --- src/api/libcellml/model.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/api/libcellml/model.h b/src/api/libcellml/model.h index d27cde1..a53a9e1 100644 --- a/src/api/libcellml/model.h +++ b/src/api/libcellml/model.h @@ -18,6 +18,7 @@ limitations under the License.Some license of other #define LIBCELLML_LIBCELLML_MODEL_H_ #include +#include #include "libcellml/libcellml_export.h" @@ -26,11 +27,28 @@ 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