/packages/ptc/src/c_api/capi_timer.inc

https://github.com/slibre/freepascal · Pascal · 148 lines · 107 code · 10 blank · 31 comment · 1 complexity · ae297c59515851f5023cdcc13bd39c09 MD5 · raw file

  1. {
  2. Free Pascal port of the OpenPTC C++ library.
  3. Copyright (C) 2001-2010 Nikolay Nikolov (nickysn@users.sourceforge.net)
  4. Original C++ version by Glenn Fiedler (ptc@gaffer.org)
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version
  9. with the following modification:
  10. As a special exception, the copyright holders of this library give you
  11. permission to link this library with independent modules to produce an
  12. executable, regardless of the license terms of these independent modules,and
  13. to copy and distribute the resulting executable under terms of your choice,
  14. provided that you also meet, for each linked independent module, the terms
  15. and conditions of the license of that module. An independent module is a
  16. module which is not derived from or based on this library. If you modify
  17. this library, you may extend this exception to your version of the library,
  18. but you are not obligated to do so. If you do not wish to do so, delete this
  19. exception statement from your version.
  20. This library is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. Lesser General Public License for more details.
  24. You should have received a copy of the GNU Lesser General Public
  25. License along with this library; if not, write to the Free Software
  26. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. }
  28. function ptc_timer_create: TPTC_TIMER;
  29. begin
  30. try
  31. ptc_timer_create := TPTC_TIMER(TPTCTimer.Create);
  32. except
  33. on error: TPTCError do
  34. begin
  35. ptc_exception_handle(error);
  36. ptc_timer_create := nil;
  37. end;
  38. end;
  39. end;
  40. procedure ptc_timer_destroy(obj: TPTC_TIMER);
  41. begin
  42. if obj = nil then
  43. exit;
  44. try
  45. TPTCTimer(obj).Destroy;
  46. except
  47. on error: TPTCError do
  48. ptc_exception_handle(error);
  49. end;
  50. end;
  51. procedure ptc_timer_set(obj: TPTC_TIMER; time: Double);
  52. begin
  53. try
  54. TPTCTimer(obj).settime(time);
  55. except
  56. on error: TPTCError do
  57. ptc_exception_handle(error);
  58. end;
  59. end;
  60. procedure ptc_timer_start(obj: TPTC_TIMER);
  61. begin
  62. try
  63. TPTCTimer(obj).start;
  64. except
  65. on error: TPTCError do
  66. ptc_exception_handle(error);
  67. end;
  68. end;
  69. procedure ptc_timer_stop(obj: TPTC_TIMER);
  70. begin
  71. try
  72. TPTCTimer(obj).stop;
  73. except
  74. on error: TPTCError do
  75. ptc_exception_handle(error);
  76. end;
  77. end;
  78. function ptc_timer_time(obj: TPTC_TIMER): Double;
  79. begin
  80. try
  81. ptc_timer_time := TPTCTimer(obj).time;
  82. except
  83. on error: TPTCError do
  84. begin
  85. ptc_exception_handle(error);
  86. ptc_timer_time := 0;
  87. end;
  88. end;
  89. end;
  90. function ptc_timer_delta(obj: TPTC_TIMER): Double;
  91. begin
  92. try
  93. ptc_timer_delta := TPTCTimer(obj).delta;
  94. except
  95. on error: TPTCError do
  96. begin
  97. ptc_exception_handle(error);
  98. ptc_timer_delta := 0;
  99. end;
  100. end;
  101. end;
  102. function ptc_timer_resolution(obj: TPTC_TIMER): Double;
  103. begin
  104. try
  105. ptc_timer_resolution := TPTCTimer(obj).resolution;
  106. except
  107. on error: TPTCError do
  108. begin
  109. ptc_exception_handle(error);
  110. ptc_timer_resolution := 0;
  111. end;
  112. end;
  113. end;
  114. procedure ptc_timer_assign(obj, timer: TPTC_TIMER);
  115. begin
  116. try
  117. TPTCTimer(obj).Assign(TPTCTimer(timer));
  118. except
  119. on error: TPTCError do
  120. ptc_exception_handle(error);
  121. end;
  122. end;
  123. function ptc_timer_equals(obj, timer: TPTC_TIMER): Boolean;
  124. begin
  125. try
  126. ptc_timer_equals := TPTCTimer(obj).equals(TPTCTimer(timer));
  127. except
  128. on error: TPTCError do
  129. begin
  130. ptc_exception_handle(error);
  131. ptc_timer_equals := False;
  132. end;
  133. end;
  134. end;