/tutorial/external/C++/example2.e

http://github.com/tybor/Liberty · Specman e · 72 lines · 42 code · 8 blank · 22 comment · 0 complexity · dbee19fe0e5893601656f51cad7161ff MD5 · raw file

  1. class EXAMPLE2
  2. --
  3. -- How to compile:
  4. -- g++ -c Foo.cpp
  5. -- compile -o example2 example2 Foo.o
  6. --
  7. -- As well as:
  8. -- compile -o example2 example2 Foo.cpp
  9. --
  10. create {ANY}
  11. make
  12. feature {ANY}
  13. make
  14. local
  15. foo_pointer: POINTER
  16. do
  17. foo_pointer := new_foo
  18. set_integer(foo_pointer, 3)
  19. io.put_integer(get_integer(foo_pointer))
  20. io.put_new_line
  21. set_real(foo_pointer, 3.0)
  22. io.put_real(get_real(foo_pointer))
  23. io.put_new_line
  24. end
  25. new_foo: POINTER
  26. -- Creation of a C++ `Foo' object. The file "Foo.h" must be
  27. -- #included and the C++ creation function has no argument.
  28. external "[
  29. C++ [new Foo "Foo.h"] ()
  30. ]"
  31. end
  32. set_integer (foo_pointer: POINTER; i: INTEGER)
  33. -- Calling C++ `set_integer' member function of C++ class `Foo'
  34. -- using `foo_pointer' as target. This member procedure as
  35. -- an argument (matching with `i') of type EIF_INTEGER (which match
  36. -- with INTEGER). The file "Foo.h" must be #included (if not
  37. -- yet done).
  38. external "[
  39. C++ [Foo "Foo.h"] (EIF_INTEGER)
  40. ]"
  41. end
  42. get_integer (foo_pointer: POINTER): INTEGER
  43. -- Calling a C++ `get_integer' member function using `foo_pointer' as
  44. -- target. The file "Foo.h" must be #included (if not yet done).
  45. external "[
  46. C++ [Foo "Foo.h"] (): int
  47. ]"
  48. end
  49. set_real (foo_pointer: POINTER; r: REAL)
  50. -- Calling `set_real' C++ member procedure using `foo_pointer' as target
  51. -- and `r' as argument. The file "Foo.h" must be #included (if not
  52. -- yet done).
  53. external "[
  54. C++ [Foo "Foo.h"] (EIF_REAL)
  55. ]"
  56. end
  57. get_real (foo_pointer: POINTER): REAL
  58. -- Calling `get_real' C++ member function using `foo_pointer' as target.
  59. -- The file "Foo.h" must be #included (if not yet done).
  60. external "[
  61. C++ [Foo "Foo.h"] (): float
  62. ]"
  63. end
  64. end -- class EXAMPLE2