/tutorial/external/C++/example4.e

http://github.com/tybor/Liberty · Specman e · 54 lines · 30 code · 6 blank · 18 comment · 0 complexity · 63f781374a628b7b7ff7b87802cb6945 MD5 · raw file

  1. class EXAMPLE4
  2. --
  3. -- How to compile :
  4. -- g++ -c Bar.cpp
  5. -- compile -o example4 example4 Bar.o
  6. --
  7. -- As well as :
  8. -- compile -o example4 example4 Bar.cpp
  9. --
  10. create {ANY}
  11. make
  12. feature {ANY}
  13. make
  14. local
  15. bar_pointer: POINTER; c: CHARACTER
  16. do
  17. bar_pointer := new_bar('x')
  18. c := do_print_and_return(3)
  19. io.put_character(c)
  20. io.put_new_line
  21. delete_bar(bar_pointer)
  22. end
  23. new_bar (c: CHARACTER): POINTER
  24. -- Creation of a C++ `Bar' object. The file "Bar.h" must be
  25. -- #included and the C++ creation function has one argument
  26. -- (matching with `c') of type EIF_CHARACTER (matching with
  27. -- CHARACTER).
  28. external "[
  29. C++ [new Bar "Bar.h"] (EIF_CHARACTER)
  30. ]"
  31. end
  32. do_print_and_return (i: INTEGER): CHARACTER
  33. -- Calling static `Bar::do_print_and_return' passing `i' as argument.
  34. -- The returned C++ type is char which is supposed to match
  35. -- with CHARACTER. The file "Bar.h" must be #included (if not
  36. -- yet done).
  37. external "[
  38. C++ [static Bar "Bar.h" ] (EIF_INTEGER): char
  39. ]"
  40. end
  41. delete_bar (bar_pointer: POINTER)
  42. -- Calling C++ delete of class `Bar' on `bar_pointer'. The file
  43. -- "Bar.h" must be #included (if not yet done).
  44. external "[
  45. C++ [delete Bar "Bar.h"] ()
  46. ]"
  47. end
  48. end -- class EXAMPLE4