| 1 |
/* |
| 2 |
* FCML - Free Code Manipulation Library. |
| 3 |
* Copyright (C) 2010-2020 Slawomir Wojtasiak |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 |
*/ |
| 19 |
|
| 20 |
/** @file fcml_dialect.hpp |
| 21 |
* C++ wrapper for the base dialect. |
| 22 |
* |
| 23 |
* @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved. |
| 24 |
* This project is released under the GNU Lesser General Public License. |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifndef FCML_DIALECT_HPP_ |
| 28 |
#define FCML_DIALECT_HPP_ |
| 29 |
|
| 30 |
#include "fcml_common.hpp" |
| 31 |
|
| 32 |
#include "fcml_dialect.h" |
| 33 |
|
| 34 |
namespace fcml { |
| 35 |
|
| 36 |
/** |
| 37 |
* An abstract dialect. It's a base class for all supported dialects. |
| 38 |
* @since 1.1.0 |
| 39 |
* @remarks This class is thread-safe. |
| 40 |
*/ |
| 41 |
class Dialect: public NonCopyable { |
| 42 |
protected: |
| 43 |
|
| 44 |
/** |
| 45 |
* Default constructor. |
| 46 |
* @since 1.1.0 |
| 47 |
*/ |
| 48 |
Dialect() { |
| 49 |
_dialect = NULL; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Virtual destructor. |
| 54 |
* @since 1.1.0 |
| 55 |
*/ |
| 56 |
virtual ~Dialect() { |
| 57 |
if (_dialect) { |
| 58 |
::fcml_fn_dialect_free(_dialect); |
| 59 |
_dialect = NULL; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
protected: |
| 64 |
|
| 65 |
friend class DialectAware; |
| 66 |
|
| 67 |
/** |
| 68 |
* Gets the wrapped FCML dialect. |
| 69 |
* |
| 70 |
* @return The wrapped FCML dialect. |
| 71 |
* @since 1.1.0 |
| 72 |
*/ |
| 73 |
fcml_st_dialect* getDialect() const { |
| 74 |
return _dialect; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Sets a new dialect for the wrapper. |
| 79 |
* |
| 80 |
* @param dialect The new dialect for the wrapper. |
| 81 |
* @since 1.1.0 |
| 82 |
*/ |
| 83 |
void setDialect(fcml_st_dialect *dialect) { |
| 84 |
this->_dialect = dialect; |
| 85 |
} |
| 86 |
|
| 87 |
private: |
| 88 |
|
| 89 |
/** Wrapped dialect */ |
| 90 |
fcml_st_dialect *_dialect; |
| 91 |
|
| 92 |
}; |
| 93 |
|
| 94 |
/** Inherit from this class in order to get access to the native FCML |
| 95 |
* dialect structure. |
| 96 |
* @since 1.1.0 |
| 97 |
*/ |
| 98 |
class DialectAware { |
| 99 |
public: |
| 100 |
|
| 101 |
/** |
| 102 |
* Default constructor. |
| 103 |
* @since 1.1.0 |
| 104 |
*/ |
| 105 |
DialectAware() { |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Virtual destructor. |
| 110 |
* @since 1.1.0 |
| 111 |
*/ |
| 112 |
virtual ~DialectAware() { |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Extracts the native FCML dialect from the dialect object. |
| 117 |
* |
| 118 |
* @param dialect The wrapper. |
| 119 |
* @return The wrapped FCML dialect. |
| 120 |
* @since 1.1.0 |
| 121 |
*/ |
| 122 |
fcml_st_dialect* extractDialect(const Dialect &dialect) const { |
| 123 |
return dialect.getDialect(); |
| 124 |
} |
| 125 |
}; |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
#endif /* FCML_DIALECT_HPP_ */ |