Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
CommonSupportXML.h
1// trax track library
2// AD 2014
3//
4// "You are too clever to be mentally ill."
5//
6// The Indelicates
7//
8// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
9// Copyright (c) 2019 Marc-Michael Horstmann
10//
11// Permission is hereby granted to any person obtaining a copy of this software
12// and associated source code (the "Software"), to use, view, and study the
13// Software for personal or internal business purposes, subject to the following
14// conditions:
15//
16// 1. Redistribution, modification, sublicensing, or commercial use of the
17// Software is NOT permitted without prior written consent from the copyright
18// holder.
19//
20// 2. The Software is provided "AS IS", without warranty of any kind, express
21// or implied.
22//
23// 3. All copies of the Software must retain this license notice.
24//
25// For further information, please contact: horstmann.marc@trendverlag.de
26
27#pragma once
28
29#include <boost/property_tree/ptree.hpp>
30
31#include "common/Interval.h"
32
33
34namespace common{
35
42 namespace ptreesupport{
43
44 template<typename Valtype>
45 boost::property_tree::ptree& operator << ( boost::property_tree::ptree& opt, const Interval<Valtype>& i );
46 template<typename Valtype>
47 boost::property_tree::ptree& operator >> ( boost::property_tree::ptree& ipt, Interval<Valtype>& i );
48
49
50 template<typename Valtype> inline
51 boost::property_tree::ptree& operator << ( boost::property_tree::ptree& opt, const Interval<Valtype>& i ){
52 boost::property_tree::ptree ptInterval;
53
54 ptInterval.add( "<xmlattr>.near", i.Near() );
55 ptInterval.add( "<xmlattr>.far", i.Far() );
56
57 opt.add_child( "Interval", ptInterval );
58 return opt;
59 }
60
61 template<typename Valtype> inline
62 boost::property_tree::ptree& operator >> ( boost::property_tree::ptree& ipt, Interval<Valtype>& i ){
63 for( auto iter = ipt.begin(); iter != ipt.end(); ++iter ){
64 if( (*iter).first == "Interval" )
65 {
66 i.m_Near = (*iter).second.get( "<xmlattr>.near", Valtype{0} );
67 i.m_Far = (*iter).second.get( "<xmlattr>.far", Valtype{0} );
68 ipt.erase( iter );
69 return ipt;
70 }
71 }
72
73 assert( !"Syntax error: no Interval tag!" );
74 return ipt;
75 }
76
77
78 template<typename Valtype> inline
79 void ReadInterval( const boost::property_tree::ptree& pt, common::Interval<Valtype>& interval ){
80 interval.Near( pt.get( "<xmlattr>.near", Valtype{0} ) );
81 interval.Far( pt.get( "<xmlattr>.far", Valtype{0} ) );
82 }
83 } // namespace ptreesupport
84} // namespace common
85
ptree operator support
Definition CommonSupportXML.h:42
Namespace of common utility classes and methods.
Definition Helpers.h:43
An interval describes the area between two numbers. It is understood to contain the near one and exlu...
Definition Interval.h:42
constexpr Valtype Near() const noexcept
Definition Interval.h:381
constexpr Valtype Far() const noexcept
Definition Interval.h:386
Valtype m_Far
The 'right' side of the interval; usually the bigger value.
Definition Interval.h:45
Valtype m_Near
The 'left' side of the interval; usually the smaller value.
Definition Interval.h:44