• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ut_Script.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) 2001 Dom Lachowicz
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 #ifndef UT_SCRIPT_H
00021 #define UT_SCRIPT_H
00022 
00023 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00024  * so even if it's commented out in-file that's still a lot of work for
00025  * the preprocessor to do...
00026  */
00027 #ifndef UT_TYPES_H
00028 #include "ut_types.h"
00029 #endif
00030 #include "ut_string_class.h"
00031 
00032 typedef UT_sint32 UT_ScriptIdType;
00033 
00034 #ifndef UTVECTOR_H
00035 #include "ut_vector.h"
00036 #endif
00037 
00038 class UT_Script;
00039 class UT_ScriptLibrary;
00040 
00041 class ABI_EXPORT UT_ScriptSniffer
00042 {
00043     friend class UT_ScriptLibrary;
00044 
00045 public:
00046     virtual ~UT_ScriptSniffer();
00047 
00048     // these you get for g_free
00049     inline bool supportsType (UT_ScriptIdType type) const { return m_type == type; }
00050     inline UT_ScriptIdType getType() const { return m_type; }
00051 
00052     // these you must override these
00053     virtual bool recognizeContents (const char * szBuf,
00054                                     UT_uint32 iNumbytes) const = 0;
00055     virtual bool recognizeSuffix (const char * szSuffix) const = 0;
00056     virtual bool getDlgLabels (const char ** szDesc,
00057                                const char ** szSuffixList,
00058                                UT_ScriptIdType * ft) const = 0;
00059     virtual UT_Error constructScript (UT_Script ** ppscript) const = 0;
00060 
00061 protected:
00062         UT_ScriptSniffer();
00063 
00064 private:
00065     // only UT_ScriptLibrary ever calls this
00066     inline void setType (UT_ScriptIdType type) { m_type = type; }
00067     UT_ScriptIdType m_type;
00068 };
00069 
00070 class ABI_EXPORT UT_Script
00071 {
00072 public:
00073     virtual UT_Error execute(const char * scriptName) = 0;
00074     virtual const UT_String& errmsg() const = 0;
00075     virtual ~UT_Script();
00076 
00077 protected:
00078     UT_Script();
00079 
00080 private:
00081     UT_Script(const UT_Script &); // no impl
00082     UT_Script& operator=(const UT_Script &); // no impl
00083 };
00084 
00085 class ABI_EXPORT UT_ScriptLibrary
00086 {
00087 public:
00088     UT_ScriptLibrary();
00089     virtual ~UT_ScriptLibrary();
00090 
00091     static UT_ScriptLibrary * instance();
00092 
00093     bool        enumerateDlgLabels(UT_uint32 ndx,
00094                                    const char ** pszDesc,
00095                                    const char ** pszSuffixList,
00096                                    UT_ScriptIdType * ft);
00097 
00098     UT_Error execute(const char * script, UT_ScriptIdType type = -1);
00099 
00100     UT_uint32 getNumScripts() const;
00101     void registerScript(UT_ScriptSniffer*);
00102     void unregisterScript(UT_ScriptSniffer*);
00103     void unregisterAllScripts();
00104 
00105     const UT_String& errmsg() const { return m_stErrMsg; }
00106 
00107 private:
00108     void errmsg(const UT_String& st) { m_stErrMsg = st; }
00109 
00110     UT_ScriptIdType typeForContents(const char * szBuf,
00111                                     UT_uint32 iNumbytes);
00112 
00113     UT_ScriptIdType typeForSuffix(const char * szSuffix);
00114     const char *          suffixesForType(UT_ScriptIdType ieft);
00115 
00116     UT_Error    constructScript(const char * szFilename,
00117                                 UT_ScriptIdType ieft,
00118                                 UT_Script ** ppscript,
00119                                 UT_ScriptIdType * pieft = NULL);
00120 
00121     UT_ScriptLibrary(const UT_ScriptLibrary&);
00122     UT_ScriptLibrary& operator=(const UT_ScriptLibrary&);
00123     static UT_ScriptLibrary * m_pInstance;
00124     friend void __dummy_method_dont_use(void);
00125 
00126     UT_GenericVector<UT_ScriptSniffer *>* mSniffers;
00127     UT_String m_stErrMsg;
00128 };
00129 
00130 #endif /* UT_SCRIPT_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1