Vuo  2.3.2
VuoList_VuoOscInputDevice.cc
Go to the documentation of this file.
1 
10 // This module is generated by vuo/type/list/generateVariants.sh.
11 
12 extern "C" {
13 #include "VuoHeap.h"
14 #include "VuoInteger.h"
15 #include "VuoText.h"
16 #include "VuoOscInputDevice.h"
18 }
19 #include "type.h"
20 #include <string>
21 #include <sstream>
22 #include <vector>
23 #include <algorithm>
24 
26 
29 #if 2 == 0
30 #define RETAIN(element)
31 #define RELEASE(element)
32 #elif 2 == 1
33 #define RETAIN(element) VuoRetain((void *)element)
34 #define RELEASE(element) VuoRelease((void *)element)
35 #elif 2 == 2
36 #define RETAIN(element) VuoOscInputDevice_retain(element)
37 #define RELEASE(element) VuoOscInputDevice_release(element)
38 #endif
40 
41 extern "C" {
43 #ifdef VUO_COMPILER
45  "title" : "List of VuoOscInputDevice elements",
46  "keywords" : [ ],
47  "version" : "1.0.0",
48  "dependencies" : [
49  "VuoInteger",
50  "VuoOscInputDevice"
51  ]
52  });
53 #endif
55 }
56 
60 void VuoListDestroy_VuoOscInputDevice(void *list);
61 
62 
64 {
65  if (!js)
66  return nullptr;
67 
69 
70  if (json_object_get_type(js) == json_type_array)
71  {
72  int itemCount = json_object_array_length(js);
73  for (int i = 0; i < itemCount; ++i)
74  {
75  json_object *itemObject = json_object_array_get_idx(js, i);
78  }
79  }
80 
81  return list;
82 }
83 
85 {
86  if (!value)
87  return nullptr;
88 
89  json_object *listObject = json_object_new_array();
90 
91  unsigned long itemCount = VuoListGetCount_VuoOscInputDevice(value);
92  for (unsigned long i = 1; i <= itemCount; ++i)
93  {
95  json_object *itemObject = VuoOscInputDevice_getJson(item);
96  json_object_array_add(listObject, itemObject);
97  }
98 
99  return listObject;
100 }
101 
102 #ifdef VuoOscInputDevice_REQUIRES_INTERPROCESS_JSON
103 struct json_object * VuoList_VuoOscInputDevice_getInterprocessJson(const VuoList_VuoOscInputDevice value)
104 {
105  json_object *listObject = json_object_new_array();
106 
107  unsigned long itemCount = VuoListGetCount_VuoOscInputDevice(value);
108  for (unsigned long i = 1; i <= itemCount; ++i)
109  {
111  json_object *itemObject = VuoOscInputDevice_getInterprocessJson(item);
112  json_object_array_add(listObject, itemObject);
113  }
114 
115  return listObject;
116 }
117 #endif
118 
120 {
121  const int maxItems = 20;
122  const int maxCharacters = 400;
123 
124  unsigned long itemCount = VuoListGetCount_VuoOscInputDevice(value);
125  if (itemCount == 0)
126  return strdup("Empty list");
127 
128  unsigned long characterCount = 0;
129 
130  std::ostringstream summary;
131  summary << "List containing " << itemCount << " item" << (itemCount == 1 ? "" : "s") << ": <ul>";
132  unsigned long i;
133  for (i = 1; i <= itemCount && i <= maxItems && characterCount <= maxCharacters; ++i)
134  {
136  char *itemSummaryCstr = VuoOscInputDevice_getSummary(item);
137  std::string itemSummary = itemSummaryCstr;
138  free(itemSummaryCstr);
139  if (itemSummary.length() && itemSummary.find_first_not_of(' ') != std::string::npos)
140  summary << "\n<li>" << itemSummary << "</li>";
141  else
142  summary << "\n<li>&nbsp;</li>";
143  characterCount += itemSummary.length();
144  }
145 
146  if (i <= itemCount)
147  summary << "\n<li>…</li>";
148 
149  summary << "</ul>";
150 
151  return strdup(summary.str().c_str());
152 }
153 
155 {
156  std::vector<VuoOscInputDevice> * l = new std::vector<VuoOscInputDevice>;
158  return reinterpret_cast<VuoList_VuoOscInputDevice>(l);
159 }
160 
162 {
163  std::vector<VuoOscInputDevice> * l = new std::vector<VuoOscInputDevice>(count, value);
165 
166 #if 2 != 0
167  for (unsigned long i = 0; i < count; ++i)
168  RETAIN(value);
169 #endif
170 
171  return reinterpret_cast<VuoList_VuoOscInputDevice>(l);
172 }
173 
175 {
176  if (!list)
177  return NULL;
178 
179  std::vector<VuoOscInputDevice> *oldList = (std::vector<VuoOscInputDevice> *)list;
180 
181  std::vector<VuoOscInputDevice> *newList = new std::vector<VuoOscInputDevice>(*oldList);
183 
184  for (std::vector<VuoOscInputDevice>::iterator i = newList->begin(); i != newList->end(); ++i)
185  RETAIN(*i);
186 
187  return reinterpret_cast<VuoList_VuoOscInputDevice>(newList);
188 }
189 
191 {
192  if (!list)
193  return;
194 
195 #if 2 != 0
197 #endif
198 
199  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
200  delete l;
201 }
202 
204 {
205  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
206 
207  if (!l || l->size() == 0)
208  return VuoOscInputDevice_makeFromJson(NULL);
209 
210  if (index == 0)
211  return (*l)[0];
212 
213  if (index > l->size())
214  return (*l)[l->size()-1];
215 
216  return (*l)[index-1];
217 }
218 
220 {
221  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
222 
223  if (!l || l->size() == 0)
224  return NULL;
225 
226  return &((*l)[0]);
227 }
228 
229 void VuoListForeach_VuoOscInputDevice(const VuoList_VuoOscInputDevice list, bool (^function)(const VuoOscInputDevice value))
230 {
231  auto l = reinterpret_cast<const std::vector<VuoOscInputDevice> *>(list);
232 
233  if (!l || l->size() == 0)
234  return;
235 
236  for (auto item : *l)
237  if (!function(item))
238  break;
239 }
240 
241 void VuoListSetValue_VuoOscInputDevice(const VuoList_VuoOscInputDevice list, const VuoOscInputDevice value, const unsigned long index, bool expandListIfNeeded)
242 {
243  if (!list)
244  return;
245 
246  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
247 
248  if (!expandListIfNeeded && l->size() == 0)
249  return;
250 
251  unsigned long clampedIndex = index - 1;
252 
253  if (index == 0)
254  clampedIndex = 0;
255 
256  if (expandListIfNeeded && clampedIndex >= l->size())
257  {
258  l->resize(clampedIndex + 1);
259  (*l)[clampedIndex] = value;
260  RETAIN(value);
261  }
262  else
263  {
264  if (index > l->size())
265  clampedIndex = l->size() - 1;
266 
267 #if 2 != 0
268  VuoOscInputDevice oldValue = (*l)[clampedIndex];
269 #endif
270  (*l)[clampedIndex] = value;
271  RETAIN(value);
272  RELEASE(oldValue);
273  }
274 }
275 
276 void VuoListInsertValue_VuoOscInputDevice(const VuoList_VuoOscInputDevice list, const VuoOscInputDevice value, const unsigned long index)
277 {
278  if (!list)
279  return;
280 
281  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
282 
283  unsigned long clampedIndex = index - 1;
284 
285  if (index == 0)
286  clampedIndex = 0;
287 
288  if (index > l->size())
289  clampedIndex = l->size() - 1;
290 
291  RETAIN(value);
292  if (index <= l->size())
293  l->insert(l->begin() + clampedIndex, value);
294  else
295  l->push_back(value);
296 }
297 
299 {
300  if (!list)
301  return;
302 
303  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
304  RETAIN(value);
305  l->insert(l->begin(), value);
306 }
307 
309 {
310  if (!list)
311  return;
312 
313  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
314  RETAIN(value);
315  l->push_back(value);
316 }
317 
318 void VuoListExchangeValues_VuoOscInputDevice(VuoList_VuoOscInputDevice list, const unsigned long indexA, const unsigned long indexB)
319 {
320  if (!list)
321  return;
322 
323  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
324 
325  size_t size = l->size();
326  if (size == 0)
327  return;
328 
329  unsigned long clampedIndexA = indexA - 1;
330  if (indexA == 0)
331  clampedIndexA = 0;
332  if (indexA > size)
333  clampedIndexA = size - 1;
334 
335  unsigned long clampedIndexB = indexB - 1;
336  if (indexB == 0)
337  clampedIndexB = 0;
338  if (indexB > size)
339  clampedIndexB = size - 1;
340 
341  VuoOscInputDevice value = (*l)[clampedIndexA];
342  (*l)[clampedIndexA] = (*l)[clampedIndexB];
343  (*l)[clampedIndexB] = value;
344 }
345 
346 #ifdef VuoOscInputDevice_SUPPORTS_COMPARISON
347 void VuoListSort_VuoOscInputDevice(VuoList_VuoOscInputDevice list)
348 {
349  if (!list)
350  return;
351 
352  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
353 
354  size_t size = l->size();
355  if (size < 2)
356  return;
357 
358  std::sort(l->begin(), l->end(), VuoOscInputDevice_isLessThan);
359 }
360 
361 bool VuoList_VuoOscInputDevice_areEqual(const VuoList_VuoOscInputDevice _a, const VuoList_VuoOscInputDevice _b)
362 {
363  if (_a == _b)
364  return true;
365 
366  if (!_a || !_b)
367  return _a == _b;
368 
369  std::vector<VuoOscInputDevice> *a = (std::vector<VuoOscInputDevice> *)_a;
370  std::vector<VuoOscInputDevice> *b = (std::vector<VuoOscInputDevice> *)_b;
371  if (a->size() != b->size())
372  return false;
373 
374  for (std::vector<VuoOscInputDevice>::iterator ia = a->begin(), ib = b->begin(); ia != a->end(); ++ia, ++ib)
375  if (!VuoOscInputDevice_areEqual(*ia, *ib))
376  return false;
377 
378  return true;
379 }
380 
381 bool VuoList_VuoOscInputDevice_isLessThan(const VuoList_VuoOscInputDevice _a, const VuoList_VuoOscInputDevice _b)
382 {
383  if (!_a || !_b)
384  return _a < _b;
385 
386  std::vector<VuoOscInputDevice> *a = (std::vector<VuoOscInputDevice> *)_a;
387  std::vector<VuoOscInputDevice> *b = (std::vector<VuoOscInputDevice> *)_b;
388  if (a->size() < b->size()) return true;
389  if (a->size() > b->size()) return false;
390 
391  for (std::vector<VuoOscInputDevice>::iterator ia = a->begin(), ib = b->begin(); ia != a->end(); ++ia, ++ib)
392  {
393  if (VuoOscInputDevice_isLessThan(*ia, *ib)) return true;
394  if (VuoOscInputDevice_isLessThan(*ib, *ia)) return false;
395  }
396 
397  return false;
398 }
399 #endif
400 
402 {
403  if (!list)
404  return;
405 
406  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
407 
408  size_t size = l->size();
409  if (size == 0)
410  return;
411 
412  double clampedChaos = MIN(MAX(chaos,0),1);
413  for (unsigned long i = 0; i < size * clampedChaos; ++i)
414  {
415  unsigned long j = VuoInteger_random(i, size-1);
416  VuoOscInputDevice value = (*l)[i];
417  (*l)[i] = (*l)[j];
418  (*l)[j] = value;
419  }
420 }
421 
423 {
424  if (!list)
425  return;
426 
427  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
428  std::reverse(l->begin(), l->end());
429 }
430 
431 VuoList_VuoOscInputDevice VuoListSubset_VuoOscInputDevice(VuoList_VuoOscInputDevice list, const signed long startIndex, const unsigned long itemCount)
432 {
433  if (!list)
434  return NULL;
435 
436  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
437 
438  size_t size = l->size();
439  if (size == 0)
440  return NULL;
441 
442  signed long clampedStartIndex = startIndex - 1;
443  signed long clampedEndIndex = clampedStartIndex + itemCount - 1;
444 
445  if (clampedStartIndex < 0)
446  clampedStartIndex = 0;
447  if (clampedEndIndex >= (signed long)size)
448  clampedEndIndex = size - 1;
449 
450  if (clampedStartIndex > clampedEndIndex)
451  return NULL;
452 
453  std::vector<VuoOscInputDevice> *newList = new std::vector<VuoOscInputDevice>(
454  l->begin() + clampedStartIndex,
455  l->begin() + clampedEndIndex + 1);
457 
458  for (std::vector<VuoOscInputDevice>::iterator i = newList->begin(); i != newList->end(); ++i)
459  RETAIN(*i);
460 
461  return reinterpret_cast<VuoList_VuoOscInputDevice>(newList);
462 }
463 
464 #ifdef VuoOscInputDevice_SUPPORTS_COMPARISON
465 VuoList_VuoOscInputDevice VuoListRemoveDuplicates_VuoOscInputDevice(VuoList_VuoOscInputDevice list)
466 {
467  if (!list)
468  return NULL;
469 
470  auto *l = (std::vector<VuoOscInputDevice> *)list;
471 
472  size_t size = l->size();
473  if (size == 0)
474  return NULL;
475 
476  auto *newList = new std::vector<VuoOscInputDevice>;
478 
479  for (auto i = l->begin(); i != l->end(); ++i)
480  {
481  bool found = false;
482  for (auto j = newList->begin(); j != newList->end(); ++j)
483  if (VuoOscInputDevice_areEqual(*i, *j))
484  {
485  found = true;
486  break;
487  }
488  if (!found)
489  newList->push_back(*i);
490  }
491 
492  for (auto i = newList->begin(); i != newList->end(); ++i)
493  RETAIN(*i);
494 
495  return reinterpret_cast<VuoList_VuoOscInputDevice>(newList);
496 }
497 #endif
498 
500 {
501  if (!list)
502  return;
503 
504  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
505 
506  if (!l->size())
507  return;
508 
509  RELEASE(l->front());
510  l->erase(l->begin());
511 }
512 
514 {
515  if (!list)
516  return;
517 
518  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
519 
520  if (!l->size())
521  return;
522 
523  RELEASE(l->back());
524  l->pop_back();
525 }
526 
528 {
529  if (!list)
530  return;
531 
532  while (VuoListGetCount_VuoOscInputDevice(list) > 0)
534 }
535 
537 {
538  if (!list)
539  return;
540 
541  if (index == 0)
542  return;
543 
544  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
545 
546  size_t size = l->size();
547  if (size == 0 || index > size)
548  return;
549 
550  l->erase(l->begin() + index - 1);
551 }
552 
554 {
555  if (!list)
556  return 0;
557 
558  std::vector<VuoOscInputDevice> * l = (std::vector<VuoOscInputDevice> *)list;
559  return l->size();
560 }