CORBA_SeqUtil.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef CORBA_SEQUTIL_H
20 #define CORBA_SEQUTIL_H
21 
22 #include <rtm/RTC.h>
23 #include <rtm/Manager.h>
24 
66 namespace CORBA_SeqUtil
67 {
97  template <class CorbaSequence, class Functor>
98  Functor for_each(CorbaSequence& seq, Functor f)
99  {
100  CORBA::ULong len;
101  len = seq.length();
102  for (CORBA::ULong i = 0; i < len; ++i)
103  {
104  f(seq[i]);
105  }
106  return f;
107  }
108 
141  template <class CorbaSequence, class Functor>
142  CORBA::Long find(const CorbaSequence& seq, Functor f)
143  {
144  CORBA::ULong len(seq.length());
145  for (CORBA::ULong i = 0; i < len; ++i)
146  {
147  if (f(seq[i])) return (CORBA::Long)i;
148  }
149  return -1;
150  }
151 
174  template <class CorbaSequence, class SequenceElement>
175  void push_back(CorbaSequence& seq, SequenceElement elem)
176  {
177  CORBA::ULong len(seq.length());
178  seq.length(len + 1);
179  seq[len] = elem;
180  }
181 
202  template <class CorbaSequence>
203  void push_back_list(CorbaSequence& seq1, const CorbaSequence& seq2)
204  {
205  CORBA::ULong len1(seq1.length());
206  CORBA::ULong len2(seq2.length());
207  CORBA::ULong len(len1 + len2);
208  seq1.length(len);
209 
210  for (CORBA::ULong i = 0; i < len2; ++i)
211  {
212  seq1[len1 + i] = seq2[i];
213  }
214  }
215 
244  template <class CorbaSequence, class SequenceElement>
245  void insert(CorbaSequence& seq, SequenceElement& elem, CORBA::ULong index)
246  {
247  CORBA::ULong len(seq.length());
248  if (index > len)
249  {
250  push_back(seq, elem);
251  return;
252  }
253 
254  seq.length(len + 1);
255  for (CORBA::ULong i = len; i > index; --i)
256  {
257  seq[i] = seq[i - 1];
258  }
259  seq[index] = elem;
260  }
261 
287  template <class CorbaSequence, class SequenceElement>
288  SequenceElement& front(CorbaSequence& seq)
289  {
290  return seq[0];
291  }
292 
316  template <class CorbaSequence, class SequenceElement>
317  SequenceElement& back(CorbaSequence& seq)
318  {
319  return seq[seq.length() - 1];
320  }
321 
344  template <class CorbaSequence>
345  void erase(CorbaSequence& seq, CORBA::ULong index)
346  {
347  CORBA::ULong len(seq.length());
348  if (index > len) return;
349 
350  for (CORBA::ULong i = index; i < len - 1; ++i)
351  {
352  seq[i] = seq[i + 1];
353  }
354  seq.length(len - 1);
355  }
356 
380  template <class CorbaSequence, class Functor>
381  void erase_if(CorbaSequence& seq, Functor f)
382  {
383  CORBA::Long index;
384  index = find(seq, f);
385  if (index < 0) return;
386  CORBA_SeqUtil::erase(seq, index);
387  }
388 
404  template <class CorbaSequence>
405  void clear(CorbaSequence& seq)
406  {
407  seq.length(0);
408  }
409  // End of CORBA sequence helper functions
410 
411 
412  template <class CorbaRefSequence>
413  coil::vstring refToVstring(const CorbaRefSequence& objlist)
414  {
415  coil::vstring iorlist;
416  CORBA::ORB_ptr orb = ::RTC::Manager::instance().getORB();
417 
418  for (CORBA::ULong i(0), len(objlist.length()); i < len; ++i)
419  {
420 #ifndef ORB_IS_RTORB
421  CORBA::String_var str_var = orb->object_to_string(objlist[i].in());
422 #else
423  CORBA_Object obj = (objlist.cobj())->_buffer[i];
424  CORBA::String_var str_var = orb->object_to_string2(obj);
425 #endif
426  iorlist.push_back(str_var.in());
427  }
428  return iorlist;
429  }
430 }; // namespace CORBA_SeqUtil
431 #endif // CORBA_SEQUTIL_H
void erase(CorbaSequence &seq, CORBA::ULong index)
Erase the element of the specified index.
SequenceElement & front(CorbaSequence &seq)
Get the front element of the CORBA sequence.
void clear(CorbaSequence &seq)
Erase all the elements of the CORBA sequence.
CORBA::ORB_ptr getORB()
Get the pointer to ORB.
Definition: Manager.cpp:832
static Manager & instance()
Get instance of the manager.
Definition: Manager.cpp:140
RTComponent manager class.
std::vector< std::string > vstring
Definition: stringutil.h:37
SequenceElement & back(CorbaSequence &seq)
Get the last element of the CORBA sequence.
void insert(CorbaSequence &seq, SequenceElement &elem, CORBA::ULong index)
Insert the element to the CORBA sequence.
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
list index
Definition: rtimages.py:10
void erase_if(CorbaSequence &seq, Functor f)
Remove an element of a sequence according to a predicate.
void push_back_list(CorbaSequence &seq1, const CorbaSequence &seq2)
Merge the elements of the CORBA sequence.
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
RTComponent header.
coil::vstring refToVstring(const CorbaRefSequence &objlist)
CORBA IOR helper functions.
Functor for_each(CorbaSequence &seq, Functor f)
Apply the functor to all CORBA sequence elements.
Definition: CORBA_SeqUtil.h:98


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:51