| 1 | // Copyright (C) 2009 - 2012 Mathias Froehlich |
| 2 | // |
| 3 | // This program is free software; you can redistribute it and/or |
| 4 | // modify it under the terms of the GNU General Public License as |
| 5 | // published by the Free Software Foundation; either version 2 of the |
| 6 | // License, or (at your option) any later version. |
| 7 | // |
| 8 | // This program is distributed in the hope that it will be useful, but |
| 9 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | // General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with this program; if not, write to the Free Software |
| 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 | |
| 17 | #ifndef HLAProxyDataElement_hxx |
| 18 | #define HLAProxyDataElement_hxx |
| 19 | |
| 20 | #include <simgear/hla/HLADataElement.hxx> |
| 21 | |
| 22 | namespace simgear { |
| 23 | |
| 24 | class HLAProxyDataElement : public HLADataElement { |
| 25 | public: |
| 26 | virtual ~HLAProxyDataElement() |
| 27 | { } |
| 28 | |
| 29 | virtual void accept(HLADataElementVisitor& visitor) |
| 30 | { |
| 31 | HLADataElement* dataElement = _getDataElement(); |
| 32 | if (!dataElement) |
| 33 | return; |
| 34 | dataElement->accept(visitor); |
| 35 | } |
| 36 | virtual void accept(HLAConstDataElementVisitor& visitor) const |
| 37 | { |
| 38 | const HLADataElement* dataElement = _getDataElement(); |
| 39 | if (!dataElement) |
| 40 | return; |
| 41 | dataElement->accept(visitor); |
| 42 | } |
| 43 | |
| 44 | virtual bool encode(HLAEncodeStream& stream) const |
| 45 | { |
| 46 | const HLADataElement* dataElement = _getDataElement(); |
| 47 | if (!dataElement) |
| 48 | return false; |
| 49 | return dataElement->encode(stream); |
| 50 | } |
| 51 | virtual bool decode(HLADecodeStream& stream) |
| 52 | { |
| 53 | HLADataElement* dataElement = _getDataElement(); |
| 54 | if (!dataElement) |
| 55 | return false; |
| 56 | return dataElement->decode(stream); |
| 57 | } |
| 58 | |
| 59 | virtual const HLADataType* getDataType() const |
| 60 | { |
| 61 | const HLADataElement* dataElement = _getDataElement(); |
| 62 | if (!dataElement) |
| 63 | return 0; |
| 64 | return dataElement->getDataType(); |
| 65 | } |
| 66 | virtual bool setDataType(const HLADataType* dataType) |
| 67 | { |
| 68 | HLADataElement* dataElement = _getDataElement(); |
| 69 | if (!dataElement) |
| 70 | return false; |
| 71 | return dataElement->setDataType(dataType); |
| 72 | } |
| 73 | |
| 74 | protected: |
| 75 | virtual HLADataElement* _getDataElement() = 0; |
| 76 | virtual const HLADataElement* _getDataElement() const = 0; |
| 77 | |
| 78 | virtual void _setStamp(Stamp* stamp) |
| 79 | { |
| 80 | HLADataElement::_setStamp(stamp); |
| 81 | HLADataElement* dataElement = _getDataElement(); |
| 82 | if (!dataElement) |
| 83 | return; |
| 84 | dataElement->attachStamp(*this); |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | } |
| 89 | |
| 90 | #endif |