--- parser3/src/include/pa_stylesheet_connection.h 2003/03/07 16:05:10 1.32.2.5 +++ parser3/src/include/pa_stylesheet_connection.h 2003/11/06 09:11:35 1.34 @@ -8,14 +8,13 @@ #ifndef PA_STYLESHEET_CONNECTION_H #define PA_STYLESHEET_CONNECTION_H -static const char* IDENT_STYLESHEET_CONNECTION_H="$Date: 2003/03/07 16:05:10 $"; +static const char* IDENT_STYLESHEET_CONNECTION_H="$Date: 2003/11/06 09:11:35 $"; #include "libxslt/xslt.h" #include "libxslt/xsltInternals.h" -#include "pa_pool.h" -#include "pa_stylesheet_manager.h" -#include "pa_exception.h" + +#include "pa_xml_exception.h" #include "pa_common.h" #include "pa_globals.h" @@ -27,25 +26,28 @@ static const char* IDENT_STYLESHEET_CONN remembers time and can figure out that it needs recompilation */ class Stylesheet_connection: public PA_Object { + + friend class Stylesheet_connection_ptr; + private: - StringPtr ffile_spec; + const String& ffile_spec; xsltStylesheet *fstylesheet; time_t time_used; time_t prev_disk_time; public: - Stylesheet_connection(StringPtr afile_spec): + Stylesheet_connection(const String& afile_spec): ffile_spec(afile_spec), prev_disk_time(0), fstylesheet(0), - time_used(0) {} + time_used(0), used(0) {} - StringPtr file_spec() { return ffile_spec; } + const String& file_spec() { return ffile_spec; } bool expired(time_t older_dies) { - return references()==1/*!used*/ && time_usedcstr(String::UL_FILE_SPEC).get()); + xsltParseStylesheetFile(BAD_CAST ffile_spec.cstr(String::L_FILE_SPEC)); xmlDoValidityCheckingDefaultValue = saved;// if(xmlHaveGenericErrors()) { GdomeException exc=0; - throw Exception(ffile_spec, exc); + throw XmlException(&ffile_spec, exc); } if(!nstylesheet) throw Exception("file.missing", - ffile_spec, + &ffile_spec, "stylesheet failed to load"); xsltFreeStylesheet(fstylesheet); @@ -99,10 +99,10 @@ private: time_t get_disk_time() { size_t size; time_t atime, mtime, ctime; - StringPtr stamp_file_spec(new String(*ffile_spec)); - *stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX; + String stamp_file_spec(ffile_spec); + stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX; // {file_spec}.stamp modification time OR {file_spec} - StringPtr stat_file_spec=file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec; + const String& stat_file_spec=file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec; file_stat(stat_file_spec, size, atime, mtime, ctime, @@ -110,12 +110,51 @@ private: return mtime; } - void touch() { +private: // connection usage methods + + int used; + void use() { time_used=time(0); // they started to use at this time + used++; + } + void unuse() { + used--; + if(!used) + close(); } }; -DECLARE_OBJECT_PTR(Stylesheet_connection); +/// Auto-object used to track Stylesheet_connection usage +class Stylesheet_connection_ptr { + Stylesheet_connection *fconnection; +public: + explicit Stylesheet_connection_ptr(Stylesheet_connection *aconnection) : + fconnection(aconnection) { + fconnection->use(); + } + ~Stylesheet_connection_ptr() { + fconnection->unuse(); + } + Stylesheet_connection* operator->() { + return fconnection; + } +/* Stylesheet_connection& operator*() { + return *fconnection; + }*/ + + // copying + Stylesheet_connection_ptr(const Stylesheet_connection_ptr& src) : fconnection(src.fconnection) { + fconnection->use(); + } + Stylesheet_connection_ptr& operator =(const Stylesheet_connection_ptr& src) { + // may do without this=src check + fconnection->unuse(); + fconnection=src.fconnection; + fconnection->use(); + + return *this; + } +}; #endif