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.

115 lines
3.7 KiB

  1. //==============================================================================
  2. //
  3. // Copyright (c) 2015-
  4. // Authors:
  5. // * Joachim Klein <klein@tcs.inf.tu-dresden.de>
  6. // * David Mueller <david.mueller@tcs.inf.tu-dresden.de>
  7. //
  8. //------------------------------------------------------------------------------
  9. //
  10. // This file is part of the cpphoafparser library,
  11. // http://automata.tools/hoa/cpphoafparser/
  12. //
  13. // The cpphoafparser library is free software; you can redistribute it and/or
  14. // modify it under the terms of the GNU Lesser General Public
  15. // License as published by the Free Software Foundation; either
  16. // version 2.1 of the License, or (at your option) any later version.
  17. //
  18. // The cpphoafparser library is distributed in the hope that it will be useful,
  19. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. // Lesser General Public License for more details.
  22. //
  23. // You should have received a copy of the GNU Lesser General Public
  24. // License along with this library; if not, write to the Free Software
  25. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. //
  27. //==============================================================================
  28. #ifndef CPPHOAFPARSER_ATOMACCEPTANCE_H
  29. #define CPPHOAFPARSER_ATOMACCEPTANCE_H
  30. #include <memory>
  31. #include <iostream>
  32. namespace cpphoafparser {
  33. /**
  34. * Atom of an acceptance condition, either Fin(accSet), Fin(!accSet), Inf(accSet) or Inf(!accSet)
  35. */
  36. class AtomAcceptance {
  37. public:
  38. /** A shared_ptr wrapping an AtomAcceptance */
  39. typedef std::shared_ptr<AtomAcceptance> ptr;
  40. /** The type of the temporal operator (Fin / Inf) */
  41. enum AtomType {TEMPORAL_FIN, TEMPORAL_INF};
  42. /**
  43. * Constructor.
  44. * @param kind the type of the temporal operator (Fin / Inf)
  45. * @param accSet the acceptance set index
  46. * @param negated is the acceptance set negated?
  47. **/
  48. AtomAcceptance(AtomType kind, unsigned int accSet, bool negated)
  49. : kind(kind), accSet(accSet), negated(negated) {
  50. }
  51. /** Static constructor for a Fin(accSet) atom. */
  52. static ptr Fin(unsigned int accSet) {
  53. return ptr(new AtomAcceptance(TEMPORAL_FIN, accSet, false));
  54. }
  55. /** Static constructor for a Fin(!accSet) atom. */
  56. static ptr FinNot(unsigned int accSet) {
  57. return ptr(new AtomAcceptance(TEMPORAL_FIN, accSet, true));
  58. }
  59. /** Static constructor for an Inf(accSet) atom. */
  60. static ptr Inf(unsigned int accSet) {
  61. return ptr(new AtomAcceptance(TEMPORAL_INF, accSet, false));
  62. }
  63. /** Static constructor for a Inf(!accSet) atom. */
  64. static ptr InfNot(unsigned int accSet) {
  65. return ptr(new AtomAcceptance(TEMPORAL_INF, accSet, true));
  66. }
  67. /** Get the temporal operator type of this atom. */
  68. AtomType getType() const {return kind;}
  69. /** Get the acceptance set index of this atom. */
  70. unsigned int getAcceptanceSet() const {return accSet;}
  71. /** Is the acceptance set negated? */
  72. bool isNegated() const {return negated;}
  73. /** Output operator, renders atom in HOA syntax */
  74. friend std::ostream& operator<<(std::ostream& out, const AtomAcceptance& atom) {
  75. out << (atom.kind == TEMPORAL_FIN ? "Fin" : "Inf");
  76. out << "(";
  77. if (atom.negated) out << "!";
  78. out << atom.accSet;
  79. out << ")";
  80. return out;
  81. }
  82. /** Equality operator */
  83. bool operator==(const AtomAcceptance& other) const {
  84. return
  85. this->kind == other.kind &&
  86. this->accSet == other.accSet &&
  87. this->negated == other.negated;
  88. }
  89. private:
  90. /** The temporal operator of this atom */
  91. AtomType kind;
  92. /** The acceptance set index of this atom */
  93. unsigned int accSet;
  94. /** Is the acceptance set negated? */
  95. bool negated;
  96. };
  97. }
  98. #endif