|
reSIProcate/rutil
9694
|
00001 #ifdef HAVE_CONFIG_H 00002 #include "config.h" 00003 #endif 00004 00005 #include "rutil/CountStream.hxx" 00006 00007 // Remove warning about 'this' use in initiator list - pointer is only stored 00008 #if defined(WIN32) && !defined(__GNUC__) 00009 #pragma warning( disable : 4355 ) // using this in base member initializer list 00010 #endif 00011 00012 using namespace resip; 00013 00014 #ifdef RESIP_USE_STL_STREAMS 00015 static const int BuffSize(2048); 00016 // singleton buffer -- not really used 00017 static char Buffer[BuffSize]; 00018 #endif 00019 00020 CountBuffer::CountBuffer(size_t& count) 00021 : mCount(count) 00022 { 00023 mCount = 0; 00024 #ifdef RESIP_USE_STL_STREAMS 00025 setp(Buffer, Buffer+BuffSize); 00026 #endif 00027 } 00028 00029 CountBuffer::~CountBuffer() 00030 {} 00031 00032 #ifdef RESIP_USE_STL_STREAMS 00033 int 00034 CountBuffer::sync() 00035 { 00036 size_t len = pptr() - pbase(); 00037 if (len > 0) 00038 { 00039 mCount += len; 00040 // reset the put buffer 00041 setp(Buffer, Buffer + BuffSize); 00042 } 00043 return 0; 00044 } 00045 00046 int 00047 CountBuffer::overflow(int c) 00048 { 00049 sync(); 00050 if (c != -1) 00051 { 00052 pbump(1); 00053 return c; 00054 } 00055 return 0; 00056 } 00057 #else 00058 UInt64 CountBuffer::tellpbuf(void) 00059 { 00060 return mCount; 00061 } 00062 00063 00064 size_t CountBuffer::writebuf(const char *str, size_t count) 00065 { 00066 mCount += count; 00067 return count; 00068 } 00069 size_t CountBuffer::putbuf(char ch) 00070 { 00071 mCount++; 00072 00073 return 1; 00074 } 00075 #endif 00076 00077 CountStream::CountStream(size_t& count) 00078 : CountBuffer(count), EncodeStream(this) 00079 { 00080 } 00081 00082 CountStream::~CountStream() 00083 { 00084 #ifdef RESIP_USE_STL_STREAMS 00085 flush(); 00086 #endif 00087 } 00088 00089 /* ==================================================================== 00090 * The Vovida Software License, Version 1.0 00091 * 00092 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00093 * 00094 * Redistribution and use in source and binary forms, with or without 00095 * modification, are permitted provided that the following conditions 00096 * are met: 00097 * 00098 * 1. Redistributions of source code must retain the above copyright 00099 * notice, this list of conditions and the following disclaimer. 00100 * 00101 * 2. Redistributions in binary form must reproduce the above copyright 00102 * notice, this list of conditions and the following disclaimer in 00103 * the documentation and/or other materials provided with the 00104 * distribution. 00105 * 00106 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00107 * and "Vovida Open Communication Application Library (VOCAL)" must 00108 * not be used to endorse or promote products derived from this 00109 * software without prior written permission. For written 00110 * permission, please contact vocal@vovida.org. 00111 * 00112 * 4. Products derived from this software may not be called "VOCAL", nor 00113 * may "VOCAL" appear in their name, without prior written 00114 * permission of Vovida Networks, Inc. 00115 * 00116 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00117 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00118 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00119 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00120 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00121 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00122 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00123 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00124 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00125 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00126 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00127 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00128 * DAMAGE. 00129 * 00130 * ==================================================================== 00131 * 00132 * This software consists of voluntary contributions made by Vovida 00133 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00134 * Inc. For more information on Vovida Networks, Inc., please see 00135 * <http://www.vovida.org/>. 00136 * 00137 */
1.7.5.1