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

ut_misc.h

Go to the documentation of this file.
00001 /* AbiSource Program Utilities
00002  * Copyright (C) 1998 AbiSource, Inc.
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 UTMISC_H
00021 #define UTMISC_H
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include "config.h"
00025 #endif
00026 
00027 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00028  * so even if it's commented out in-file that's still a lot of work for
00029  * the preprocessor to do...
00030  */
00031 #ifndef UT_TYPES_H
00032 #include "ut_types.h"
00033 #endif
00034 
00035 #ifndef UTVECTOR_H
00036 #include "ut_vector.h"
00037 #endif
00038 
00039 #include <string>
00040 
00041 class UT_Rect;
00042 class UT_String;
00043 class UT_UTF8String;
00044 class PP_AttrProp;
00045 
00046 
00047 // ----------------------------------------------------------------
00048 class ABI_EXPORT UT_Rect
00049 {
00050 public:
00051     UT_Rect();
00052     UT_Rect(UT_sint32 iLeft, UT_sint32 iTop, UT_sint32 iWidth, UT_sint32 iHeight);
00053     UT_Rect(const UT_Rect &);
00054     UT_Rect(const UT_Rect * r);
00055 
00056     bool containsPoint(UT_sint32 x, UT_sint32 y) const;
00057     void set(UT_sint32 iLeft, UT_sint32 iTop, UT_sint32 iWidth, UT_sint32 iHeight);
00058     bool intersectsRect(const UT_Rect * pRect) const;
00059     void unionRect( const UT_Rect *pRect);
00060     UT_sint32   left;
00061     UT_sint32   top;
00062     UT_sint32   width;
00063     UT_sint32   height;
00064 };
00065 
00066 // ----------------------------------------------------------------
00067 struct ABI_EXPORT UT_Point
00068 {
00069     UT_sint32   x;
00070     UT_sint32   y;
00071 };
00072 
00073 #define UT_MAX(A,B) (((A) > (B)) ? (A) : (B))
00074 #define UT_MIN(A,B) (((A) < (B)) ? (A) : (B))
00075 #define UT_ABS(A)   ( ((A) < 0) ? (-(A)) : (A) )
00076 
00077 std::string UT_pathSuffix(std::string path);
00078 bool         UT_addOrReplacePathSuffix(std::string & sPath, const char* sSuffix);
00079 
00080 bool UT_isWordDelimiter(UT_UCSChar currentChar, UT_UCSChar followChar, UT_UCSChar prevChar);
00081 
00085 ABI_EXPORT const gchar* UT_getAttribute(const gchar* name,
00086                                         const gchar** atts);
00087 
00092 ABI_EXPORT const gchar* UT_getAttribute( const gchar* name,
00093                                          const gchar** atts, const gchar* def );
00094 
00095 
00096 
00101 ABI_EXPORT bool isTrue( const char* s );
00102 
00103 
00104 
00105 ABI_EXPORT gchar ** UT_cloneAndDecodeAttributes (const gchar ** attrs);
00106 
00107 UT_sint32 signedHiWord(UT_uint32 dw);
00108 UT_sint32 signedLoWord(UT_uint32 dw);
00109 
00110 UT_GenericVector<UT_String*> * simpleSplit (const UT_String & str, char separator = ' ',
00111                          size_t max = 0 /* 0 == full split */);
00112 
00113 UT_uint32 UT_HeadingDepth(const char * szHeadName);
00114 
00115 /*
00116    The purpose of this class is to generate document-unique
00117    numerical identifiers; uniqueness is type-specific, i.e., id's of
00118    the different types generated by the class can overlap. Most of the
00119    time you probably will not want to use this class directly, but use
00120    the methods provided in PD_Document class.
00121 */
00122 
00123 #define UT_UID_INVALID 0xffffffff
00124 class ABI_EXPORT UT_UniqueId
00125 {
00126   public:
00127     UT_UniqueId();
00128     ~UT_UniqueId(){};
00129 
00130     enum idType
00131     {
00132         List = 0,
00133         Footnote,
00134         Endnote,
00135         Annotation,
00136         HeaderFtr,
00137         Image,
00138         Math,
00139         Embed,
00140         ODTCTSplit,
00141 
00142         /* must be last; for internal use only !*/
00143         _Last
00144     };
00145 
00146     UT_uint32 getUID(idType t);
00147     bool      setMinId(idType t, UT_uint32 iMin);
00148     bool      isIdUnique(idType t, UT_uint32 iId) const;
00149 
00150   private:
00151     UT_uint32 m_iID[(UT_uint32)_Last];
00152 };
00153 
00154 ABI_EXPORT bool UT_parseBool (const char * param, bool dfl);
00155 
00156 
00157 #if 0
00158 /*
00159    if your platform does not define timeval, turn on the following definitions
00160 */
00161 #include <time.h>
00162 
00163 typedef signed long suseconds_t;
00164 
00165 struct timeval
00166 {
00167     time_t           tv_sec;
00168     suseconds_t      tv_usec;
00169 };
00170 #endif
00171 
00177 void UT_gettimeofday(struct timeval *tv);
00178 
00179 typedef unsigned char UT_EthernetAddress[6];
00183 bool UT_getEthernetAddress(UT_EthernetAddress &a);
00184 
00185 class ABI_EXPORT UT_VersionInfo
00186 {
00187   public:
00188     UT_VersionInfo(UT_uint32 maj, UT_uint32 min, UT_uint32 mic, UT_uint32 nan)
00189         : m_iMajor(maj), m_iMinor(min), m_iMicro(mic), m_iNano(nan) {};
00190 
00191     UT_VersionInfo()
00192         : m_iMajor(0), m_iMinor(0), m_iMicro(0), m_iNano(0) {};
00193 
00194     UT_uint32 getMajor() const {return m_iMajor;}
00195     UT_uint32 getMinor() const {return m_iMinor;}
00196     UT_uint32 getMicro() const {return m_iMicro;}
00197     UT_uint32 getNano()  const {return m_iNano;}
00198 
00199     void set(UT_uint32 maj, UT_uint32 min, UT_uint32 mic, UT_uint32 nan)
00200         {m_iMajor = maj; m_iMinor = min; m_iMicro = mic; m_iNano = nan;}
00201 
00202     bool operator > (const UT_VersionInfo &v) const
00203         {
00204             if(m_iMajor > v.m_iMajor)
00205                 return true;
00206             if(m_iMajor < v.m_iMajor)
00207                 return false;
00208 
00209             if(m_iMinor > v.m_iMinor)
00210                 return true;
00211             if(m_iMinor < v.m_iMinor)
00212                 return false;
00213 
00214             if(m_iMicro > v.m_iMicro)
00215                 return true;
00216             if(m_iMicro < v.m_iMicro)
00217                 return false;
00218 
00219             if(m_iNano > v.m_iNano)
00220                 return true;
00221             if(m_iNano < v.m_iNano)
00222                 return false;
00223 
00224             return false;
00225         }
00226 
00227     const UT_UTF8String & getString() const;
00228 
00229 
00230   private:
00231     UT_uint32 m_iMajor;
00232     UT_uint32 m_iMinor;
00233     UT_uint32 m_iMicro;
00234     UT_uint32 m_iNano;
00235 };
00236 
00237 /*
00238    returns a copy of props which has all values (not names!) set to NULL; the caller must delete[] the returned pointer
00239    but not the contents
00240 
00241    this function reuses the property names from the original string, so if those are freed, the copy
00242    too becomes invalid !!!
00243 */
00244 const gchar ** UT_setPropsToNothing(const gchar ** props);
00245 
00246 const gchar ** UT_setPropsToValue(const gchar ** props, const gchar * value);
00247 
00248 ABI_EXPORT const gchar ** UT_splitPropsToArray(gchar * props);
00249 
00250 UT_uint64 UT_hash64(const char * p, UT_uint32 bytelen = 0);
00251 UT_uint32 UT_hash32(const char * p, UT_uint32 bytelen = 0);
00252 
00253 // Hack so we get AbiNativeWidget with an xp include
00254 #ifdef TOOLKIT_GTK_ALL
00255 #include <gtk/gtk.h>
00256 typedef GtkWidget AbiNativeWidget;
00257 #else
00258 // TODO maintainers please fix their platform
00259 typedef void AbiNativeWidget;
00260 #endif
00261 
00262 #endif /* UTMISC_H */

Generated on Wed May 22 2013 for AbiWord by  doxygen 1.7.1