diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-09 06:41:55 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-09 06:41:55 +0000 |
commit | 8bec1dda934fa75cbb1402c58cb879b23305dc40 (patch) | |
tree | b4294963397117f1cf022e7a62452697df996de3 /src/result.h | |
download | abakus-8bec1dda934fa75cbb1402c58cb879b23305dc40.tar.gz abakus-8bec1dda934fa75cbb1402c58cb879b23305dc40.zip |
Add abakus
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/abakus@1071969 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/result.h')
-rw-r--r-- | src/result.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/result.h b/src/result.h new file mode 100644 index 0000000..682324c --- /dev/null +++ b/src/result.h @@ -0,0 +1,77 @@ +#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., 59 Temple Place, Suite 330, Boston, MA 02110-1301 USA + */ + +#include <qstring.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 QString &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; } + + QString 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; + QString m_message; + static Result *m_lastResult; +}; + +#endif /* ABAKUS_RESULT_H */ + +// vim: set et ts=8 sw=4: |