NVUtil.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
17 
18 import sys
19 import traceback
20 from omniORB import any
21 
22 import OpenRTM_aist
23 import SDOPackage, SDOPackage__POA
24 
25 
26 
50 def newNV(name, value):
51  try:
52  any_val = any.to_any(value)
53  except:
54  print "ERROR NVUtil.newNV : Can't convert to any. ", type(value)
55  raise
56 
57 
58  nv = SDOPackage.NameValue(name, any_val)
59  return nv
60 
61 
62 
85 def copyFromProperties(nv, prop):
86  keys = prop.propertyNames()
87  keys_len = len(keys)
88  nv_len = len(nv)
89  if nv_len > 0:
90  for i in range(nv_len):
91  del nv[-1]
92 
93  for i in range(keys_len):
94  nv.append(newNV(keys[i], prop.getProperty(keys[i])))
95 
96 
97 
118 def copyToProperties(prop, nvlist):
119  for nv in nvlist:
120  try:
121  val = str(any.from_any(nv.value, keep_structs=True))
122  prop.setProperty(str(nv.name),val)
123  except:
124  print OpenRTM_aist.Logger.print_exception()
125  pass
126 
127 
128 
129 
134 class to_prop:
135  def __init__(self):
137 
138  def __call__(self, nv):
139  self._prop.setProperty(nv.name, nv.value)
140 
141 
142 
143 
158 def toProperties(nv):
160  return p._prop
161 
162 
163 
164 
169 class nv_find:
170  """
171  """
172 
173  def __init__(self, name):
174  self._name = name
175 
176  def __call__(self, nv):
177  return str(self._name) == str(nv.name)
178 
179 
180 
204 def find(nv, name):
205  index = OpenRTM_aist.CORBA_SeqUtil.find(nv, nv_find(name))
206 
207  if index < 0:
208  raise "Not found."
209 
210  return nv[index].value
211 
212 
213 
229 def find_index(nv, name):
230  return OpenRTM_aist.CORBA_SeqUtil.find(nv, nv_find(name))
231 
232 
233 
249 def isString(nv, name):
250  try:
251  value = find(nv, name)
252  val = any.from_any(value, keep_structs=True)
253  return type(val) == str
254  except:
255  return False
256 
257 
258 
276 def isStringValue(nv, name, value):
277  if isString(nv, name):
278  if toString(nv, name) == value:
279  return True
280  return False
281 
282 
283 
311 def toString(nv, name=None):
312  if not name:
313  str_ = [""]
314  return dump_to_stream(str_, nv)
315 
316  str_value = ""
317  try:
318  ret_value = find(nv, name)
319  val = any.from_any(ret_value, keep_structs=True)
320  if type(val) == str:
321  str_value = val
322  except:
323  print OpenRTM_aist.Logger.print_exception()
324  pass
325 
326  return str_value
327 
328 
329 
352 def appendStringValue(nv, name, value):
353  index = find_index(nv, name)
354  if index >= 0:
355  tmp_str = nv[index].value.value()
356  values = OpenRTM_aist.split(tmp_str,",")
357  find_flag = False
358  for val in values:
359  if val == value:
360  find_flag = True
361 
362  if not find_flag:
363  tmp_str += ", "
364  tmp_str += value
365  nv[index].value = any.to_any(tmp_str)
366  else:
368 
369  return True
370 
371 
372 
386 def append(dest, src):
387  for i in range(len(src)):
389 
390 
391 
398 def dump_to_stream(out, nv):
399  for i in range(len(nv)):
400  val = any.from_any(nv[i].value, keep_structs=True)
401  if type(val) == str:
402  out[0] += (nv[i].name + ": " + str(nv[i].value) + "\n")
403  else:
404  out[0] += (nv[i].name + ": not a string value \n")
405 
406  return out[0]
407 
408 
409 
423 def dump(nv):
424  out = [""]
425  print dump_to_stream(out, nv)
def push_back(seq, elem)
Push the new element back to the CORBA sequence.
def for_each(seq, f)
Apply the functor to all CORBA sequence elements.
def copyToProperties(prop, nvlist)
Copy to Proeprties from NVList.
Definition: NVUtil.py:118
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
def appendStringValue(nv, name, value)
Definition: NVUtil.py:352
def __call__(self, nv)
Definition: NVUtil.py:138
def __init__(self, name)
Definition: NVUtil.py:173
def find_index(nv, name)
Definition: NVUtil.py:229
def toString(nv, name=None)
Get string value in NVList specified by name.
Definition: NVUtil.py:311
def isString(nv, name)
Definition: NVUtil.py:249
def isStringValue(nv, name, value)
Definition: NVUtil.py:276
def dump_to_stream(out, nv)
Print information configured in NVList as a string type std::ostream& dump_to_stream(std::ostream& ou...
Definition: NVUtil.py:398
def find(seq, f)
Return the index of CORBA sequence element that functor matches.
def __call__(self, nv)
Definition: NVUtil.py:176
def append(dest, src)
Definition: NVUtil.py:386
def toProperties(nv)
coil::Properties toProperties(const SDOPackage::NVList& nv);
Definition: NVUtil.py:158
def find(nv, name)
Get value in NVList specified by name.
Definition: NVUtil.py:204
def copyFromProperties(nv, prop)
Copy to NVList from Proeprties.
Definition: NVUtil.py:85
def newNV(name, value)
Create NameVale.
Definition: NVUtil.py:50


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Feb 28 2022 23:01:06