00001 /*************************************************************************** 00002 ulxr_cached_resource.cpp - resources accessed via ulxmlrpcpp 00003 ------------------- 00004 begin : Sun May 1 2005 00005 copyright : (C) 2002-2007 by Ewald Arnold 00006 email : ulxmlrpcpp@ewald-arnold.de 00007 00008 $Id: ulxr_cached_resource.cpp 940 2006-12-30 18:22:05Z ewald-arnold $ 00009 00010 ***************************************************************************/ 00011 00012 /************************************************************************** 00013 * 00014 * This program is free software; you can redistribute it and/or modify 00015 * it under the terms of the GNU Lesser General Public License as 00016 * published by the Free Software Foundation; either version 2 of the License, 00017 * or (at your option) any later version. 00018 * 00019 * This program is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public License 00025 * along with this program; if not, write to the Free Software 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00027 * 00028 ***************************************************************************/ 00029 00030 //#define ULXR_SHOW_TRACE 00031 //#define ULXR_DEBUG_OUTPUT 00032 00033 00034 #define ULXR_NEED_EXPORTS 00035 #include <ulxmlrpcpp/ulxmlrpcpp.h> // always first header 00036 00037 #include <ulxmlrpcpp/ulxr_cached_resource.h> 00038 00039 00040 namespace ulxr { 00041 00042 00043 ULXR_API_IMPL0 CachedResource::CachedResource(const CppString &in_name) 00044 : name(in_name) 00045 { 00046 reset(); 00047 } 00048 00049 00050 ULXR_API_IMPL(CppString) CachedResource::getResourceName() const 00051 { 00052 ULXR_TRACE(ULXR_PCHAR("CachedResource::getResourceName")); 00053 return name; 00054 } 00055 00056 00057 ULXR_API_IMPL0 CachedResource::~CachedResource() 00058 { 00059 ULXR_TRACE(ULXR_PCHAR("~CachedResource ") << name); 00060 } 00061 00062 00063 ULXR_API_IMPL(std::string) CachedResource::data() const 00064 { 00065 ULXR_TRACE(ULXR_PCHAR("CachedResource::data")); 00066 return cache; 00067 } 00068 00069 00070 ULXR_API_IMPL(std::string) CachedResource::read() 00071 { 00072 ULXR_TRACE(ULXR_PCHAR("CachedResource::read")); 00073 std::string s = cache.substr(read_pointer); 00074 read_pointer = cache.length(); 00075 return s; 00076 } 00077 00078 00079 ULXR_API_IMPL(std::string) CachedResource::read(unsigned len) 00080 { 00081 ULXR_TRACE(ULXR_PCHAR("CachedResource::read(int) ") << len); 00082 std::string s = cache.substr(read_pointer, len); 00083 read_pointer += len; 00084 if (read_pointer > cache.length()) 00085 read_pointer = cache.length(); 00086 00087 return s; 00088 } 00089 00090 00091 ULXR_API_IMPL(void) CachedResource::write (const std::string &s) 00092 { 00093 ULXR_TRACE(ULXR_PCHAR("CachedResource::write ") << s.length()); 00094 cache += s; 00095 } 00096 00097 00098 ULXR_API_IMPL(void) CachedResource::write (const char *str, unsigned len) 00099 { 00100 ULXR_TRACE(ULXR_PCHAR("CachedResource::write(str, len) ") << len); 00101 cache.append(str, len); 00102 } 00103 00104 00105 ULXR_API_IMPL(void) CachedResource::clear() 00106 { 00107 cache = ""; 00108 read_pointer = 0; 00109 } 00110 00111 00112 ULXR_API_IMPL(void) CachedResource::reset() 00113 { 00114 read_pointer = 0; 00115 } 00116 00117 00118 }; // namespace ulxr