File: fcml_dialect.hpp

package info (click to toggle)
fcml 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,536 kB
  • sloc: ansic: 57,510; cpp: 21,835; sh: 4,410; lex: 834; makefile: 508; yacc: 317
file content (129 lines) | stat: -rw-r--r-- 2,897 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * FCML - Free Code Manipulation Library.
 * Copyright (C) 2010-2020 Slawomir Wojtasiak
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

/** @file fcml_dialect.hpp
 * C++ wrapper for the base dialect.
 *
 * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved.
 * This project is released under the GNU Lesser General Public License.
 */

#ifndef FCML_DIALECT_HPP_
#define FCML_DIALECT_HPP_

#include "fcml_common.hpp"

#include "fcml_dialect.h"

namespace fcml {

/**
 * An abstract dialect. It's a base class for all supported dialects.
 * @since 1.1.0
 * @remarks This class is thread-safe.
 */
class Dialect: public NonCopyable {
protected:

    /**
     * Default constructor.
     * @since 1.1.0
     */
    Dialect() {
        _dialect = NULL;
    }

    /**
     * Virtual destructor.
     * @since 1.1.0
     */
    virtual ~Dialect() {
        if (_dialect) {
            ::fcml_fn_dialect_free(_dialect);
            _dialect = NULL;
        }
    }

protected:

    friend class DialectAware;

    /**
     * Gets the wrapped FCML dialect.
     *
     * @return The wrapped FCML dialect.
     * @since 1.1.0
     */
    fcml_st_dialect* getDialect() const {
        return _dialect;
    }

    /**
     * Sets a new dialect for the wrapper.
     *
     * @param dialect The new dialect for the wrapper.
     * @since 1.1.0
     */
    void setDialect(fcml_st_dialect *dialect) {
        this->_dialect = dialect;
    }

private:

    /** Wrapped dialect */
    fcml_st_dialect *_dialect;

};

/** Inherit from this class in order to get access to the native FCML
 * dialect structure.
 * @since 1.1.0
 */
class DialectAware {
public:

    /**
     * Default constructor.
     * @since 1.1.0
     */
    DialectAware() {
    }

    /**
     * Virtual destructor.
     * @since 1.1.0
     */
    virtual ~DialectAware() {
    }

    /**
     * Extracts the native FCML dialect from the dialect object.
     *
     * @param dialect The wrapper.
     * @return The wrapped FCML dialect.
     * @since 1.1.0
     */
    fcml_st_dialect* extractDialect(const Dialect &dialect) const {
        return dialect.getDialect();
    }
};

}

#endif /* FCML_DIALECT_HPP_ */