WPOCT Software Developer's Kit (SDK)
SDK For using Wasatch Photonics OCT Spectrometers
Helper.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #define WIN32_LEAN_AND_MEAN
9 #include <fstream>
10 #include <sstream>
11 #include <vector>
12 
13 bool ParseBool(const char* str);
14 int ParseNumberInt(const char* str);
15 double ParseNumberDouble(const char* str);
16 
17 void Waitms(int val);
18 
19 std::string GetUserProfile();
20 void GetFullPathName(const char* rpstr, char* &ret_buff, int buffLen);
21 void GetFullPathName(const char* relativePathName, const char* initPath,
22  char* &ret_buff, int buffLen);
23 std::string GetFullPathName(std::string relativePathName, std::string initPath);
24 
26 std::string GetFilledDigits(int number, size_t totalDigits);
27 
28 void StringToLower (std::string &str);
29 void StringToUpper (std::string &str);
30 
32 void __declspec(dllexport) smessage(std::string msg);
33 
38 template< class T >
39 void SafeDelete(T*& pVal)
40 {
41  delete pVal;
42  pVal = nullptr;
43 }
44 
49 template< class T >
50 void SafeDeleteArray(T*& pVal)
51 {
52  delete[] pVal;
53  pVal = nullptr;
54 }
55 
56 template<class T>
57 void ResizeContainer (std::vector<T>& vec, size_t size, bool zeroIfNotResized = false)
58 {
59  // Check size is correct.
60  if (vec.size() != size)
61  {
62  // Resize also zeros out elements.
63  vec.resize(size);
64  }
65  else if (zeroIfNotResized)
66  {
67  // Fill with 0s.
68  std::fill(vec.begin(), vec.end(), T());
69  }
70 }
71 
77 template<typename T>
78 inline T Round(T num)
79 {
80  return (num > 0.0) ? floor(num + 0.5) : ceil(num - 0.5);
81 }
82 
86 template <typename DstType, typename SrcType>
87 inline bool IsType(const SrcType* src)
88 {
89  return dynamic_cast<const DstType*>(src) != 0;
90 }
91 
95 template<typename T>
96 inline bool Contains(std::vector<T, std::allocator<T> > vec, T item)
97 {
98  for (int i = 0; i < vec.size(); i++)
99  {
100  T old = vec[i];
101  if (old == item) { return true; }
102  }
103  return false;
104 }
105 
109 template<typename T>
110 inline std::string NumToString(T val)
111 {
112  std::stringstream stream;
113  stream << val;
114  return stream.str();
115 }
116 
122 //write typed value from string into t, base 10 is std::dec
123 template <typename T>
124 inline bool FromString(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&) = std::dec)
125 {
126  std::istringstream iss(s);
127  return !(iss >> f >> t).fail();
128 }
T Round(T num)
round value
Definition: Helper.h:78
std::string GetFilledDigits(int number, size_t totalDigits)
Gets the string prefixed with zeros so the string is a certain length.
Definition: Helper.cpp:61
bool Contains(std::vector< T, std::allocator< T > > vec, T item)
Definition: Helper.h:96
bool IsType(const SrcType *src)
Definition: Helper.h:87
std::string NumToString(T val)
Definition: Helper.h:110
bool FromString(T &t, const std::string &s, std::ios_base &(*f)(std::ios_base &)=std::dec)
save the array to file
Definition: Helper.h:124
void __declspec(dllexport) smessage(std void SafeDelete(T *&pVal)
messaging
Definition: Helper.h:39
void SafeDeleteArray(T *&pVal)
Safely delete memory that was allocated with new[].
Definition: Helper.h:50
__declspec(dllexport) IWPOCTCamera *GetOCTCamera(IWPOCTCamera __declspec(dllexport) IWPOCTCamera __declspec(dllexport) bool DestroyOCTCamera(IWPOCTCamera *camera
Gets the instance of the camera object.
Definition: IWPOCTController.cpp:29