BT-MatML-Editor 0.1.4
Editor for the MatML 3.1 XML Schema
matml31_strongtypedef.h
1
2// Name: matml31_strongtypedef.h
3// Purpose: Extension to the matml31.h classes to include strongtypesdef.
4// Author: Paul McGrath
5// Modified by:
6// Created:
7// Copyright: (c) Paul McGrath
8// Licence: CC licence
10#pragma once
11#include "matml31.hxx"
12
13#include <boost/serialization/strong_typedef.hpp>
14
15#include <boost/config.hpp>
16#include <boost/operators.hpp>
17#include <boost/type_traits/has_nothrow_assign.hpp>
18#include <boost/type_traits/has_nothrow_constructor.hpp>
19#include <boost/type_traits/has_nothrow_copy.hpp>
20
21namespace bellshire {
22
23//Breaks Strongtype to Weaktype linkage.
24#define STRONG_TYPEDEF(T, D) \
25 struct D \
26 : boost::totally_ordered1< D \
27 , boost::totally_ordered2< D, T \
28 > > \
29 { \
30 typedef T* value_type; \
31 T* t; \
32 explicit D(T* t_) BOOST_NOEXCEPT_IF(boost::has_nothrow_copy_constructor<T>::value) : t((t_)) {} \
33 D() BOOST_NOEXCEPT_IF(boost::has_nothrow_default_constructor<T>::value) : t(nullptr) {} \
34 D( D* t_) BOOST_NOEXCEPT_IF(boost::has_nothrow_copy_constructor<T>::value) : t(t_->t) {} \
35 D* operator=( D* rhs) BOOST_NOEXCEPT_IF(boost::has_nothrow_assign<T>::value) { t = (rhs)->t; return this; } \
36 D* operator=( T* rhs) BOOST_NOEXCEPT_IF(boost::has_nothrow_assign<T>::value) { t = (rhs); return this; } \
37 operator const T* () const { return t; } \
38 operator T* () { return t; } \
39 operator const T& () const { return *t; } \
40 operator T& () { return *t; } \
41 bool operator==(const D* rhs) { return t == rhs->t; } \
42 bool operator<(const D* rhs) { return t < rhs->t; } \
43 void null() { t = nullptr; } \
44 };
45
54 const Class& lhs_mod(lhs);
55 const Class& rhs_mod(rhs);
56 return lhs_mod < rhs_mod;
57 }
58
59
61 /* The following is an example of how to use the strong_type created by the strong_typedef.
62 It is important to note that all the data contained in MatMLTreeItemData is destroyed/deleted by
63 MatMLTreeItemData::~MatMLTreeItemData using individual delete functions like
64 DeleteStrongType<Shape>() so the use of new is required and any new strongtypes have to be added
65 to the delete MatMLTreeItemData::~MatMLTreeItemData function.
66
67 MatMLTreeItemData data = new MatMLTreeItemData(new Shape(MatML_Element));
68 CurrentId = m_MatMLTreeCtrl->AppendItem(ParentId, str, -1, -1, data );
69
70 It should be noted that the strongtypes are used for selections and comparisions. Actual
71 manipulation of MatML data is done using the MatML data types.
72
73 e.g. Use Definition strongtype for comparisions and selection of the data from the
74 MatMLTreeCtrl. Use GlossaryTerms::Definition_type for the manipulation of the
75 MatML data. If a comparision is required between the strongtype and the MatML type
76 then use strongtype->t which is the MatML type encased within the strongtype.
77 */
78 STRONG_TYPEDEF(GlossaryTerm::Definition_type, Definition);
79 STRONG_TYPEDEF(GlossaryTerm::Abbreviation_type, Abbreviation);
80 STRONG_TYPEDEF(GlossaryTerm::Synonym_type, Synonym);
81 STRONG_TYPEDEF(Geometry::Shape_type, Shape);
82 STRONG_TYPEDEF(Geometry::Dimensions_type, Dimensions);
83 STRONG_TYPEDEF(Geometry::Orientation_type, Orientation);
84 STRONG_TYPEDEF(ProcessingDetails::Result_type, Result);
86 STRONG_TYPEDEF(Form::Description_type, Description); // Form::Description is Name. Use Name instead;
89
90}//namespace bellshire
Definition: matml31.hxx:897
Definition: matml31.hxx:2658
Contains the GUI and GUI associated classes. OnInit() calls the creation of the MaterialFrame GUI
Definition: BT_MatML_App.h:39
STRONG_TYPEDEF(GlossaryTerm::Definition_type, Definition)
Allows for the boost::any_cast to work with uniquely identify typedefs in the MatML Schema.
bool operator<(const Class::ParentSubClass_type &lhs, const Class::ParentSubClass_type &rhs)
This was required for the creation of the ParentSubClass strongtype
Definition: matml31_strongtypedef.h:53