/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/amqp_0_10/SerializableString.h

00001 #ifndef QPID_AMQP_0_10_SERIALIZABLESTRING_H
00002 #define QPID_AMQP_0_10_SERIALIZABLESTRING_H
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 namespace qpid {
00025 namespace amqp_0_10 {
00026 
00031 template <class T, class SizeType, int Unique=0>
00032 struct SerializableString : public std::basic_string<T> {
00033     SerializableString() {}
00034     template <class U> SerializableString(const U& u) : std::basic_string<T>(u) {}
00035     template <class I> SerializableString(const I& i, const I& j) : std::basic_string<T>(i,j) {}
00036 
00037     using std::basic_string<T>::operator=;
00038 
00039     template <class S> void serialize(S& s) { s.split(*this); }
00040 
00041     template <class S> void encode(S& s) const {
00042         s(SizeType(this->size()))(this->begin(), this->end());
00043     }
00044 
00045     template <class S> void decode(S& s) {
00046         SizeType newSize;
00047         s(newSize);
00048         this->resize(newSize);
00049         s(this->begin(), this->end());
00050     }
00051 };
00052 
00053 // TODO aconway 2008-02-29: separate ostream ops
00054 template <class T, class SizeType>
00055 std::ostream& operator<<(std::ostream& o, const SerializableString<T,SizeType>& s) {
00056     const std::basic_string<T> str(s);
00057     return o << str.c_str();    // TODO aconway 2008-02-29: why doesn't o<<str work?
00058 }
00059 
00060 }} // namespace qpid::amqp_0_10
00061 
00062 #endif  

Generated on Thu Apr 10 11:08:17 2008 for Qpid by  doxygen 1.4.7