File indexing completed on 2024-04-14 14:21:05

0001 /*
0002     This file is part of the kholidays library.
0003 
0004     SPDX-FileCopyrightText: 2010 John Layt <john@layt.net>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KHOLIDAYS_HOLIDAYPARSERDRIVER_P_H
0010 #define KHOLIDAYS_HOLIDAYPARSERDRIVER_P_H
0011 
0012 #include "qcalendarsystem_p.h"
0013 
0014 #include <QDate>
0015 #include <QString>
0016 
0017 #include "holiday.h"
0018 
0019 namespace KHolidays
0020 {
0021 /**
0022  * HolidayParserDriver abstract base class
0023  *
0024  * Defines a standard interface for parsing holiday files of various formats
0025  *
0026  * Derived classes must implement method parse(), other methods should work for
0027  * most circumstances
0028  *
0029  * @internal Private, for internal use only
0030  */
0031 class HolidayParserDriver
0032 {
0033 public:
0034     /**
0035      * Constructor of abstract holiday file parser driver class.
0036      * This will be called by derived classes.
0037      *
0038      * @param filePath full path to holiday file
0039      */
0040     explicit HolidayParserDriver(const QString &filePath);
0041 
0042     /**
0043      * Destructor.
0044      */
0045     virtual ~HolidayParserDriver();
0046 
0047     /**
0048      * Return the ISO 3166 country/region code of the file
0049      *
0050      * May be either just a country code ("US" = USA) or may include a regional
0051      * identifier ("US-CA" = California).  Returns "XX" if not a country.
0052      *
0053      * @return the full country code of the file
0054      */
0055     virtual QString fileCountryCode() const;
0056 
0057     /**
0058      * Return the ISO 639-1 language code of the file
0059      *
0060      * May be either just a language code ("en" = US English) or may include a country
0061      * identifier ("en_GB" = British English).
0062      *
0063      * @return the language code of the file
0064      */
0065     virtual QString fileLanguageCode() const;
0066 
0067     /**
0068      * Return the untranslated name of the file
0069      *
0070      * @return the untranslated name code of the file
0071      */
0072     virtual QString fileName() const;
0073 
0074     /**
0075      * Return the untranslated description of the file if available
0076      *
0077      * @return the untranslated description of the file
0078      */
0079     virtual QString fileDescription() const;
0080 
0081     /**
0082      * Return a list of holidays falling between any two dates with category
0083      *
0084      * @param startDate start date of the holiday parse range
0085      * @param endDate end date of the holiday parse range
0086      * @param category only holidays with corresponing category
0087      *
0088      * @return a list of holidays
0089      */
0090     virtual Holiday::List parseHolidays(const QDate &startDate, const QDate &endDate, const QString &category);
0091 
0092     /**
0093      * Return a list of holidays falling between any two dates inclusive astro seasons
0094      *
0095      * @param startDate start date of the holiday parse range
0096      * @param endDate end date of the holiday parse range
0097      *
0098      * @return a list of holidays
0099      */
0100     virtual Holiday::List parseHolidays(const QDate &startDate, const QDate &endDate);
0101 
0102     /**
0103      * Convenience function
0104      * Return a list of holidays falling on a given date
0105      *
0106      * @param date date to return holidays for
0107      *
0108      * @return a list of holidays
0109      */
0110     virtual Holiday::List parseHolidays(const QDate &date);
0111 
0112     /**
0113      * Return a list of holidays falling between any two dates without astro seasons
0114      *
0115      * @param startDate start date of the holiday parse range
0116      * @param endDate end date of the holiday parse range
0117      *
0118      * @return a list of holidays
0119      */
0120     virtual Holiday::List parseRawHolidays(const QDate &startDate, const QDate &endDate);
0121 
0122     /**
0123      * Convenience function
0124      * Return a list of holidays falling in a given calendar year
0125      *
0126      * @param calendarYear year to return holidays for
0127      * @param calendar calendar system of year
0128      *
0129      * @return a list of holidays
0130      */
0131     virtual Holiday::List parseHolidays(int calendarYear, QCalendarSystem::CalendarSystem calendar = QCalendarSystem::GregorianCalendar);
0132 
0133     /**
0134      * Standard error message handling
0135      *
0136      * @param errorMessage error message to log
0137      */
0138     virtual void error(const QString &errorMessage);
0139 
0140 protected:
0141     /**
0142      * Actually parse the file, must be re-implemented by derived classes
0143      */
0144     virtual void parse();
0145 
0146     /**
0147      * Parse the file for metadata only and populate the metadata variables
0148      */
0149     virtual void parseMetadata();
0150 
0151     /**
0152      * Set the calendar system to use
0153      *
0154      * @param calendar The QCalendarSystem calendar system to use
0155      */
0156     virtual void setParseCalendar(QCalendarSystem::CalendarSystem calendar);
0157 
0158     /**
0159      * Initialise parse year variables for calendar system
0160      */
0161     virtual void setParseStartEnd();
0162 
0163     QString m_filePath; // File to be parsed
0164 
0165     QString m_fileCountryCode; // File country code in ISO 3166-2 standard
0166     QString m_fileLanguageCode; // File language
0167     QString m_fileName; // File name
0168     QString m_fileDescription; // File description
0169 
0170     QDate m_requestStart; // First day of period being requested
0171     QDate m_requestEnd; // Last day of period being requested
0172 
0173     Holiday::List m_resultList; // List of requested holidays
0174 
0175     QCalendarSystem m_parseCalendar; // Calendar system being parsed
0176     int m_parseYear; // Year currently being parsed
0177     int m_parseStartYear; // First year to parse in parse calendar
0178     int m_parseEndYear; // Last year to parse in parse calendar
0179 };
0180 
0181 }
0182 
0183 #endif // KHOLIDAYS_HOLIDAYPARSERDRIVER_P_H