ffead.server.doc
AMEFResources.h
1 /*
2  Copyright 2009-2012, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #ifndef AMEFRESOURCES_H_
18 #define AMEFRESOURCES_H_
19 
20 #include "AMEFEncoder.h"
21 #include "AMEFDecoder.h"
22 
24 {
25  AMEFResources(){}
26  ~AMEFResources();
27 public:
28 
29  static char* longTocharArray(long l,int ind)
30  {
31  char* result = new char[ind];
32  for (int i = 0; i<ind; i++)
33  {
34  int offset = (ind - 1 - i) * 8;
35  result[i] = (char) ((l >> offset) & 0xFF);
36  }
37  return result;
38  }
39 
40  static string longTocharArrayS(long l,int ind)
41  {
42  char* result = new char[ind];
43  for (int i = 0; i<ind; i++)
44  {
45  int offset = (ind - 1 - i) * 8;
46  result[i] = (char) ((l >> offset) & 0xFF);
47  }
48  string tem(result);
49  return tem;
50  }
51 
52  static char* intTocharArray(int l,int ind)
53  {
54  char* result = new char[ind];
55  for (int i = 0; i<ind; i++)
56  {
57  int offset = (ind - 1 - i) * 8;
58  result[i] = (char) ((l >> offset) & 0xFF);
59  }
60  return result;
61  }
62 
63  static char* intTocharArrayWI(int l)
64  {
65  int ind = 1;
66  if(l<256)
67  ind =1;
68  else if(l<65536)
69  ind = 2;
70  else if(l<16777216)
71  ind =3;
72  else
73  ind =4;
74  char* result = new char[ind];
75  for (int i = 0; i<ind; i++)
76  {
77  int offset = (ind - 1 - i) * 8;
78  result[i] = (char) ((l >> offset) & 0xFF);
79  }
80  return result;
81  }
82 
83  static int charArrayToInt(char l[])
84  {
85  int t = 0;
86  int ind = sizeof l;
87  for (int i = 0; i < ind; i++)
88  {
89  int offset = (ind -1 - i) * 8;
90  t += (l[i] & 0x000000FF) << offset;
91  }
92  return t;
93  }
94 
95  static int charArrayToInt(char* l,int off,int ind)
96  {
97  int t = 0;
98  for (int i = 0; i < ind; i++)
99  {
100  int offset = (ind -1 - i) * 8;
101  t += (l[off+i] & 0x000000FF) << offset;
102  }
103  return t;
104  }
105 
106  static long charArrayToLong(char l[])
107  {
108  long t = 0;
109  int ind = sizeof l;
110  for (int i = 0; i < ind; i++)
111  {
112  int offset = (ind -1 - i) * 8;
113  t += (l[i] & 0x000000FF) << offset;
114  }
115  return t;
116  }
117  static long charArrayToLong(char* l,int off,int ind)
118  {
119  long t = 0;
120  for (int i = 0; i < ind; i++)
121  {
122  int offset = (ind -1 - i) * 8;
123  t += (l[off+i] & 0x000000FF) << offset;
124  }
125  return t;
126  }
127  static long charArrayToLong(char* l,int ind)
128  {
129  long t = 0;
130  for (int i = 0; i < ind; i++)
131  {
132  int offset = (ind -1 - i) * 8;
133  t += (l[i] & 0x000000FF) << offset;
134  }
135  return t;
136  }
137 
138  static string intTocharArrayS(int l, int ind)
139  {
140  char* result = new char[ind];
141  for (int i = 0; i<ind; i++)
142  {
143  int offset = (ind - 1 - i) * 8;
144  result[i] = (char) ((l >> offset) & 0xFF);
145  }
146  string tem(result);
147  return tem;
148  }
149  #ifdef IS_64_BIT
150  static string longTocharArrayWI(unsigned long long l)
151  {
152  int ind = 1;
153  if(l<256)
154  ind =1;
155  else if(l<65536)
156  ind = 2;
157  else if(l<16777216)
158  ind =3;
159  else if(l<4294967296ULL)
160  ind =4;
161  else if(l<1099511627776ULL)
162  ind =5;
163  else if(l<281474976710656ULL)
164  ind =6;
165  else if(l<72057594037927936ULL)
166  ind =7;
167  else
168  ind =8;
169  string result;
170  for (int i = 0; i<ind; i++)
171  {
172  int offset = (ind - 1 - i) * 8;
173  result.push_back((char) ((l >> offset) & 0xFF));
174  }
175  return result;
176  }
177  static string longTocharArrayWI(long l)
178  {
179  int ind = 1;
180  if(l<256)
181  ind =1;
182  else if(l<65536)
183  ind = 2;
184  else if(l<16777216)
185  ind =3;
186  else if(l<(long)4294967296ULL)
187  ind =4;
188  else if(l<(long)1099511627776ULL)
189  ind =5;
190  else if(l<(long)281474976710656ULL)
191  ind =6;
192  else if(l<(long)72057594037927936ULL)
193  ind =7;
194  else
195  ind =8;
196  string result;
197  for (int i = 0; i<ind; i++)
198  {
199  int offset = (ind - 1 - i) * 8;
200  result.push_back((char) ((l >> offset) & 0xFF));
201  }
202  return result;
203  }
204  #else
205  static string longTocharArrayWI(unsigned long long l)
206  {
207  int ind = 1;
208  if(l<256)
209  ind =1;
210  else if(l<65536)
211  ind = 2;
212  else if(l<16777216)
213  ind =3;
214  else if(l<4294967296ULL)
215  ind =4;
216  else if(l<1099511627776ULL)
217  ind =5;
218  else if(l<281474976710656ULL)
219  ind =6;
220  else if(l<72057594037927936ULL)
221  ind =7;
222  else
223  ind =8;
224  string result;
225  for (int i = 0; i<ind; i++)
226  {
227  int offset = (ind - 1 - i) * 8;
228  result.push_back((char) ((l >> offset) & 0xFF));
229  }
230  return result;
231  }
232  static string longTocharArrayWI(long l)
233  {
234  int ind = 1;
235  if(l<256)
236  ind =1;
237  else if(l<65536)
238  ind = 2;
239  else if(l<16777216)
240  ind =3;
241  else
242  ind =4;
243  string result;
244  for (int i = 0; i<ind; i++)
245  {
246  int offset = (ind - 1 - i) * 8;
247  result.push_back((char) ((l >> offset) & 0xFF));
248  }
249  return result;
250  }
251  #endif
252 };
253 
254 #endif /* AMEFRESOURCES_H_ */