00001 /* 00002 * Copyright (c) 2008, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 * 00029 */ 00030 00040 namespace warehouse_ros 00041 { 00042 00043 template<class M> 00044 ResultIterator<M>::ResultIterator(ResultIteratorHelper::Ptr results, bool metadata_only) : 00045 results_(results), metadata_only_(metadata_only) 00046 { 00047 if (!results_->hasData()) 00048 results_.reset(); 00049 } 00050 00051 template<class M> 00052 ResultIterator<M>::ResultIterator(const ResultIterator<M>& other) : 00053 results_(other.results_), metadata_only_(other.metadata_only_) 00054 { 00055 } 00056 00057 template<class M> 00058 ResultIterator<M>::ResultIterator() : 00059 metadata_only_(false) 00060 { 00061 } 00062 00063 template<class M> 00064 ResultIterator<M>::~ResultIterator() 00065 { 00066 } 00067 00068 template<class M> 00069 ResultIterator<M>& ResultIterator<M>::operator=(const ResultIterator& other) 00070 { 00071 results_ = other.results_; 00072 metadata_only_ = other.metadata_only_; 00073 return *this; 00074 } 00075 00076 template<class M> 00077 void ResultIterator<M>::increment() 00078 { 00079 if (!results_->next()) 00080 { 00081 results_.reset(); 00082 } 00083 } 00084 00085 template<class M> 00086 typename MessageWithMetadata<M>::ConstPtr ResultIterator<M>::dereference() const 00087 { 00088 ROS_ASSERT(results_); 00089 00090 typename MessageWithMetadata<M>::Ptr msg(new MessageWithMetadata<M>(results_->metadata())); 00091 if (!metadata_only_) 00092 { 00093 std::string str = results_->message(); 00094 uint8_t* buf = (uint8_t*)str.c_str(); 00095 ros::serialization::IStream istream(buf, str.size()); 00096 ros::serialization::Serializer<M>::read(istream, *msg); 00097 } 00098 return msg; 00099 } 00100 00101 template<class M> 00102 bool ResultIterator<M>::equal(const ResultIterator<M>& other) const 00103 { 00104 // Incomplete, the only case we care about is whether iter is at the end 00105 return (!results_ && !other.results_); 00106 } 00107 00108 } // namespace