CORBA_SeqUtil.py

説明を見る。
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 
00004 ##
00005 #  @file CORBA_SeqUtil.py
00006 #  @brief CORBA sequence utility template functions
00007 #  @date $Date: 2007/09/03 $
00008 #  @author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara
00009 # 
00010 #  Copyright (C) 2006-2008
00011 #      Task-intelligence Research Group,
00012 #      Intelligent Systems Research Institute,
00013 #      National Institute of
00014 #          Advanced Industrial Science and Technology (AIST), Japan
00015 #      All rights reserved.
00016 
00017 
00018 
00019 ##
00020 # @if jp
00021 # 
00022 # @brief CORBA sequence に対して functor を適用する
00023 # 
00024 # CORBA sequence 全ての要素に対して、与えられた functor を適用する。
00025 # functor は void functor(CORBA sequence の要素) の形式をとる必要がある。
00026 # 
00027 # @param seq Functor を適用する CORBA sequence
00028 # @param f CORBA sequence の要素を処理する Functor
00029 # 
00030 # @return 全ての要素を処理した Functor
00031 # 
00032 # @since 0.4.0
00033 # 
00034 # @else
00035 # 
00036 # @brief Apply the functor to all CORBA sequence elements
00037 # 
00038 # Apply the given functor to the given CORBA sequence.
00039 # functor should be void functor(CORBA sequence element).
00040 # 
00041 # @param seq CORBA sequence to be applied the functor
00042 # @param functor A functor to process CORBA sequence elements
00043 # 
00044 # @return Functor that processed all CORBA sequence elements
00045 # 
00046 # @endif
00047 def for_each(seq, f):
00048   len_ = len(seq)
00049   for i in range(len_):
00050     f(seq[i])
00051   return f
00052 
00053 
00054 ##
00055 # @if jp
00056 # @brief CORBA sequence の中から functor に適合する要素のインデックスを返す
00057 # 
00058 # CORBA sequence 全ての要素に対して、与えられた functor を適用し、
00059 # functor が true を返すようそのインデックスを返す。
00060 # functor は bool functor(const CORBA sequence の要素) の形式をとり、
00061 # 適合する要素に対して true を返す必要がある。
00062 # 
00063 # @param seq Functor を適用する CORBA sequence
00064 # @param f CORBA sequence から要素を見つける Functor
00065 # 
00066 # @return Functor に適合する要素のインデックス。見つからないときは -1 を返す。
00067 # 
00068 # @else
00069 # 
00070 # @brief Return the index of CORBA sequence element that functor matches 
00071 # 
00072 # This operation applies the given functor to the given CORBA sequence,
00073 # and returns the index of the sequence element that the functor matches.
00074 # The functor should be bool functor(const CORBA sequence element) type,
00075 # and it would return true, if the element matched the functor.
00076 # 
00077 # @param seq CORBA sequence to be applied the functor
00078 # @param functor A functor to process CORBA sequence elements
00079 # 
00080 # @return The index of the element that functor matches.
00081 #          If no element found, it would return -1.
00082 # 
00083 # @endif
00084 def find(seq, f):
00085   len_ = len(seq)
00086   for i in range(len_):
00087     if f(seq[i]):
00088       return i
00089   return -1
00090 
00091 
00092 ##
00093 # @if jp
00094 # @brief CORBA sequence の最後に要素を追加する
00095 # 
00096 # CORBA sequence の最後に与えられた要素を追加する。
00097 # CORBA sequence の長さは自動的に拡張される。
00098 # 
00099 # @param seq 要素を追加する CORBA sequence
00100 # @param elem 追加する要素
00101 # 
00102 # @else
00103 # 
00104 # @brief Push the new element back to the CORBA sequence
00105 # 
00106 # Add the given element to the last of CORBA sequence.
00107 # The length of the CORBA sequence will be expanded automatically.
00108 # 
00109 # @param seq CORBA sequence to be added a new element
00110 # @param elem The new element to be added to the CORBA sequence
00111 # 
00112 # @endif
00113 def push_back(seq, elem):
00114   seq.append(elem)
00115 
00116 
00117 ##
00118 # @if jp
00119 # @brief CORBA sequence をマージする
00120 # 
00121 # 与えられた CORBA sequence をマージする。
00122 # 
00123 # @param seq1 マージされる CORBA sequence
00124 # @param seq2 マージされる CORBA sequence
00125 # 
00126 # @else
00127 # 
00128 # @endif
00129 def push_back_list(seq1, seq2):
00130   for elem in seq2:
00131     seq1.append(elem)
00132 
00133 
00134 ##
00135 # @if jp
00136 # @brief CORBA sequence に要素を挿入する
00137 # 
00138 # CORBA sequence の index の位置に要素を加える。
00139 # index が 与えられた CORBA sequence の最大の index より大きい場合
00140 # 最後の要素として加えられる。
00141 # CORBA sequence の長さは自動的に拡張される。
00142 # 
00143 # @param seq 要素を追加する CORBA sequence
00144 # @param elem 追加する要素
00145 # @param index 要素を追加する位置
00146 # 
00147 # @else
00148 # 
00149 # @brief Insert the element to the CORBA sequence
00150 # 
00151 # Insert a new element in the given position to the CORBA sequence.
00152 # If the given index is greater than the length of the sequence,
00153 # the given element is pushed back to the last of the sequence.
00154 # The length of the CORBA sequence will be expanded automatically.
00155 # 
00156 # @param seq The CORBA sequence to be inserted a new element
00157 # @param elem The new element to be inserted the sequence
00158 # @param index The inserting position
00159 # 
00160 # @endif
00161 def insert(seq, elem, index):
00162   len_ = len(seq)
00163   if index < 0:
00164     return
00165   elif index > len:
00166     seq.append(elem)
00167     return
00168   seq.insert(index, elem)
00169 
00170 
00171 ##
00172 # @if jp
00173 # @brief CORBA sequence の先頭要素を取得する
00174 # 
00175 # CORBA sequence の先頭要素を取得する。
00176 # seq[0] と同じ。
00177 # 
00178 # @param seq 要素を取得する CORBA sequence
00179 # 
00180 # @return 取得した要素
00181 # 
00182 # @else
00183 # 
00184 # @brief Get the front element of the CORBA sequence
00185 # 
00186 # This operation returns seq[0].
00187 # 
00188 # @param seq The CORBA sequence to be get the element
00189 # 
00190 # @endif
00191 def front(seq):
00192   return seq[0]
00193 
00194 
00195 ##
00196 # @if jp
00197 # @brief CORBA sequence の末尾要素を取得する
00198 # 
00199 # CORBA sequence の末尾要素を取得する。
00200 # seq[seq.length() - 1] と同じ。
00201 # 
00202 # @param seq 要素を取得する CORBA sequence
00203 # 
00204 # @return 取得した要素
00205 # 
00206 # @else
00207 # 
00208 # @brief Get the last element of the CORBA sequence
00209 # 
00210 # This operation returns seq[seq.length() - 1].
00211 # 
00212 # @param seq The CORBA sequence to be get the element
00213 # 
00214 # @endif
00215 def back(seq):
00216   if len(seq) > 0:
00217     return seq[-1]
00218 
00219 
00220 ##
00221 # @if jp
00222 # @brief CORBA sequence の指定された位置の要素を削除する
00223 # 
00224 # 指定されたインデックスの要素を削除する。
00225 # 削除された要素は詰められ、sequence の長さは1減る。
00226 # 
00227 # @param seq 要素を削除する CORBA sequence
00228 # @param index 削除する要素のインデックス
00229 # 
00230 # @else
00231 # 
00232 # @brief Erase the element of the specified index
00233 # 
00234 # This operation removes the element of the given index.
00235 # The other elements are closed up around the hole.
00236 # 
00237 # @param seq The CORBA sequence to be get the element
00238 # @param index The index of the element to be removed
00239 # 
00240 # @endif
00241 def erase(seq, index):
00242   if index > len(seq) or index < 0:
00243     return
00244 
00245   del seq[index]
00246 
00247 ##
00248 # @if jp
00249 # 
00250 # @brief シーケンスの要素を述語にしたがって削除する
00251 # 
00252 # このオペレーションは述語として与えられた関数オブジェクトの
00253 # 条件が真のとき、そのシーケンスの要素を削除する。
00254 # 
00255 # @param seq 要素検索対象の CORBA sequence
00256 # @param f 削除するシーケンスを決定する術語
00257 # 
00258 # @else
00259 # 
00260 # @endif
00261 def erase_if(seq, f):
00262   index = find(seq, f)
00263   if index < 0:
00264     return
00265   del seq[index]
00266 
00267 
00268 ##
00269 # @if jp
00270 # @brief CORBA sequence の全要素を削除
00271 # 
00272 # CORBA sequence の全要素を削除する。
00273 # seq.length(0) と同じ。
00274 # 
00275 # @else
00276 # 
00277 # @brief Erase all the elements of the CORBA sequence
00278 # 
00279 # same as seq.length(0).
00280 # 
00281 # @endif
00282 def clear(seq):
00283   del seq[0:]

OpenRTMに対してMon Mar 17 15:11:05 2008に生成されました。  doxygen 1.5.4