--- parser3/src/include/pa_stylesheet_connection.h 2003/11/20 16:34:25 1.35 +++ parser3/src/include/pa_stylesheet_connection.h 2023/09/26 20:49:07 1.49 @@ -1,14 +1,14 @@ /** @file Parser: Stylesheet connection decl. - Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexandr Petrosian (http://paf.design.ru) + Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_STYLESHEET_CONNECTION_H #define PA_STYLESHEET_CONNECTION_H -static const char * const IDENT_STYLESHEET_CONNECTION_H="$Date: 2003/11/20 16:34:25 $"; +#define IDENT_PA_STYLESHEET_CONNECTION_H "$Id: pa_stylesheet_connection.h,v 1.49 2023/09/26 20:49:07 moko Exp $" #include "libxslt/xslt.h" #include "libxslt/xsltInternals.h" @@ -17,12 +17,11 @@ static const char * const IDENT_STYLESHE #include "pa_xml_exception.h" #include "pa_common.h" #include "pa_globals.h" +#include "pa_xml_io.h" // defines -#define STYLESHEET_FILENAME_STAMP_SUFFIX ".stamp" - -/** Connection with stylesheet: +/** Connection with stylesheet: remembers time and can figure out that it needs recompilation */ class Stylesheet_connection: public PA_Object { @@ -31,37 +30,45 @@ class Stylesheet_connection: public PA_O private: - const String& ffile_spec; + String::Body ffile_spec; xsltStylesheet *fstylesheet; + HashStringBool* dependencies; time_t time_used; time_t prev_disk_time; public: - Stylesheet_connection(const String& afile_spec): + Stylesheet_connection(String::Body afile_spec): ffile_spec(afile_spec), - prev_disk_time(0), fstylesheet(0), - time_used(0), used(0) {} - - const String& file_spec() { return ffile_spec; } + dependencies(0), + time_used(0), + prev_disk_time(0), + used(0) + {} + + String::Body file_spec() { return ffile_spec; } + + bool uncachable() { + return !dependencies /*means they were external*/; + } bool expired(time_t older_dies) { - return !used && time_usedprev_disk_time?now_disk_time:0; } - void load(time_t new_disk_time) { - int saved=xmlDoValidityCheckingDefaultValue;// - xmlDoValidityCheckingDefaultValue=0;// - xsltStylesheet *nstylesheet= - xsltParseStylesheetFile(BAD_CAST ffile_spec.cstr(String::L_FILE_SPEC)); - xmlDoValidityCheckingDefaultValue = saved;// - if(xmlHaveGenericErrors()) { - GdomeException exc=0; - throw XmlException(&ffile_spec, exc); - } - if(!nstylesheet) - throw Exception("file.missing", - &ffile_spec, - "stylesheet failed to load"); - - xsltFreeStylesheet(fstylesheet); - fstylesheet=nstylesheet; - prev_disk_time=new_disk_time; - } - - time_t get_disk_time() { - size_t size; - time_t atime, mtime, ctime; - String stamp_file_spec(ffile_spec); - stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX; - // {file_spec}.stamp modification time OR {file_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, - true/*exception on error*/); - return mtime; - } + void load(time_t new_disk_time); + time_t get_disk_time(); 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) @@ -129,8 +107,7 @@ private: // connection usage methods class Stylesheet_connection_ptr { Stylesheet_connection *fconnection; public: - explicit Stylesheet_connection_ptr(Stylesheet_connection *aconnection) : - fconnection(aconnection) { + Stylesheet_connection_ptr(Stylesheet_connection *aconnection) : fconnection(aconnection) { fconnection->use(); } ~Stylesheet_connection_ptr() { @@ -139,22 +116,6 @@ public: 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