AbaKus – a complex calculator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1KB

  1. #ifndef ABAKUS_RESULT_H
  2. #define ABAKUS_RESULT_H
  3. /*
  4. * result.h - part of abakus
  5. * Copyright (C) 2004, 2005 Michael Pyne <michael.pyne@kdemail.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <tqstring.h>
  22. #include "node.h"
  23. #include "sharedptr.h"
  24. /**
  25. * A conceptual result from an expression parse. Used to determine if the
  26. * parse succeeded or failed. If it succeeded it will have a node value you
  27. * can query as the answer.
  28. */
  29. class Result
  30. {
  31. public:
  32. typedef enum { Error, Null, Value } Type;
  33. /**
  34. * Default constructor, which constructs a "failed" Result.
  35. */
  36. Result(const TQString &message = "");
  37. /**
  38. * Node constructor, which constructs a "succeeded" result.
  39. */
  40. Result(NodePtr node);
  41. /**
  42. * Constructor, constructs a "null" result. This means that the
  43. * operation was successful, but did not result in a normal value.
  44. */
  45. Result(Type type);
  46. bool failed() const { return m_type == Error; }
  47. Type type() const { return m_type; }
  48. TQString message() const { return m_message; }
  49. const NodePtr result() const { return m_node; }
  50. NodePtr result() { return m_node; }
  51. static Result *lastResult() { return m_lastResult; }
  52. static void setLastResult(const Result &result)
  53. {
  54. *m_lastResult = result;
  55. }
  56. private:
  57. NodePtr m_node;
  58. Type m_type;
  59. TQString m_message;
  60. static Result *m_lastResult;
  61. };
  62. #endif /* ABAKUS_RESULT_H */
  63. // vim: set et ts=8 sw=4: