Open Core Interface - MLPI
MLPI-MotionLogicProgrammingInterface(mlpiCore)  1.26.2
mlpiApiHelper.h
Go to the documentation of this file.
1 #ifndef __MLPIAPIHELPER_H__
2 #define __MLPIAPIHELPER_H__
3 
4 // -----------------------------------------------------------------------
5 // MLPI - <mlpiApiHelper.h>
6 // -----------------------------------------------------------------------
7 // Copyright (c) 2013 Bosch Rexroth. All rights reserved.
8 // Redistribution and use in source and binary forms of this MLPI software
9 // (SW) provided to you, with or without modification, are permitted
10 // without prior approval provided that the following conditions are met:
11 //
12 // 1. Redistributions of source code of SW must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // 2. Redistributions in binary form of SW must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
18 //
19 // 3. User recognizes and acknowledges that it acquires no right,
20 // title or interest in or to any of the names or trademarks used in
21 // connection with the SW ("names") by virtue of this License and waives
22 // any right to or interest in the names. User recognizes and acknowledges
23 // that names of companies or names or products of companies displayed
24 // in the documentation of SW to indicate the interoperability of products
25 // with the SW are the names of their respective owners. The use of such
26 // names in the documentation of SW does not imply any sponsorship,
27 // approval, or endorsement by such companies of this product.
28 //
29 // 4. Modified code versions, i.e. any addition to or deletion from
30 // the substance or structure of the original code of the SW running
31 // the MLPI must be plainly marked as such and must not be misrepresented
32 // as being original SW.
33 //
34 // 5. The SW may only be used in connection with a Bosch Rexroth product.
35 //
36 // THIS INFORMATION IS PROVIDED BY BOSCH REXROTH CORPORATION "AS IS"
37 // AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING
38 // (BUT NOTLIMITED TO) ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
39 // FITNESS FOR ANY PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WHILE THE
40 // INFORMATION PROVIDED IS BELIEVED TO BE ACCURATE, IT MAY INCLUDE
41 // ERRORS OR INACCURACIES.
42 // SUBJECT TO COMPULSORY STATUTORY PROVISIONS OF THE GERMAN LAW AS
43 // THE APPLICABLE LAW FOR THIS LICENSE BOSCH REXROTH CORPORATION WILL
44 // NOT BE LIABLE FOR ANY DAMAGES OF ANY KIND ARISING FROM THE USE OF
45 // THE SOFTWARE DISTRIBUTED HEREUNDER, INCLUDING BUT NOT LIMITED TO
46 // DIRECT, INDIRECT, INCIDENTAL, PUNITIVE, AND CONSEQUENTIAL DAMAGES.
47 // -----------------------------------------------------------------------
48 //
58 //
59 // -----------------------------------------------------------------------
60 
61 
62 
76 
77 
78 
79 // -----------------------------------------------------------------------
80 // GLOBAL INCLUDES
81 // -----------------------------------------------------------------------
82 #include <set>
83 
84 #include "mlpiGlobal.h"
85 #include "wchar16.h"
86 
87 #include "mlpiApiLib.h"
88 
89 // -----------------------------------------------------------------------
90 // GLOBAL TYPEDEFS
91 // -----------------------------------------------------------------------
92 
93 using std::set;
94 using std::string;
95 
96 // -----------------------------------------------------------------------
97 // CLASS
98 // -----------------------------------------------------------------------
124 {
125 private:
126  string *W2S16(WCHAR16 *permission) {
127  return(new string(W2A16(permission)));
128  }
129 
130  set<string> c_setPermission;
131 
132 public:
133  MlpiApiPermissionEvaluation(const WCHAR16 *permissions) {
134  if (permissions==NULL)
135  return;
136  WCHAR16 *loc = wcsdup16(permissions), *curr = loc, *nxt = loc;
137  if (loc!=NULL)
138  {
139  while (true)
140  {
141  // find separator of two permissions or end of string
142  while (*nxt!=0 && *nxt!=';')
143  nxt++;
144  if (curr==nxt)
145  break;
146  if (*nxt!=0)
147  *nxt++=0;
148  // store permission string
149  c_setPermission.insert(*MlpiApiPermissionEvaluation::W2S16(curr));
150  // go to next permission string
151  curr = nxt;
152  }
153  delete[] loc;
154  }
155  }
156 
157  virtual ~MlpiApiPermissionEvaluation(void) {
158  c_setPermission.clear();
159  }
160 
161  BOOL8 hasPermission(WCHAR16 *permission) {
162  string tmp(W2A16(permission));
163  if(c_setPermission.find(tmp)!=c_setPermission.end())
164  return true;
165  else
166  return false;
167  }
168 };
169 
170 // -----------------------------------------------------------------------
171 // GLOBAL CONSTANTS
172 // -----------------------------------------------------------------------
173 
174 // -----------------------------------------------------------------------
175 // GLOBAL MACROS
176 // -----------------------------------------------------------------------
177 
178 // -----------------------------------------------------------------------
179 // GLOBAL EXPORTS
180 // -----------------------------------------------------------------------
181 
182 #ifdef __cplusplus
183 extern "C" {
184 #endif
185 
186 
187 
188 #ifdef __cplusplus
189 }
190 #endif
191 
192 
193 #endif /* __MLPIAPIHELPER_H__ */
signed char BOOL8
1 byte boolean
Definition: mlpiGlobal.h:158
This class helps to find out whether a permission is available.
wchar_t WCHAR16
UTF16 string.
Definition: mlpiGlobal.h:193
WCHAR16 * wcsdup16(const WCHAR16 *src)
Function appends a WCHAR16 string with a certain length to another.
Definition: wchar16.h:285