Utility.hpp
Go to the documentation of this file.
1 // This file contains symbols that may be used by any class or don't really go anywhere else.
2 #pragma once
3 
4 #include <iostream>
5 #include "Driver/OniDriverAPI.h"
6 
7 
8 // Oni helpers
9 
10 static OniVideoMode makeOniVideoMode(OniPixelFormat pixel_format, int resolution_x, int resolution_y, int frames_per_second)
11 {
12  OniVideoMode mode;
13  mode.pixelFormat = pixel_format;
14  mode.resolutionX = resolution_x;
15  mode.resolutionY = resolution_y;
16  mode.fps = frames_per_second;
17  return mode;
18 }
19 static bool operator==(const OniVideoMode& left, const OniVideoMode& right)
20 {
21  return (left.pixelFormat == right.pixelFormat && left.resolutionX == right.resolutionX
22  && left.resolutionY == right.resolutionY && left.fps == right.fps);
23 }
24 static bool operator<(const OniVideoMode& left, const OniVideoMode& right)
25 {
26  return (left.resolutionX * left.resolutionY < right.resolutionX * right.resolutionY);
27 }
28 
29 static bool operator<(const OniDeviceInfo& left, const OniDeviceInfo& right)
30 {
31  return (strcmp(left.uri, right.uri) < 0);
32 }
33 
34 
36 struct ExtractKey
37 {
38  template <typename T> typename T::first_type
39  operator()(T pair) const
40  {
41  return pair.first;
42  }
43 };
44 
45 
46 // holding out on C++11
47 template <typename T>
48 static std::string to_string(const T& n)
49 {
50  std::ostringstream oss;
51  oss << n;
52  return oss.str();
53 }
54 
55 
56 // global logging
57 namespace FreenectDriver
58 {
59  static void WriteMessage(std::string info)
60  {
61  std::cout << "OpenNI2-FreenectDriver: " << info << std::endl;
62  }
63 
64  // DriverServices is set in DeviceDriver.cpp so all files can call errorLoggerAppend()
66  static void LogError(std::string error)
67  {
68  // errorLoggerAppend() doesn't seem to go anywhere, so WriteMessage also
69  WriteMessage("(ERROR) " + error);
70 
71  if (DriverServices != NULL)
72  DriverServices->errorLoggerAppend(std::string("OpenNI2-FreenectDriver: " + error).c_str());
73  }
74 }
T::first_type operator()(T pair) const
Definition: Utility.hpp:39
static void LogError(std::string error)
Definition: Utility.hpp:66
void errorLoggerAppend(const char *format,...)
Definition: OniDriverAPI.h:141
int resolutionY
Definition: OniCTypes.h:63
Extracts first from pair, for transforming a map into its keys.
Definition: Utility.hpp:36
static bool operator==(const OniVideoMode &left, const OniVideoMode &right)
Definition: Utility.hpp:19
static bool operator<(const OniVideoMode &left, const OniVideoMode &right)
Definition: Utility.hpp:24
char uri[ONI_MAX_STR]
Definition: OniCTypes.h:78
int resolutionX
Definition: OniCTypes.h:62
OniPixelFormat pixelFormat
Definition: OniCTypes.h:61
static OniVideoMode makeOniVideoMode(OniPixelFormat pixel_format, int resolution_x, int resolution_y, int frames_per_second)
Definition: Utility.hpp:10
static std::string to_string(const T &n)
Definition: Utility.hpp:48
static void WriteMessage(std::string info)
Definition: Utility.hpp:59
OniPixelFormat
Definition: OniCEnums.h:47
static oni::driver::DriverServices * DriverServices
Definition: Utility.hpp:65


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Mon Jun 10 2019 13:46:42