NetOceanDirect  1.31.0
OceanDirect .NET API
Utility.h
1 #pragma once
2 #include "stdafx.h"
3 
4 class Utility
5 {
6 public:
7  static array<int>^ IntegerManagedArray(int* memory, int count) {
8  if (memory == NULL)
9  throw gcnew ArgumentNullException("memory");
10 
11  if (count <= 0)
12  return gcnew array<int>(0);
13 
14  array<int>^ arr = gcnew array<int>(count);
15 
16  pin_ptr<int> arrPin = &arr[0];
17 
18  memcpy_s(arrPin, count * sizeof(int), memory, count * sizeof(int));
19 
20  return arr;
21  }
22 
23  static array<int>^ LongToIntegerManagedArray(long* memory, int count) {
24  if (memory == NULL) {
25  throw gcnew ArgumentNullException("memory");
26  }
27 
28  if (count <= 0) {
29  return gcnew array<int>(0);
30  }
31 
32  array<int>^ arr = gcnew array<int>(count);
33 
34  for (int i = 0; i < count; i++) {
35  arr[i] = static_cast<int>(memory[i]);
36  }
37 
38  return arr;
39  }
40 
41 
42  static array<std::uint32_t>^ UnsignedIntegerManagedArray(std::uint32_t* memory, int count) {
43  if (memory == NULL) {
44  throw gcnew ArgumentNullException("memory");
45  }
46 
47  if (count <= 0) {
48  return gcnew array<std::uint32_t>(0);
49  }
50 
51  array<std::uint32_t>^ arr = gcnew array<std::uint32_t>(count);
52 
53  pin_ptr<std::uint32_t> arrPin = &arr[0];
54 
55  memcpy_s(arrPin, count * sizeof(std::uint32_t), memory, count * sizeof(std::uint32_t));
56 
57  return arr;
58  }
59 
60  static array<double>^ DoubleManagedArray(double* memory, int count) {
61  if (memory == NULL)
62  throw gcnew ArgumentNullException("memory");
63 
64  if (count <= 0)
65  return gcnew array<double>(0);
66 
67  array<double>^ arr = gcnew array<double>(count);
68 
69  pin_ptr<double> arrPin = &arr[0];
70  memcpy_s(arrPin, count * sizeof(double), memory, count * sizeof(double));
71  return arr;
72  }
73 
74  static array<unsigned char>^ UCharManagedArray(unsigned char* memory, int count) {
75  if (memory == NULL)
76  throw gcnew ArgumentNullException("memory");
77 
78  if (count <= 0)
79  return gcnew array<unsigned char>(0);
80 
81  array<unsigned char>^ arr = gcnew array<unsigned char>(count);
82 
83  pin_ptr<unsigned char> arrPin = &arr[0];
84  memcpy_s(arrPin, count * sizeof(unsigned char), memory, count * sizeof(unsigned char));
85  return arr;
86  }
87 
88  static array<char>^ CharManagedArray(char* memory, int count) {
89  if (memory == NULL)
90  throw gcnew ArgumentNullException("memory");
91 
92  if (count <= 0)
93  return gcnew array<char>(0);
94 
95  array<char>^ arr = gcnew array<char>(count);
96 
97  pin_ptr<char> arrPin = &arr[0];
98  memcpy_s(arrPin, count * sizeof(char), memory, count * sizeof(char));
99  return arr;
100  }
101 
102  static String^ ToManagedString(const char* string)
103  {
104  return Marshal::PtrToStringAnsi((IntPtr)(char*)string);
105  }
106 
107  static char* ToUnmanagedString(String^ string)
108  {
109  return (char*)Marshal::StringToHGlobalAnsi(string).ToPointer();
110  }
111 
112  static const char* string_to_char_array(String^ string)
113  {
114  const char* str = (const char*)(Marshal::StringToHGlobalAnsi(string)).ToPointer();
115  return str;
116  }
117 
118 private:
119  Utility() {}
120 };
121 
Definition: Utility.h:5