Platform.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #include "Platform.h"
25 
26 #include <stdio.h>
27 #include <stdarg.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #ifdef WIN32
31  #include <windows.h>
32 #else
33  #include <time.h>
34 #endif
35 
36 namespace alvar {
37 
38 void errorAtLine(int status, int error, const char *filename,
39  unsigned int line, const char *format, ...)
40 {
41  fflush(stdout);
42  if (filename) {
43  fprintf(stderr, "%s:%d: ", filename, line);
44  }
45  if (format) {
46  va_list args;
47  va_start(args, format);
48  vfprintf(stderr, format, args);
49  va_end(args);
50  }
51  if (error) {
52  fprintf(stderr, ": %s", strerror(error));
53  }
54  fprintf(stderr, "\n");
55  fflush(stderr);
56  if (status) {
57  exit(status);
58  }
59 }
60 
61 void sleep(unsigned long milliseconds)
62 {
63  #ifdef WIN32
64  Sleep(milliseconds);
65  #else
66  struct timespec t;
67  t.tv_sec = 0;
68  t.tv_nsec = 1000 * 1000 * milliseconds;
69  nanosleep(&t, NULL);
70  #endif
71 }
72 
73 } // namespace alvar
Main ALVAR namespace.
Definition: Alvar.h:174
void ALVAR_EXPORT sleep(unsigned long milliseconds)
Sleep for a specified amount of milliseconds.
Definition: Platform.cpp:61
void ALVAR_EXPORT errorAtLine(int status, int error, const char *filename, unsigned int line, const char *format,...)
Error reporting function inspired by error_at_line() on Linux.
Definition: Platform.cpp:38
This file implements generic platform specific methods.


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04