summaryrefslogtreecommitdiffstats
path: root/src/result.h
blob: 600338a89649cb47f18e4bb6bf3742223d784248 (plain)
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
#ifndef ABAKUS_RESULT_H
#define ABAKUS_RESULT_H
/*
 * result.h - part of abakus
 * Copyright (C) 2004, 2005 Michael Pyne <michael.pyne@kdemail.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <tqstring.h>

#include "node.h"
#include "sharedptr.h"

/**
 * A conceptual result from an expression parse.  Used to determine if the
 * parse succeeded or failed.  If it succeeded it will have a node value you
 * can query as the answer.
 */
class Result
{
public:
    typedef enum { Error, Null, Value } Type;

    /**
     * Default constructor, which constructs a "failed" Result.
     */
    Result(const TQString &message = "");

    /**
     * Node constructor, which constructs a "succeeded" result.
     */
    Result(NodePtr node);

    /**
     * Constructor, constructs a "null" result.  This means that the
     * operation was successful, but did not result in a normal value.
     */
    Result(Type type);

    bool failed() const { return m_type == Error; }

    Type type() const { return m_type; }

    TQString message() const { return m_message; }

    const NodePtr result() const { return m_node; }
    NodePtr result() { return m_node; }

    static Result *lastResult() { return m_lastResult; }
    static void setLastResult(const Result &result)
    {
        *m_lastResult = result;
    }

private:
    NodePtr m_node;
    Type m_type;
    TQString m_message;
    static Result *m_lastResult;
};

#endif /* ABAKUS_RESULT_H */