LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
GenericAnnotation.h
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
18#ifndef LIMA_ANNOTATIONGRAPHS_GENERICANNOTATION_H
19#define LIMA_ANNOTATIONGRAPHS_GENERICANNOTATION_H
20
21#include <iostream>
22#include <boost/any.hpp>
23
24namespace Lima {
25namespace Common {
26namespace AnnotationGraphs {
27
30{
31public:
33 GenericAnnotation(const GenericAnnotation& ga) : m_annot(ga.m_annot) {}
34 template<typename ValueType> GenericAnnotation(const ValueType & v) : m_annot(v) {}
36 {
37 m_annot = ga.m_annot;
38 return *this;
39 }
40 template<typename ValueType> GenericAnnotation& operator=(const ValueType &v)
41 {
42 m_annot = v;
43 return *this;
44 }
45 virtual ~GenericAnnotation() {}
46
47 template<typename ValueType> ValueType * pointerValue()
48 {
49 return boost::any_cast<ValueType>(&m_annot);
50 }
51
52 template<typename ValueType> const ValueType * pointerValue() const
53 {
54 return boost::any_cast<ValueType>(&m_annot);
55 }
56
57 template<typename ValueType> ValueType value() const
58 {
59 return boost::any_cast<ValueType>(m_annot);
60 }
61
62private:
63 boost::any m_annot;
64};
65
66template<typename ValueType> std::ostream& operator<<(std::ostream& os, const GenericAnnotation& ga)
67{
68 os << ga.value<ValueType>();
69 return os;
70}
71
72
73} // closing namespace AnnotationGraphs
74} // closing namespace Common
75} // closing namespace Lima
76
77#endif // LIMA_ANNOTATIONGRAPHS_GENERICANNOTATION_H
This class allows to convert any object into an annotation by inheritance.
GenericAnnotation & operator=(const GenericAnnotation &ga)
GenericAnnotation & operator=(const ValueType &v)
LIMA_ANNOTATIONGRAPH_EXPORT QDebug & operator<<(QDebug &os, const AnnotationGraphEdge &e)
NAUTITIA.