diff options
Diffstat (limited to 'cosv')
60 files changed, 10217 insertions, 0 deletions
diff --git a/cosv/inc/cosv/bstream.hxx b/cosv/inc/cosv/bstream.hxx new file mode 100644 index 000000000000..0d27c438988a --- /dev/null +++ b/cosv/inc/cosv/bstream.hxx @@ -0,0 +1,150 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_BSTREAM_HXX +#define CSV_BSTREAM_HXX + +#include <string.h> +#include <cosv/string.hxx> + + +namespace csv +{ + + +enum seek_dir +{ + beg = 0, + cur = 1, + end = 2 +}; + + +class bistream +{ + public: + // LIFECYCLE + virtual ~bistream() {} + + // OPERATIONS + /// @return Number of actually read bytes. + uintt read( + void * out_pDest, + uintt i_nNrofBytes); + // INQUIRY + /** @return True, if already one try to read had failed. + There is no guarantee, that it returns true, if end of data + is just reached. + Though it will return false, if there is still somemething + to read. + */ + bool eod() const; + + private: + virtual uintt do_read( + void * out_pDest, + uintt i_nNrofBytes) = 0; + virtual bool inq_eod() const = 0; +}; + + +class bostream +{ + public: + // LIFECYCLE + virtual ~bostream() {} + + // OPERATIONS + /// @return Number of actually written bytes. + uintt write( + const void * i_pSrc, + uintt i_nNrofBytes); + /// @return Number of actually written bytes. + uintt write( + const char * i_pSrc ); + /// @return Number of actually written bytes. + uintt write( + const String & i_pSrc ); + private: + virtual uintt do_write( + const void * i_pSrc, + uintt i_nNrofBytes) = 0; +}; + + +class bstream : public bistream, + public bostream +{ + public: + uintt seek( + intt i_nDistanceFromBegin, + seek_dir i_eStartPoint = ::csv::beg ); + uintt position() const; + + private: + virtual uintt do_seek( + intt i_nDistance, + seek_dir i_eStartPoint = ::csv::beg ) = 0; + virtual uintt inq_position() const = 0; +}; + + +// IMPLEMENTATION +inline uintt +bistream::read( void * o_pDest, + uintt i_nNrofBytes) + { return do_read(o_pDest, i_nNrofBytes); } +inline bool +bistream::eod() const + { return inq_eod(); } + +inline uintt +bostream::write( const void * i_pSrc, + uintt i_nNrofBytes) + { return do_write( i_pSrc, i_nNrofBytes ); } +inline uintt +bostream::write( const char * i_sSrc ) + { return write( i_sSrc, strlen(i_sSrc) ); } +inline uintt +bostream::write( const String & i_sSrc ) + { return write( i_sSrc.c_str(), i_sSrc.length() ); } + +inline uintt +bstream::seek( intt i_nDistance, + seek_dir i_eStartPoint ) + { return do_seek( i_nDistance, i_eStartPoint ); } +inline uintt +bstream::position() const + { return inq_position(); } + + + +} // namespace csv + + +#endif + diff --git a/cosv/inc/cosv/comdline.hxx b/cosv/inc/cosv/comdline.hxx new file mode 100644 index 000000000000..99c036cfb271 --- /dev/null +++ b/cosv/inc/cosv/comdline.hxx @@ -0,0 +1,70 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_COMDLINE_HXX +#define CSV_COMDLINE_HXX +// KORR_DEPRECATED_3.0 +// Replace by cosv/commandline.hxx. + + +namespace csv +{ + +class CommandLine_Ifc +{ + public: + virtual ~CommandLine_Ifc() {} + + void Init( + int argc, + char * argv[] ); + void PrintUse() const; + bool CheckParameters() const; + + private: + virtual void do_Init( + int argc, + char * argv[] ) = 0; + + virtual void do_PrintUse() const = 0; + virtual bool inq_CheckParameters() const = 0; +}; + +inline void +CommandLine_Ifc::Init( int argc, + char * argv[] ) + { do_Init( argc, argv ); } +inline void +CommandLine_Ifc::PrintUse() const + { do_PrintUse(); } + +} // namespace csv + + + +#endif + diff --git a/cosv/inc/cosv/comfunc.hxx b/cosv/inc/cosv/comfunc.hxx new file mode 100644 index 000000000000..ce78c72d4656 --- /dev/null +++ b/cosv/inc/cosv/comfunc.hxx @@ -0,0 +1,125 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_COMFUNC_HXX +#define CSV_COMFUNC_HXX + +#include <stdlib.h> + + + + +namespace csv +{ + class String; + + +// min, max and range functions +template <class E> +inline E max(E in1, E in2); +template <class E> +inline E min(E in1, E in2); +template <class E> +inline bool in_range(E low, E val, E high); // return low <= val < high; + + +// string functions +inline const char * valid_str(const char * str); +inline bool no_str(const char * str); // return !str || !strlen(str) +intt count_chars(const char * str, char c); + + +// endian functions +template <class NUMTYPE> +void switch_endian( + NUMTYPE & o_rNumber, + const NUMTYPE & i_rNumber ); + +// Zeit-Typecasts +bool str2date(const char * str, int & out_day, int & out_month, int & out_year); +void date2str(String & out_Str, int day, int month, int year); +bool str2time(const char * str, int & out_hour, int & out_min, int & out_sec); +void time2str(String & out_Str, int hour, int min, int sec); + +class noncopyable +{ + protected: + noncopyable() {} + ~noncopyable() {} + private: + // Private to make copying impossible: + noncopyable(const noncopyable&); + noncopyable & operator=(const noncopyable&); +}; + + + + +// IMPLEMENTATION +template <class E> +inline E +max(E in1, E in2) { return in1 < in2 ? in2 : in1; } +template <class E> +inline E +min(E in1, E in2) { return in1 < in2 ? in1 : in2; } +template <class E> +inline bool +in_range(E low, E val, E high) { return low <= val AND val < high; } + +inline const char * +valid_str(const char * str) { return str != 0 ? str : ""; } +inline bool +no_str(const char * str) { return str != 0 ? *str == '\0' : true; } + + +template <class NUMTYPE> +void +switch_endian( NUMTYPE & o_rNumber, + const NUMTYPE & i_rNumber ) +{ + char * pFront = reinterpret_cast< char* >(&o_rNumber); + const char * pBack = reinterpret_cast< const char* >(&i_rNumber) + sizeof(NUMTYPE); + + for ( size_t p = 0; p < sizeof(NUMTYPE); --p ) + { + *pFront++ = *(--pBack); + } +} + + +} // namespace csv + + + + +#define NON_COPYABLE(xy) \ + private: xy(const xy &); xy & operator=(const xy &) + + + + +#endif diff --git a/cosv/inc/cosv/commandline.hxx b/cosv/inc/cosv/commandline.hxx new file mode 100644 index 000000000000..b5fd6a4e0cdc --- /dev/null +++ b/cosv/inc/cosv/commandline.hxx @@ -0,0 +1,180 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_COMMANDLINE_HXX +#define CSV_COMMANDLINE_HXX + +#include <cosv/string.hxx> + + + + +namespace csv +{ + +/** Does the standards in handling command line parameters. + + This class provides a default behaviour this way: + + * Each option can have several forms + + like: "-f" and "--file" + + which are identified by having the same id. + The option id is used when calling ->do_HandleOption(). + + * For each recognized option together with its parameters + ->do_HandleOption() is called. + + * For the first unrecognized argument ->do_HandleFreeArgument() is + called. + After the first unrecognized argument, ->do_HandleFreeArgument() + is called for all remaining arguments. + + @howtoderive + - Overwrite ->do_HandleOption() to act on all known options. + Overwrite ->do_HandleFreeArgument() to act on additional + arguments not connected to an option. +*/ +class CommandLine +{ + public: + // LIFECYCLE + virtual ~CommandLine() {} + + // OPERATIONS + bool Interpret( + int argc, + char * argv[] ); + // INQUIRY + const StringVector & + Arguments() const; + bool IsOk() const; + + protected: + CommandLine(); + void Add_Option( + intt i_id, + String i_text ); + void Set_Error(); + + private: + // public for use by struct commandline.cxx-anonymous::FindOptionByText; + struct OptionDescription + { + intt nId; + String sText; + + OptionDescription( + intt i_id, + String i_text ); + }; private: + + struct FindOptionByText; + + typedef std::vector<OptionDescription> OptionList; + typedef std::vector<StringVector::const_iterator> StringCIteratorList; + typedef std::vector<intt> OptionIdList; + + // Locals + void Get_Arguments( + int argc, + char * argv[] ); + intt Find_Option( + const String & i_text ) const; + bool Store_Argument( + const String & i_arg ); + void Find_OptionPoints(); + void Handle_FreeArguments( + StringVector::const_iterator + i_begin, + StringVector::const_iterator + i_end ); + + // Helpers for options included via file + bool Try2Include_Options( + const String & i_optionsFile ); + bool Include_Options( + const String & i_optionsFile ); + bool Load_Options( + StreamStr & o_text, + const String & i_optionsFile ); + + /** Handles an option found in the command line. + Needs to be overwritten. + + @return + The first argument within the range + i_next_argument .. i_comandLine_end that does not belong as a + parameter to the handled option. + */ + virtual StringVector::const_iterator + do_HandleOption( + intt i_id, + StringVector::const_iterator + i_paramsBegin, + StringVector::const_iterator + i_paramsEnd ) = 0; + /** Handles arguments on the command line that do not belong to + an option. + */ + virtual void do_HandleFreeArgument( + const String & i_argument ) = 0; + // DATA + OptionList aOptions; + + /// Used during and after ->GetArguments() + StringVector aCommandLine; + StringCIteratorList aOptionPoints; + OptionIdList aOptionIds; + bool bIsOk; +}; + + +inline const StringVector & +CommandLine::Arguments() const +{ + return aCommandLine; +} + +inline bool +CommandLine::IsOk() const +{ + return bIsOk; +} + +inline void +CommandLine::Set_Error() +{ + bIsOk = false; +} + + + + +} // namespace csv +#endif diff --git a/cosv/inc/cosv/csv_env.hxx b/cosv/inc/cosv/csv_env.hxx new file mode 100644 index 000000000000..d6feb055c0f2 --- /dev/null +++ b/cosv/inc/cosv/csv_env.hxx @@ -0,0 +1,154 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_CSV_ENV_HXX +#define CSV_CSV_ENV_HXX + + + +//******* Include c-language-types ************// +// size_t, wchar_t +#include <stdlib.h> + + + +//******* Builtin types of exact length ************// + +// Exact length builtin types +typedef signed char INT8; +typedef unsigned char UINT8; +typedef short INT16; +typedef unsigned short UINT16; +typedef long INT32; +typedef unsigned long UINT32; +typedef float REAL32; +typedef double REAL64; + + +// Additional builtin types +typedef INT32 intt; // standard sized integer. +typedef UINT32 uintt; // standard sized unsigned integer. +typedef REAL64 real; // standard sized real. + +// Constants +// --------- +// Zero-pointer for use in ellipsed (...) parameter lists which expect a +// pointer which may have another size than an int. +// Must be a define to be used in precompiled headers: +#define NIL ((void*)0) +// char '\0' +#define NULCH '\0' + + + +// Boolesche Operatoren +#define AND && +#define OR || +#define NOT ! + +// Macro for distinguishing dynamic allocated pointers from +// referencing pointers +#define DYN // Exact specification: DYN has to be used if and only if: + // 1. DYN specifies a class member pointer or reference variable and + // the class must free the referenced memory. + // 2. DYN specifies a pointer or reference (return-) parameter of a function + // and for in-parameters the function or its class + // must free the referenced memory, the parameter is then called + // a let-parameter. + // For out- and inout-parameters + // or return values the caller of the function hast to + // free the referenced memory. + // + // It is irrelevant who allocated the memory! + // + // DYN - variables use the prefixes "dp" or "dr" instead of "p" or "r". + + +//****** Assertions ******// + +namespace csv +{ +void PerformAssertion( + const char * condition, + const char * file, + unsigned line ); +} + +// Programming by contract +#ifndef CSV_NO_ASSERTIONS + +#ifdef CSV_USE_CSV_ASSERTIONS +#define csv_assert(x) ( (x) ? (void)(0) : ::csv::PerformAssertion( #x, __FILE__, __LINE__) ) +#else + +// Save NDEBUG state +#ifdef NDEBUG +#define CSV_CSV_ENV_HXX_HAD_NDEBUG +#undef NDEBUG +#endif + +#if OSL_DEBUG_LEVEL == 0 +#define NDEBUG +#endif +#include <assert.h> + +#define csv_assert(x) assert(x); + +// Restore NDEBUG state +#ifdef CSV_CSV_ENV_HXX_HAD_NDEBUG +#define NDEBUG +#else +#undef NDEBUG +#endif + +#endif + +#else // #ifndef CSV_NO_ASSERTIONS else + +#define csv_assert(x) + +#endif // end ifndef CSV_NO_ASSERTIONS else + + + +/* Additional Programming Conventions + +1. see above at "#define DYN" +2. function parameters get one of these prefixes: + - i_ := Function uses only the value, but must not change a referenced variable. + - o_ := Parameter is undefined until function has set it. + Parametere must be set by the function. + - io_ := Function may use and change the referenced variable. + - pass_ := Funktion may use and change the referenced variable and HAS TO free the + associated memory. +3. Global constants get the prefix 'C_', global variables the prefix 'G_'. +4. Static members end with an underscore '_'. + +*/ + + +#endif diff --git a/cosv/inc/cosv/csv_ostream.hxx b/cosv/inc/cosv/csv_ostream.hxx new file mode 100644 index 000000000000..7e657f875eb9 --- /dev/null +++ b/cosv/inc/cosv/csv_ostream.hxx @@ -0,0 +1,134 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_CSV_OSTREAM_HXX +#define CSV_CSV_OSTREAM_HXX + +// USED SERVICES + // BASE CLASSES + // COMPONENTS + // PARAMETERS + + + +#ifndef CSV_NO_IOSTREAMS + +#include <iostream> + + +namespace csv +{ + +typedef std::ios ios; +typedef std::ostream ostream; + +} // namespace csv + + +#else + +#include <cosv/tpl/dyn.hxx> + +namespace csv +{ + +class StreamStr; + +class ios +{ + public: + enum seek_dir + { + beg=0, + cur=1, + end=2 + }; +}; + +class ostream : public ios +{ + public: + typedef ostream self; + + virtual ~ostream(); + + self & operator<<( + const char * i_s ); + self & operator<<( + char i_c ); + self & operator<<( + unsigned char i_c ); + self & operator<<( + signed char i_c ); + + self & operator<<( + short i_n ); + self & operator<<( + unsigned short i_n ); + self & operator<<( + int i_n ); + self & operator<<( + unsigned int i_n ); + self & operator<<( + long i_n ); + self & operator<<( + unsigned long i_n ); + + self & operator<<( + float i_n ); + self & operator<<( + double i_n ); + + self & seekp( + intt i_nOffset, + seek_dir i_eStart = ios::beg ); + protected: + ostream( + uintt i_nStartSize ); + const StreamStr & Data() const; + + private: + Dyn<StreamStr> pData; +}; + + + +inline const StreamStr & +ostream::Data() const + { return *pData; } + + +} // namespace csv + + +#endif + + + + +#endif + diff --git a/cosv/inc/cosv/csv_precomp.h b/cosv/inc/cosv/csv_precomp.h new file mode 100644 index 000000000000..d6dd85c53084 --- /dev/null +++ b/cosv/inc/cosv/csv_precomp.h @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __CSV_PRECOMP_H_06071998__ +#define __CSV_PRECOMP_H_06071998__ + + + + +#define CSV_USE_CSV_ASSERTIONS +#include <cosv/csv_env.hxx> + +#include <cosv/comfunc.hxx> +#include <cosv/string.hxx> +#include <cosv/streamstr.hxx> +#include <cosv/std_outp.hxx> +#include <cosv/tpl/dyn.hxx> + + + + +#endif diff --git a/cosv/inc/cosv/datetime.hxx b/cosv/inc/cosv/datetime.hxx new file mode 100644 index 000000000000..ee773df66380 --- /dev/null +++ b/cosv/inc/cosv/datetime.hxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_DATETIME_HXX +#define CSV_DATETIME_HXX + + + +namespace csv +{ + + +class Date +{ + public: + Date(); + Date( + unsigned i_nDay, + unsigned i_nMonth, + unsigned i_nYear ); + + unsigned Day() const { return nData >> 24; } + unsigned Month() const { return (nData & 0x00FF0000) >> 16; } + unsigned Year() const { return nData & 0x0000FFFF; } + + static const Date & Null_(); + + private: + UINT32 nData; +}; + +class Time +{ + public: + Time(); + Time( + unsigned i_nHour, + unsigned i_nMinutes, + unsigned i_nSeconds = 0, + unsigned i_nSeconds100 = 0 ); + + unsigned Hour() const { return nData >> 24; } + unsigned Minutes() const { return (nData & 0x00FF0000) >> 16; } + unsigned Seconds() const { return (nData & 0x0000FF00) >> 8; } + unsigned Seconds100() const { return nData & 0x000000FF; } + + static const Time & Null_(); + + private: + UINT32 nData; +}; + + +} // namespace csv + + + + +#endif + diff --git a/cosv/inc/cosv/dirchain.hxx b/cosv/inc/cosv/dirchain.hxx new file mode 100644 index 000000000000..e62af1d1a8a4 --- /dev/null +++ b/cosv/inc/cosv/dirchain.hxx @@ -0,0 +1,180 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_DIRCHAIN_HXX +#define CSV_DIRCHAIN_HXX + + +// USED SERVICES + // BASE CLASSES + // COMPONENTS +#include <cosv/string.hxx> + // PARAMETERS +#include <cosv/csv_ostream.hxx> + +#include <cosv/persist.hxx> +#include <cosv/tpl/tpltools.hxx> + + + +namespace csv +{ + class bostream; + +namespace ploc +{ + + +class DirectoryChain +{ + public: + DirectoryChain(); + DirectoryChain( + const char * i_sPath, + bool i_bPathIsAlwaysDir = false, + const char * i_sDelimiter = Delimiter() ); + DirectoryChain( + const DirectoryChain & + i_rDC ); + ~DirectoryChain(); + + // OPERATORS + DirectoryChain & operator=( + const DirectoryChain & + i_rDC ); + DirectoryChain & operator+=( + const String & i_sName ); + DirectoryChain & operator+=( + const DirectoryChain & + i_rDC ); + DirectoryChain & operator-=( + uintt i_nLevelsUp ); + + // OPERATIONS + void Set( + const char * i_sPath, + bool i_bPathIsAlwaysDir = false, + const char * i_sDelimiter = Delimiter() ); + void PushFront( + const String & i_sName ); + void PushFront( + const DirectoryChain & + i_sPath ); + void PushBack( + const String & i_sName ); + void PushBack( + const DirectoryChain & + i_sPath ); + void PopFront( + uintt i_nCount = 1 ); + void PopBack( + uintt i_nCount = 1 ); + + // INQUIRY + uintt Size() const; + + StringVector::const_iterator + Begin() const; + StringVector::const_iterator + End() const; + + const String & Front() const; + const String & Back() const; + + void Get( + ostream & o_rPath, + const char * i_sDelimiter ) const; + void Get( + bostream & o_rPath, + const char * i_sDelimiter ) const; + private: + StringVector aPath; +}; + + +// IMPLEMENTATION +inline +DirectoryChain::DirectoryChain( const DirectoryChain & i_rDC ) + { PushBack(i_rDC); } + + // OPERATORS +inline DirectoryChain & +DirectoryChain::operator=( const DirectoryChain & i_rDC ) + { csv::erase_container(aPath); PushBack(i_rDC); return *this; } +inline DirectoryChain & +DirectoryChain::operator+=( const String & i_sName ) + { PushBack(i_sName); return *this; } +inline DirectoryChain & +DirectoryChain::operator+=( const DirectoryChain & i_rDC ) + { PushBack(i_rDC); return *this; } +inline DirectoryChain & +DirectoryChain::operator-=( uintt i_nLevelsUp ) + { PopBack(i_nLevelsUp); return *this; } +inline uintt +DirectoryChain::Size() const + { return aPath.size(); } + +inline StringVector::const_iterator +DirectoryChain::Begin() const + { return aPath.begin(); } +inline StringVector::const_iterator +DirectoryChain::End() const + { return aPath.end(); } +inline const String & +DirectoryChain::Front() const + { return aPath.empty() ? String::Null_() : aPath.front(); } +inline const String & +DirectoryChain::Back() const + { return aPath.empty() ? String::Null_() : aPath.back(); } + + +} // namespace ploc +} // namespace csv + + +inline csv::ostream & +operator<<( csv::ostream & o_rOut, + const csv::ploc::DirectoryChain & i_rSubPath ) +{ + i_rSubPath.Get(o_rOut, csv::ploc::Delimiter()); + return o_rOut; +} + +inline csv::bostream & +operator<<( csv::bostream & o_rOut, + const csv::ploc::DirectoryChain & i_rSubPath ) +{ + i_rSubPath.Get(o_rOut, csv::ploc::Delimiter()); + return o_rOut; +} + + + +#endif + + + diff --git a/cosv/inc/cosv/file.hxx b/cosv/inc/cosv/file.hxx new file mode 100644 index 000000000000..7039964769ad --- /dev/null +++ b/cosv/inc/cosv/file.hxx @@ -0,0 +1,137 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_FILE_HXX +#define CSV_FILE_HXX + +// USED SERVICES + // BASE CLASSES +#include <cosv/bstream.hxx> +#include <cosv/openclose.hxx> + // COMPONENTS +#include <stdio.h> +#include <cosv/string.hxx> + // PARAMETERS +#include <cosv/persist.hxx> +#include <cosv/ploc.hxx> + + +class FileStrategy; + + +namespace csv +{ + + +/** @task + File is a class representing a file. +*/ +class File : public bstream, + public OpenClose, + public ploc::Persistent +{ + public: + // LIFECYCLE + File( + uintt i_nMode = CFM_RW ); + File( + const ::csv::ploc::Path & + i_rLocation, + uintt i_nMode = CFM_RW ); + File( + const char * i_sLocation, + uintt in_nMode = CFM_RW ); + File( + const String & i_sLocation, + uintt in_nMode = CFM_RW ); + virtual ~File(); + + // OPERATIONS + bool Assign( + ploc::Path i_rLocation ); + bool Assign( + const char * i_sLocation ); + bool Assign( + const String & i_sLocation ); + // INQUIRY + uintt Mode() const; + + private: + enum E_LastIO + { + io_none = 0, + io_read, + io_write + }; + + // Interface bistream: + virtual uintt do_read( + void * out_pDest, + uintt i_nNrofBytes); + virtual bool inq_eod() const; + // Interface bostream: + virtual uintt do_write( + const void * i_pSrc, + uintt i_nNrofBytes); + // Interface bstream: + virtual uintt do_seek( + intt i_nDistance, + seek_dir i_eStartPoint = ::csv::beg ); + virtual uintt inq_position() const; + // Interface OpenClose: + virtual bool do_open( + uintt in_nOpenModeInfo ); + virtual void do_close(); + virtual bool inq_is_open() const; + // Interface Persistent: + virtual const ploc::Path & + inq_MyPath() const; + // DATA + ploc::Path aPath; + FILE * pStream; + + uintt nMode; /// RWMode, OpenMode and ShareMode. + E_LastIO eLastIO; +}; + + + +// IMPLEMENTATION + +inline uintt +File::Mode() const + { return nMode; } + + +} // namespace csv + + + + +#endif + + diff --git a/cosv/inc/cosv/mbstream.hxx b/cosv/inc/cosv/mbstream.hxx new file mode 100644 index 000000000000..0778d8333952 --- /dev/null +++ b/cosv/inc/cosv/mbstream.hxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_MBSTREAM_HXX +#define CSV_MBSTREAM_HXX + +// USED SERVICES + // BASE CLASSES +#include <cosv/bstream.hxx> + // COMPONENTS + // PARAMETERS + + +namespace csv +{ + +class mbstream : public bstream +{ + public: + // LIFECYCLE + mbstream( + uintt i_nSize); + ~mbstream(); + // OPERATIONS + void resize( + uintt i_nSize ); + // INQUIRY + uintt size() const; + const void * data() const; + + private: + // Interface bistream: + virtual uintt do_read( + void * out_pDest, + uintt i_nNrofBytes); + virtual bool inq_eod() const; + // Interface bostream: + virtual uintt do_write( + const void * i_pSrc, + uintt i_nNrofBytes); + // Interface bstream: + virtual uintt do_seek( + intt i_nDistance, + seek_dir i_eStartPoint = ::csv::beg ); + virtual uintt inq_position() const; + + // DYN + DYN char * dpOwnedMemorySpace; + uintt nSize; + uintt nCurPosition; +}; + + +// IMPLEMENTATION + +inline uintt +mbstream::size() const + { return nSize; } +inline const void * +mbstream::data() const + { return dpOwnedMemorySpace; } + + +} // namespace csv + + +#endif + + diff --git a/cosv/inc/cosv/openclose.hxx b/cosv/inc/cosv/openclose.hxx new file mode 100644 index 000000000000..2f3ade89440a --- /dev/null +++ b/cosv/inc/cosv/openclose.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_OPENCLOSE_HXX +#define CSV_OPENCLOSE_HXX + + +namespace csv +{ + +// Open modes for storages: +enum E_RWMode +{ + rwDefault = 0x0000, // Keep old settings. If there are none, set default. + rwRead = 0x0001, // Reads only + rwWrite = 0x0002, // Writes only + rwReadWrite = 0x0003 // Reads and writes. +}; + +enum E_OpenMode +{ + omCreateIfNecessary = 0x0000, // Creates a new file only, if file does not exist. + omCreateNot = 0x0010, // Open fails, if file does not exist. + omCreate = 0x0020 // Existing file will be deleted. +}; +enum E_ShareMode +{ + shmShareNot = 0x0000, // Allow others nothing + shmShareRead = 0x0004, // Allow others to read + shmShareAll = 0x000C // Allow others to read and write +}; + +/** Constants for filemode combinations + These combinations are the only ones, guaranteed to be supported. +*/ +const UINT32 CFM_RW = rwReadWrite; +const UINT32 CFM_CREATE = + static_cast< UINT32 >(rwReadWrite) | static_cast< UINT32 >(omCreate); +const UINT32 CFM_READ = + static_cast< UINT32 >(rwRead) | static_cast< UINT32 >(omCreateNot) | + static_cast< UINT32 >(shmShareRead); + + + +class OpenClose +{ + public: + virtual ~OpenClose() {} + + bool open( + UINT32 in_nOpenModeInfo = 0 ); /// Combination of values of E_RWMode and E_ShareMode und E_OpenMode. 0 := Keep existing mode. + void close(); + + bool is_open() const; + + private: + virtual bool do_open( + UINT32 in_nOpenModeInfo ) = 0; + virtual void do_close() = 0; + virtual bool inq_is_open() const = 0; +}; + + + +class OpenCloseGuard +{ + public: + OpenCloseGuard( + OpenClose & i_rOpenClose, + UINT32 i_nOpenModeInfo = 0 ); + ~OpenCloseGuard(); + operator bool() const; + + private: + // Forbidden: + OpenCloseGuard(OpenCloseGuard&); + OpenCloseGuard & operator=(OpenCloseGuard&); + + // DATA + OpenClose & rOpenClose; +}; + + +// IMPLEMENTATION + +inline bool +OpenClose::open( UINT32 i_nOpenModeInfo ) + { return do_open(i_nOpenModeInfo); } +inline void +OpenClose::close() + { do_close(); } +inline bool +OpenClose::is_open() const + { return inq_is_open(); } + +inline +OpenCloseGuard::OpenCloseGuard( OpenClose & i_rOpenClose, + UINT32 i_nOpenModeInfo ) + : rOpenClose(i_rOpenClose) + { rOpenClose.open(i_nOpenModeInfo); } +inline +OpenCloseGuard::~OpenCloseGuard() + { if (rOpenClose.is_open()) rOpenClose.close(); } +inline +OpenCloseGuard::operator bool() const + { return rOpenClose.is_open(); } + + + + +} // namespace csv + + + + + + +#endif + + diff --git a/cosv/inc/cosv/persist.hxx b/cosv/inc/cosv/persist.hxx new file mode 100644 index 000000000000..11b198fe6ac2 --- /dev/null +++ b/cosv/inc/cosv/persist.hxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_PERSIST_HXX +#define CSV_PERSIST_HXX + + +// USED SERVICES + // BASE CLASSES + // COMPONENTS +#include <cosv/string.hxx> + // PARAMETERS + + +namespace csv +{ +namespace ploc +{ + +class Path; + + +inline const char * +Delimiter() +{ +#ifdef WNT + return "\\"; +#elif defined(UNX) + return "/"; +#else +#error For using csv::ploc there has to be defined: WNT or UNX. +#endif +} + + + +class Persistent +{ + public: + virtual ~Persistent() {} + + const Path & MyPath() const; + /// @return all pathes without completing delimiter, even directories. + const char * StrPath() const; + bool Exists() const; + + protected: + Persistent(); + void InvalidatePath(); + + private: + virtual const Path & + inq_MyPath() const = 0; + // DATA + mutable StreamStr sPath; +}; + + + +// IMPLEMENTATION + +inline +Persistent::Persistent() + : sPath(30) { } +inline const Path & +Persistent::MyPath() const + { return inq_MyPath(); } +inline void +Persistent::InvalidatePath() + { sPath.clear(); } + + + +} // namespace csv +} // namespace ploc + + +#endif + + + diff --git a/cosv/inc/cosv/ploc.hxx b/cosv/inc/cosv/ploc.hxx new file mode 100644 index 000000000000..f00321d81948 --- /dev/null +++ b/cosv/inc/cosv/ploc.hxx @@ -0,0 +1,129 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_PLOC_HXX +#define CSV_PLOC_HXX + +// USED SERVICES +#include <cosv/string.hxx> +#include <cosv/plocroot.hxx> +#include <cosv/dirchain.hxx> +#include <cosv/tpl/dyn.hxx> +#include <cosv/csv_ostream.hxx> + + + + +namespace csv +{ + class bostream; + +namespace ploc +{ + class Root; + + +/** Represents a path in the file system. + + The path can be relative or absolute and in Unix- or Windows-syntax. +*/ +class Path +{ + public: + + // LIFECYCLE + explicit Path( + const char * i_sPath = ".", /// Dirs have to be ended with a '\\ or '/'. + bool i_bPathIsAlwaysDir = false, /// This overrides a missing Delimiter at the end of the i_sPath, if true. + const char * i_sDelimiter = Delimiter() ); + Path( + const Path & i_rPath ); + ~Path(); + // OPERATORS + Path & operator=( + const Path & i_rPath ); + // OPERATIONS + void Set( + const char * i_sPath, + bool i_bPathIsAlwaysDir = false, + const char * i_sDelimiter = Delimiter() ); + void SetFile( // If there is already a file, that is exchanged. + const String & i_sName ); + // INQUIRY + const Root & RootDir() const { return *pRoot; } + const DirectoryChain & + DirChain() const { return aPath; } + const String & File() const { return sFile; } + const char * FileExtension() const; + bool IsValid() const; + bool IsDirectory() const { return sFile.length() == 0; } + bool IsFile() const { return sFile.length() > 0; } + + /// Directories have a delimiter at the end, files not. + void Get( + ostream & o_rPath ) const; + /// Directories have a delimiter at the end, files not. + void Get( + bostream & o_rPath ) const; + // ACCESS + DirectoryChain & DirChain() { return aPath; } + + private: + Dyn<Root> pRoot; + DirectoryChain aPath; + String sFile; +}; + + + + +} // namespace ploc +} // namespace csv + + + +/// Directories produce a delimiter at the end, files not. +inline csv::ostream & +operator<<( csv::ostream & o_rOut, + const csv::ploc::Path & i_rPath ) +{ + i_rPath.Get(o_rOut); + return o_rOut; +} + +/// Directories produce a delimiter at the end, files not. +inline csv::bostream & +operator<<( csv::bostream & o_rOut, + const csv::ploc::Path & i_rPath ) +{ + i_rPath.Get(o_rOut); + return o_rOut; +} + + + +#endif diff --git a/cosv/inc/cosv/ploc_dir.hxx b/cosv/inc/cosv/ploc_dir.hxx new file mode 100644 index 000000000000..2e133307ea72 --- /dev/null +++ b/cosv/inc/cosv/ploc_dir.hxx @@ -0,0 +1,118 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_PLOCDIR_HXX +#define CSV_PLOCDIR_HXX + + +// USED SERVICES + // BASE CLASSES +#include <cosv/persist.hxx> + // COMPONENTS +#include <cosv/ploc.hxx> + // PARAMETERS + +namespace csv +{ +namespace ploc +{ + +class DirectoryChain; + +enum E_Recursivity +{ + flat, + recursive +}; + +class Directory : public Persistent +{ + public: + // LIFECYCLE + Directory(); + Directory( + const Path & i_rLocation ); + Directory( + const char * i_rLocation ); + Directory( + const String & i_rLocation ); + Directory( + const Directory & i_rDir ); + virtual ~Directory(); + + // OPERATORS + Directory & operator+=( + const String & i_sName ); + Directory & operator+=( + const DirectoryChain & + i_sDirChain ); + Directory & operator-=( + uintt i_nLevels ); + + // OPERATIONS + bool PhysicalCreate( + bool i_bCreateParentsIfNecessary = true ) const; + + // INQUIRY + void GetContainedDirectories( + StringVector & o_rResult ) const; + /** @param i_sFilter + Currently only filters of the form "*.ending" or "*.*" + (the default) are processed correctly under UNIX. Under WNT this + restriction does not apply. + */ + void GetContainedFiles( + StringVector & o_rResult, + const char * i_sFilter = "*.*", + E_Recursivity i_eRecursivity = flat ) const; + private: + // Interface Peristent: + virtual const Path & + inq_MyPath() const; + + // Locals: + /** @return + true, if parent(!) directory exists or could be created. + false, if this is a root directory. + */ + bool Check_Parent() const; + bool PhysicalCreate_Dir( + const char * i_sStr ) const; + // DATA + Path aPath; +}; + + + +} // namespace ploc +} // namespace csv + + + +#endif + + diff --git a/cosv/inc/cosv/plocroot.hxx b/cosv/inc/cosv/plocroot.hxx new file mode 100644 index 000000000000..e83327fab876 --- /dev/null +++ b/cosv/inc/cosv/plocroot.hxx @@ -0,0 +1,80 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_PLOCROOT_HXX +#define CSV_PLOCROOT_HXX + + +// USED SERVICES + // BASE CLASSES + // COMPONENTS +#include <cosv/string.hxx> + // PARAMETERS +#include <cosv/csv_ostream.hxx> +#include <cosv/persist.hxx> + + +namespace csv +{ + +class bostream; + + +namespace ploc +{ + + +class Root +{ + public: + virtual ~Root(); + + static DYN Root * Create_( + const char * & o_sPathAfterRoot, + const char * i_sPath, + const char * i_sDelimiter = Delimiter() ); + + virtual void Get( /// Does not add a '\0' at the end, + ostream & o_rPath ) const = 0; + virtual void Get( /// Does not add a '\0' at the end. + bostream & so_rPath ) const = 0; + virtual DYN Root * CreateCopy() const = 0; + virtual const char * + OwnDelimiter() const = 0; +}; + + + +} // namespace ploc +} // namespace csv + + + +#endif + + + diff --git a/cosv/inc/cosv/std_outp.hxx b/cosv/inc/cosv/std_outp.hxx new file mode 100644 index 000000000000..705aa8312a02 --- /dev/null +++ b/cosv/inc/cosv/std_outp.hxx @@ -0,0 +1,136 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_STD_OUTP_HXX +#define CSV_STD_OUTP_HXX + +// USED SERVICES + // BASE CLASSES + // COMPONENTS +#include <cosv/csv_ostream.hxx> + // PARAMETERS + + + + +namespace csv +{ + +#ifdef CSV_NO_IOSTREAMS +class redirect_out : public ostream +{ + public: + virtual ~redirect_out() {} + + void re_endl() { do_re_endl(); } + void re_flush() { do_re_flush(); } + + static void set_( + redirect_out & o_rStdOut, + redirect_out & o_rStdErr ) + { pStdOut_ = &o_rStdOut; + pStdErr_ = &o_rStdErr; } + + static redirect_out & + std_() { return *pStdOut_; } + static redirect_out & + err_() { return *pStdErr_; } + static bool useme_() { return pStdOut_ != 0; } + + private: + virtual void do_re_endl() = 0; + virtual void do_re_flush() = 0; + + // DATA + static redirect_out * + pStdOut_; + static redirect_out * + pStdErr_; +}; +#endif // defined(CSV_NO_IOSTREAMS) + + +inline ostream & +Cout() +{ + +#ifndef CSV_NO_IOSTREAMS +// return redirect_out::useme_() +// ? (ostream&)( redirect_out::std_() ) +// : (ostream&)( std::cout ); + return (ostream&)( std::cout ); +#else + csv_assert( redirect_out::useme_() ); + return redirect_out::std_(); +#endif +} + +inline ostream & +Cerr() +{ +#ifndef CSV_NO_IOSTREAMS +// return redirect_out::useme_() +// ? (ostream&)( redirect_out::err_() ) +// : (ostream&)( std::cerr ); + return (ostream&)( std::cerr ); +#else + csv_assert( redirect_out::useme_() ); + return redirect_out::err_(); +#endif +} + + + +typedef void (*F_FLUSHING_FUNC)(ostream&, bool, int*); + +void Endl( ostream&, bool, int* ); + +void Flush( ostream&, bool, int* ); + + +} // namespace csv + + + +inline csv::ostream & +operator<<( csv::ostream & io_rStream, + csv::F_FLUSHING_FUNC i_fFlushingFunc ) +{ +#ifndef CSV_NO_IOSTREAMS +// (*i_fFlushingFunc)( io_rStream, csv::redirect_out::useme_(), 0 ); + (*i_fFlushingFunc)( io_rStream, false, 0 ); +#else + csv_assert( csv::redirect_out::useme_() ); + (*i_fFlushingFunc)( io_rStream, true, 0 ); +#endif + return io_rStream; +} + + +#endif + + diff --git a/cosv/inc/cosv/str_types.hxx b/cosv/inc/cosv/str_types.hxx new file mode 100644 index 000000000000..1eb9d5ad9729 --- /dev/null +++ b/cosv/inc/cosv/str_types.hxx @@ -0,0 +1,94 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef COSV_STR_TYPES_HXX +#define COSV_STR_TYPES_HXX + + +namespace csv +{ + +/** Provides some generally used constants. +*/ +struct str +{ + public: + typedef ::size_t position; + typedef ::size_t size; + + enum constants + { + npos = position(-1), + maxsize = size(-1) + }; + + enum insert_mode + { + overwrite = 0, + insert = 1 + }; +}; + + +/** Is used for string comparisons. + + @collab String + @collab various csv::compare(...) functions +*/ +class CharOrder_Table +{ + public: + /** @precond + Parameter i_pCharWeightsArray + must have size of 256. + */ + CharOrder_Table( + const int * i_pCharWeightsArray ); + + /** @return the weight of the char i_c. + @precond + Even with unusual implementations, where char has more than 8 bit, + there must be true: 0 <= i_c < 256. + */ + int operator()( + char i_c ) const; + private: + int cWeights[256]; +}; + + +// IMPLEMENTATION + +inline int +CharOrder_Table::operator()( char i_c ) const + { return cWeights[ UINT8(i_c) ]; } + + + +} // namespace csv + +#endif diff --git a/cosv/inc/cosv/streamstr.hxx b/cosv/inc/cosv/streamstr.hxx new file mode 100644 index 000000000000..d61fbc6edf22 --- /dev/null +++ b/cosv/inc/cosv/streamstr.hxx @@ -0,0 +1,391 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_STREAMSTR_HXX +#define CSV_STREAMSTR_HXX + +// BASE CLASSES +#include <cosv/bstream.hxx> +// USED SERVICES +#include <cosv/str_types.hxx> +#include <string.h> + + + + +namespace csv +{ + class String; + + +void c_str(); // Dummy needed for StreamStr::operator<<(StreamStr::F_CSTR); + + +/** A string buffer class for all kinds of string manipulation. +*/ +class StreamStr : public bostream +{ + public: + typedef StreamStr self; + + typedef str::size size_type; + typedef str::position position_type; + typedef intt seek_type; + typedef str::insert_mode insert_mode; + + typedef const char * const_iterator; + typedef char * iterator; + + typedef void (*F_CSTR)(); + + + /** Represents an area within a string. + */ + struct Area + { + typedef str::size size_type; + + Area( + const char * i_str = "", + size_type i_nLength = str::maxsize ) + : sStr(i_str), + nLength( i_nLength == str::maxsize + ? strlen(i_str) + : i_nLength ) {} + const char * sStr; + size_type nLength; + }; + + // LIFECYCLE + StreamStr( + size_type i_nCapacity ); + StreamStr( + const char * i_sInitStr, + size_type i_nCapacity ); /// Only used if > strlen(i_sInitStr). + StreamStr( + size_type i_nGuessedCapacity, + const char * str1, // [!= 0] + const char * str2, // [!= 0] + ... ); // Has to end with NIL . + StreamStr( + csv::bstream & i_source ); + /// Copies also insert_mode and current position. + StreamStr( + const self & i_rOther ); + ~StreamStr(); + + // OPERATORS + /// Copies also insert_mode and current position. + self & operator=( + const self & i_rOther ); + + self & operator<<( + const char * i_s ); + self & operator<<( + const String & i_s ); + self & operator<<( + char i_c ); + self & operator<<( + unsigned char i_c ); + self & operator<<( + signed char i_c ); + + self & operator<<( + short i_n ); + self & operator<<( + unsigned short i_n ); + self & operator<<( + int i_n ); + self & operator<<( + unsigned int i_n ); + self & operator<<( + long i_n ); + self & operator<<( + unsigned long i_n ); + + self & operator<<( + float i_n ); + self & operator<<( + double i_n ); + + /** This operator is used to finish a sequence of streaming + oeprators by returning the c-string of the complete string. + + @return The same as ->c_str(). + + @example + csv::StreamStr s(100); + const char * + fullname = s << qualifier() << "::" << name() << csv::c_str; + */ + const char * operator<<( + F_CSTR i_f ); + + const char & operator[]( + position_type i_nPosition ) const; + char & operator[]( + position_type i_nPosition ); + + // OPERATIONS + void resize( + size_type i_nMinimumCapacity ); + + void clear(); + void swap( + StreamStr & io_swap ); + + /** Sets start point for the next operator<<() call. + if the intended position is not reachable, nothing happens. + */ + self & seekp( + seek_type i_nCount, + seek_dir i_eDirection = ::csv::beg ); + self & reset() { return seekp(0); } + /** Sets the insertion mode of all and only the operator<<() calls. + + Default is str::overwrite: + str::overwrite: seekp() always sets the cur end of the string. + operator<<() calls push the end of the string forward. + str::insert: seekp() only sets the insertion point. + operator<<() calls insert their text at the tellp() + position and keep the rest of the string. tellp() is + then after the inserted text, on the beginning of the + rest of the string. + */ + self & set_insert_mode( + insert_mode i_eMode ); + + void push_front( + const char * i_str ); + void push_front( + char i_c ); + void push_back( + const char * i_str ); + void push_back( + char i_c ); + void pop_front( + size_type i_nCount ); + void pop_back( + size_type i_nCount ); + + /// Works like operator<<(). Does the same as Perl's join(). + self & operator_join( + std::vector<String>::const_iterator + i_rBegin, + std::vector<String>::const_iterator + i_rEnd, + const char * i_sLink ); + /// Works like operator<<() + self & operator_add_substr( + const char * i_sText, + size_type i_nLength ); + /// Works like operator<<() + self & operator_add_token( + const char * i_sText, + char i_cDelimiter ); + /// Works like operator<<() + self & operator_read_line( + bstream & i_src ); + + void strip_front( + char i_cToRemove ); + void strip_back( + char i_cToRemove ); + void strip_frontback( + char i_cToRemove ); + void strip_front_whitespace(); /// removes space, tab and crlf. + void strip_back_whitespace(); + void strip_frontback_whitespace(); + + /** @precond i_begin is valid + @precond i_end is valid + @precond i_end >= i_begin + */ + void remove( + iterator i_begin, + iterator i_end ); + void replace( + position_type i_nStart, + size_type i_nSize, + Area i_aReplacement ); + + void replace_all( + char i_cCarToSearch, + char i_cReplacement ); + void replace_all( + Area i_aStrToSearch, + Area i_aReplacement ); + + StreamStr & to_lower( + position_type i_nStart = 0, + size_type i_nLength = str::maxsize ); + StreamStr & to_upper( + position_type i_nStart = 0, + size_type i_nLength = str::maxsize ); + + // INQUIRY + const char * c_str() const; + const char * data() const; + + bool empty() const; + size_type size() const; + size_type length() const; + + size_type capacity() const; + + position_type tellp() const; + + const_iterator begin() const; + const_iterator cur() const; + const_iterator end() const; + + size_type token_count( + char i_cSplit ) const; + String token( + position_type i_nNr, /// Starting with 0. + char i_cSpli ) const; + + // ACCESS + iterator begin(); + iterator cur(); + iterator end(); + + private: + // Interface bostream + virtual UINT32 do_write( + const void * i_pSrc, + UINT32 i_nNrofBytes); + // Locals + void ProvideAddingSize( + size_type i_nSize2Add ); + /// Resizes with the factor 2.0 (under 128), 1.5 or until i_nMinimumCapacity, whatever is bigger. + void Resize( + size_type i_nMinimumCapacity = 0 ); + void Advance( + size_type i_nAddedSize ); + void MoveData( + char * i_pStart, + char * i_pEnd, + seek_type i_nDiff ); + // DATA + size_type nCapacity1; /// Capacity of characters to contain + 1 for terminating 0. + DYN char * dpData; + char * pEnd; + char * pCur; + insert_mode eMode; +}; + + + +class StreamStrLock +{ + public: + StreamStrLock( + uintt i_nMinimalSize ); + ~StreamStrLock(); + + StreamStr & operator()() { return *pStr; } + + private: + StreamStr * pStr; +}; + +/** Splits a string into tokens by whitespace. + + The tokens are added to the end of o_list. +*/ +void Split( + std::vector<String> & + o_list, + const char * i_text ); +inline void Join( + StreamStr & o_text, + std::vector<String> & + i_list, + const char * i_sLink = " "); + +// IMPLEMENTATION + +inline const char * +StreamStr::operator<<( F_CSTR ) + { return dpData; } +inline void +StreamStr::clear() + { pEnd = pCur = dpData; *pEnd = '\0'; } +inline const char * +StreamStr::c_str() const + { return dpData; } +inline const char * +StreamStr::data() const + { return dpData; } +inline bool +StreamStr::empty() const + { return dpData == pEnd; } +inline StreamStr::size_type +StreamStr::size() const + { return pEnd - dpData; } +inline StreamStr::size_type +StreamStr::length() const + { return size(); } +inline StreamStr::size_type +StreamStr::capacity() const + { return nCapacity1-1; } +inline StreamStr::position_type +StreamStr::tellp() const + { return size_type(pCur-dpData); } +inline StreamStr::const_iterator +StreamStr::begin() const + { return dpData; } +inline StreamStr::const_iterator +StreamStr::cur() const + { return pCur; } +inline StreamStr::const_iterator +StreamStr::end() const + { return pEnd; } +inline StreamStr::iterator +StreamStr::begin() + { return dpData; } +inline StreamStr::iterator +StreamStr::cur() + { return pCur; } +inline StreamStr::iterator +StreamStr::end() + { return pEnd; } + +inline void +Join( StreamStr & o_text, + std::vector<String> & i_list, + const char * i_sLink ) +{ + o_text.operator_join(i_list.begin(),i_list.end(),i_sLink); +} + + + + +} // namespace csv +#endif diff --git a/cosv/inc/cosv/string.hxx b/cosv/inc/cosv/string.hxx new file mode 100644 index 000000000000..bba6af8e6b3b --- /dev/null +++ b/cosv/inc/cosv/string.hxx @@ -0,0 +1,579 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef COSV_STRING_HXX +#define COSV_STRING_HXX + +// USED SERVICES +#include <cosv/stringdata.hxx> +#include <cosv/str_types.hxx> +#include <string.h> +#include <cosv/csv_ostream.hxx> +#include <vector> + + + + +namespace csv +{ + + +/** The Simple String: + It is used to just hold short to middle long texts as + data, which are constant at most times. They are reference + counted, so they are space efficient and have constant time + copy semantics. + + For all compare() functions the return value is like in strcmp(). + + @attention + The present version of this class is NOT thread safe. +*/ + + +class String +{ + public: + typedef String self; + + typedef str::size size_type; + typedef str::position position_type; + + typedef const char * const_iterator; + + // LIFECYCLE + String(); + + /// Intentionally not explicit, smooth casting is intended. + String( + const char * i_str ); + /// @precond i_nLength <= strlen(i_str) or i_nLength == str::maxsize. + String( + const char * i_str, + size_type i_nLength ); + /** @precond i_nLength == str::maxsize + || i_nStartPosition+i_nLength <= i_rStr.Size(). + */ + String( + const self & i_rStr, + position_type i_nStartPosition, + size_type i_nLength ); + /** @precond i_itBegin and i_itEnd are in the same valid + memory-area, such that zero to finite times repetition of + ++i_itBegin leads to i_itBegin == i_itEnd. + */ + String( + const_iterator i_itBegin, + const_iterator i_itEnd ); + + String( + const self & i_rStr ); + + ~String(); + // OPERATORS + self & operator=( + const self & i_rStr ); + self & operator=( + const char * i_str ); + + operator const char * () const; + + bool operator==( + const self & i_rStr ) const; + bool operator!=( + const self & i_rStr ) const; + bool operator<( + const self & i_rStr ) const; + bool operator>( + const self & i_rStr ) const; + bool operator<=( + const self & i_rStr ) const; + bool operator>=( + const self & i_rStr ) const; + + // OPERATIONS + void clear(); + + void swap( + self & i_rStr ); + + /** @precond i_nLength == str::maxsize + || i_nStartPosition+i_nLength <= i_rStr.Size(). + */ + void assign( + const self & i_rStr, + position_type i_nStartPosition, + size_type i_nLength ); + void assign( + const char * i_str ); + /// @precond i_nLength == str::maxsize OR i_nLength < strlen(i_str) . + void assign( + const char * i_str, + size_type i_nLength ); + /// Create a string consisting of a sequence of i_nCount times the same char. + void assign( + size_type i_nCount, + char i_c ); + /** @precond i_itBegin and i_itEnd are in the same valid + memory-area, such that zero to finite times repetition of + ++i_itBegin leads to i_itBegin == i_itEnd. + */ + void assign( + const_iterator i_itBegin, + const_iterator i_itEnd ); + + // INQUIRY + const char * c_str() const; + const char * data() const; + + bool empty() const; + size_type size() const; + size_type length() const; + + const char & char_at( + position_type i_nPosition ) const; + + const_iterator begin() const; + + /// This is inefficient, so shouldn't be used within loops. + const_iterator end() const; + + int compare( + const self & i_rStr ) const; + int compare( + const CharOrder_Table & + i_rOrder, + const self & i_rStr ) const; + + self substr( + position_type i_nStartPosition = 0, + size_type i_nLength = str::maxsize ) const; + + /** @param i_strToSearch [i_strToSearch != 0] + i_strToSearch == "" will return npos. + */ + position_type find( + const char * i_strToSearch, + position_type i_nSearchStartPosition = 0 ) const; + position_type find( + char i_charToSearch, + position_type i_nSearchStartPosition = 0 ) const; + +//*********** Not yet implemented *********************// + position_type rfind( + const char * i_strToSearch, + position_type i_nSearchStartPosition = str::npos ) const; + position_type rfind( + char i_charToSearch, + position_type i_nSearchStartPosition = str::npos ) const; + + position_type find_first_not_of( + const char * i_strToSearch, + position_type i_nSearchStartPosition = 0 ) const; + position_type find_first_not_of( + char i_charToSearch, + position_type i_nSearchStartPosition = 0 ) const; + + position_type find_last_not_of( + const char * i_strToSearch, + position_type i_nSearchStartPosition = str::npos ) const; + position_type find_last_not_of( + char i_charToSearch, + position_type i_nSearchStartPosition = str::npos ) const; +//*********** end - not yet implemented *****************// + + static const self & Null_(); + static const char & Nulch_(); + + private: + struct S_Data + { + S_Data(); + /// @precond i_nValidLength <= strlen(i_sData) or i_nValidLength == str::maxsize. + explicit S_Data( + const char * i_sData, + size_type i_nValidLength = str::maxsize ); + ~S_Data(); + + const S_Data * Acquire() const; + + /// Deletes this, if nCount becomes 0. + void Release() const; + + StringData<char> aStr; + mutable UINT32 nCount; + + private: + // Forbidden functions, because this is a refcounted structure. + S_Data(const S_Data&); + S_Data & operator=(const S_Data&); + }; + + // Locals + const StringData<char> & + Str() const; + + // DATA + const S_Data * pd; +}; + + +//********** Global compare functions ***************// + + //*** Natural order, no substrings + +inline int compare( + const String & i_s1, + const String & i_s2 ); +inline int compare( + const String & i_s1, + const char * i_s2 ); +inline int compare( + const char * i_s1, + const String & i_s2 ); +inline int compare( + const char * i_s1, + const char * i_s2 ); + + //*** Natural order, substrings + +int compare( + const String & i_s1, + csv::str::position i_nStartPosition1, + const char * i_s2, + csv::str::size i_nLength ); +int compare( + const char * i_s1, + const String & i_s2, + csv::str::position i_nStartPosition2, + csv::str::size i_nLength ); +inline int compare( + const char * i_s1, + const char * i_s2, + csv::str::size i_nLength ); + + //*** Defined order, no substrings + +inline int compare( + const CharOrder_Table & i_rOrder, + const String & i_s1, + const char * i_s2 ); +inline int compare( + const CharOrder_Table & i_rOrder, + const char * i_s1, + const String & i_s2 ); +int compare( + const CharOrder_Table & i_rOrder, + const char * i_s1, + const char * i_s2 ); + + //*** Defined order, substrings + +int compare( + const CharOrder_Table & i_rOrder, + const String & i_s1, + csv::str::position i_nStartPosition1, + const char * i_s2, + csv::str::size i_nLength2 ); +int compare( + const CharOrder_Table & i_rOrder, + const char * i_s1, + const String & i_s2, + csv::str::position i_nStartPosition2, + csv::str::size i_nLength ); +int compare( + const CharOrder_Table & i_rOrder, + const char * i_s1, + const char * i_s2, + csv::str::size i_nLength ); + + +} // namespace csv + + + + +//****************** global comparation operators *********************// + +inline bool operator==( + const csv::String & i_s1, + const char * i_s2 ); +inline bool operator!=( + const csv::String & i_s1, + const char * i_s2 ); +inline bool operator<( + const csv::String & i_s1, + const char * i_s2 ); +inline bool operator>( + const csv::String & i_s1, + const char * i_s2 ); +inline bool operator<=( + const csv::String & i_s1, + const char * i_s2 ); +inline bool operator>=( + const csv::String & i_s1, + const char * i_s2 ); + +inline bool operator==( + const char * i_s1, + const csv::String & i_s2 ); +inline bool operator!=( + const char * i_s1, + const csv::String & i_s2 ); +inline bool operator<( + const char * i_s1, + const csv::String & i_s2 ); +inline bool operator>( + const char * i_s1, + const csv::String & i_s2 ); +inline bool operator<=( + const char * i_s1, + const csv::String & i_s2 ); +inline bool operator>=( + const char * i_s1, + const csv::String & i_s2 ); + + +//****************** global stream operators *********************// + + +inline csv::ostream & +operator<<( csv::ostream & o_rOut, + const csv::String & i_rSrc ); + + + + +// IMPLEMENTATION +namespace csv +{ + + +inline const StringData<char> & +String::Str() const +{ return pd->aStr; } + + +inline const char & +String::char_at( position_type i_nPosition ) const +{ if ( i_nPosition < Str().Size() ) + return Str().Data()[i_nPosition]; + return Nulch_(); +} + +inline bool +String::operator==( const self & i_rStr ) const +{ return compare(i_rStr) == 0; } + +inline bool +String::operator!=( const self & i_rStr ) const +{ return compare(i_rStr) != 0; } + +inline bool +String::operator<( const self & i_rStr ) const +{ return compare(i_rStr) < 0; } + +inline bool +String::operator>( const self & i_rStr ) const +{ return compare(i_rStr) > 0; } + +inline bool +String::operator<=( const self & i_rStr ) const +{ return compare(i_rStr) <= 0; } + +inline bool +String::operator>=( const self & i_rStr ) const +{ return compare(i_rStr) >= 0; } + +inline void +String::clear() +{ operator=( String::Null_() ); } + +inline const char * +String::c_str() const +{ return Str().Data(); } + +inline +String::operator const char * () const +{ return c_str(); } + +inline const char * +String::data() const +{ return c_str(); } + +inline String::size_type +String::size() const +{ return Str().Size(); } + +inline bool +String::empty() const +{ return size() == 0; } + +inline String::size_type +String::length() const +{ return size(); } + +inline String::const_iterator +String::begin() const +{ return data(); } + +inline String::const_iterator +String::end() const +{ return data() + size(); } + + + +//****************** global compare-functions ********************// +inline int +compare( const String & i_s1, + const String & i_s2 ) +{ return i_s1.compare(i_s2); } + +inline int +compare( const String & i_s1, + const char * i_s2 ) +{ return strcmp(i_s1.c_str(), i_s2); } + +inline int +compare( const char * i_s1, + const String & i_s2 ) +{ return strcmp(i_s1, i_s2.c_str()); } + +inline int +compare( const char * i_s1, + const char * i_s2 ) +{ return strcmp(i_s1, i_s2); } + +inline int +compare( const char * i_s1, + const char * i_s2, + str::size i_nLength ) +{ return strncmp( i_s1, i_s2, i_nLength ); } + +inline int +compare( const CharOrder_Table & i_rOrder, + const String & i_s1, + const char * i_s2 ) +{ return compare( i_rOrder, i_s1.c_str(), i_s2 ); } + +inline int +compare( const CharOrder_Table & i_rOrder, + const char * i_s1, + const String & i_s2 ) +{ return compare( i_rOrder, i_s1, i_s2.c_str() ); } + + +} // namespace csv + + +inline bool +operator==( const csv::String & i_s1, + const char * i_s2 ) +{ return csv::compare( i_s1, i_s2 ) == 0; } + +inline bool +operator!=( const csv::String & i_s1, + const char * i_s2 ) +{ return csv::compare( i_s1, i_s2 ) != 0; } + +inline bool +operator<( const csv::String & i_s1, + const char * i_s2 ) +{ return csv::compare( i_s1, i_s2 ) < 0; } + +inline bool +operator>( const csv::String & i_s1, + const char * i_s2 ) +{ return csv::compare( i_s1, i_s2 ) > 0; } + +inline bool +operator<=( const csv::String & i_s1, + const char * i_s2 ) +{ return csv::compare( i_s1, i_s2 ) <= 0; } + +inline bool +operator>=( const csv::String & i_s1, + const char * i_s2 ) +{ return csv::compare( i_s1, i_s2 ) >= 0; } + + +inline bool +operator==( const char * i_s1, + const csv::String & i_s2 ) +{ return csv::compare( i_s1, i_s2 ) == 0; } + +inline bool +operator!=( const char * i_s1, + const csv::String & i_s2 ) +{ return csv::compare( i_s1, i_s2 ) != 0; } + +inline bool +operator<( const char * i_s1, + const csv::String & i_s2 ) +{ return csv::compare( i_s1, i_s2 ) < 0; } + +inline bool +operator>( const char * i_s1, + const csv::String & i_s2 ) +{ return csv::compare( i_s1, i_s2 ) > 0; } + +inline bool +operator<=( const char * i_s1, + const csv::String & i_s2 ) +{ return csv::compare( i_s1, i_s2 ) <= 0; } + +inline bool +operator>=( const char * i_s1, + const csv::String & i_s2 ) +{ return csv::compare( i_s1, i_s2 ) >= 0; } + + + //************ global stream operators **************// + + +inline csv::ostream & +operator<<( csv::ostream & o_rOut, + const csv::String & i_rSrc ) + { o_rOut << i_rSrc.c_str(); return o_rOut; } + + + + + +//****************** typedefs *********************// + +namespace csv +{ + +typedef std::vector<String> StringVector; + +} + + + + +#endif diff --git a/cosv/inc/cosv/stringdata.hxx b/cosv/inc/cosv/stringdata.hxx new file mode 100644 index 000000000000..fec8ed0126f6 --- /dev/null +++ b/cosv/inc/cosv/stringdata.hxx @@ -0,0 +1,135 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef COSV_STRINGDATA_HXX +#define COSV_STRINGDATA_HXX + + +#include <cosv/str_types.hxx> + + + +namespace csv +{ + +/** @tpl CHAR + The expression CHAR(0) has to be valid. +*/ +template <class CHAR> +class StringData +{ + public: + typedef StringData self; + + typedef str::size size_type; + typedef str::position position_type; + + // LIFECYCLE + StringData(); + /** @precond i_pData != 0 + @precond i_nValidLength <= strlen(i_pData) + */ + StringData( + const CHAR * i_pData, + size_type i_nValidLength ); + ~StringData(); + // OPERATORS + + // OPERATIONS + + // INQUIRY + const CHAR * Data() const; + + /** @returns the allocated number of CHAR. + This may be different from the number of bytes. + There is actually allocated one more CHAR, + which is guaranteed to be CHAR(0) in all circumstances. + */ + size_type Size() const; + + private: + /* Because this is used only within a refcounted structure, + these functions are forbidden - at least yet. + */ + StringData(const self&); + self & operator=(const self&); + + // DATA + DYN CHAR * dpData; + size_type nSize; /// The allocated size - 1 (for the finishing 0). +}; + + + +// IMPLEMENTATION + +template <class CHAR> +StringData<CHAR>::StringData() + : dpData( new CHAR[1] ), + nSize(0) +{ + *dpData = CHAR(0); +} + +template <class CHAR> +StringData<CHAR>::StringData( const CHAR * i_pData, + size_type i_nValidLength ) + : dpData( new CHAR[i_nValidLength + 1] ), + nSize(i_nValidLength) +{ + memcpy( dpData, i_pData, i_nValidLength * sizeof(CHAR) ); + dpData[nSize] = CHAR(0); +} + +template <class CHAR> +StringData<CHAR>::~StringData() +{ + delete [] dpData; +} + +template <class CHAR> +const CHAR * +StringData<CHAR>::Data() const +{ + return dpData; +} + +template <class CHAR> +typename StringData<CHAR>::size_type +StringData<CHAR>::Size() const +{ + return nSize; +} + + + +} // namespace csv + + +#endif + + diff --git a/cosv/inc/cosv/tpl/dyn.hxx b/cosv/inc/cosv/tpl/dyn.hxx new file mode 100644 index 000000000000..ab305b264ae8 --- /dev/null +++ b/cosv/inc/cosv/tpl/dyn.hxx @@ -0,0 +1,238 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_DYN_HXX +#define CSV_DYN_HXX + + + + +namespace csv +{ + + +/** Dyn owns an object on the heap, which will be automatically + deleted in its D'tor. + + Dyn's main purpose is for class members on the heap: + You can't forget to delete them in the D'tor. Constness will be transfered + to the hold object. + + Dyn forbids the CopyC'tor and operator=(). So you can't incidentally + run into problems with compiler defined CopyC'tor or operator=() of the + owning class. If you need those, you have to define them explicitely - as + you should do anyway with all classes, that own members on the heap. + + Dyn also works with incomplete types. + You only need to write + class DX; + but needn't include #include <DX>.hxx. + This is a difference to std::auto_ptr, where it is not absolutely clear + if it is allowed to use it with incomplete types. + + You can also use Dyn within function bodies, to make them exception safe. + + @attention + If you use Dyn with an incomplete type, the owning class needs to + define a non-inline D'tor. Else the compiler will complain. +*/ +template <class DX> +class Dyn +{ + public: + // LIFECYCLE + /// From now on, let_dpObject is owned by this Dyn-object. + explicit Dyn( + DX * let_dpObject = 0); + ~Dyn(); + // OPERATORS + /** This deletes a prevoiusly existing dpObject! + From now on, let_dpObject is owned by this Dyn-object. + */ + Dyn<DX> & operator=( + DX * let_dpObject); + /// @return true, if any valid object is hold, false else. + operator bool() const; + + const DX * operator->() const; + DX * operator->(); + + const DX & operator*() const; + DX & operator*(); + + // OPERATIONS + /** @return The hold object on the heap. + + @ATTENTION + The caller of the function is responsible to delete + the returned object + + @postcond + this->dpObject == 0. + */ + DX * Release(); + + // INQUIRY + /// Shorthand for operator->(), if implicit overloading of -> can not be used. + const DX * Ptr() const; + + // ACCESS + /// Shorthand for operator->(), if implicit overloading of -> can not be used. + DX * Ptr(); + /// So const objects can return mutable pointers to the owned object. + DX * MutablePtr() const; + + private: + /* Does NOT set dpObject to zero! Because it is only used + internally in situations where dpObject is set immediately + after. + */ + void Delete(); + + /** Forbidden function! + ------------------- + Help ensure, that classes with + dynamic pointers use a selfdefined copy constructor + and operator=(). If the default versions of these + functions are used, the compiler will throw an error. + **/ + Dyn( const Dyn<DX> & ); + /** Forbidden function! + ------------------- + Help ensure, that classes with + dynamic pointers use a selfdefined copy constructor + and operator=(). If the default versions of these + functions are used, the compiler will throw an error. + **/ + Dyn<DX> & operator=( const Dyn<DX> & ); + + // DATA + /// An owned heap object. Needs to be deleted by this class. + DX * dpObject; +}; + + + + +// IMPLEMENTATION +template <class DX> +void +Dyn<DX>::Delete() +{ + if (dpObject != 0) + delete dpObject; +} + +template <class DX> +inline +Dyn<DX>::Dyn( DX * let_dpObject ) + : dpObject(let_dpObject) {} + +template <class DX> +inline +Dyn<DX>::~Dyn() +{ Delete(); } + + +template <class DX> +inline Dyn<DX> & +Dyn<DX>::operator=( DX * let_dpObject ) +{ + if ( dpObject == let_dpObject ) + return *this; + + Delete(); + dpObject = let_dpObject; + return *this; +} + +template <class DX> +inline +Dyn<DX>::operator bool() const +{ return dpObject != 0; } + +template <class DX> +inline +const DX * +Dyn<DX>::operator->() const +{ return dpObject; } + +template <class DX> +inline DX * +Dyn<DX>::operator->() +{ return dpObject; } + +template <class DX> +inline const DX & +Dyn<DX>::operator*() const +{ csv_assert(dpObject != 0); + return *dpObject; +} + +template <class DX> +inline DX & +Dyn<DX>::operator*() +{ csv_assert(dpObject != 0); + return *dpObject; +} + +template <class DX> +inline DX * +Dyn<DX>::Release() +{ DX * ret = dpObject; + dpObject = 0; + return ret; +} + +template <class DX> +inline const DX * +Dyn<DX>::Ptr() const +{ return dpObject; } + +template <class DX> +inline DX * +Dyn<DX>::Ptr() +{ return dpObject; } + +template <class DX> +inline DX * +Dyn<DX>::MutablePtr() const +{ return dpObject; } + +} // namespace csv + + + + +#ifndef CSV_HIDE_DYN +#define Dyn ::csv::Dyn +#endif + + + + +#endif diff --git a/cosv/inc/cosv/tpl/funcall.hxx b/cosv/inc/cosv/tpl/funcall.hxx new file mode 100644 index 000000000000..03ff8a3bba55 --- /dev/null +++ b/cosv/inc/cosv/tpl/funcall.hxx @@ -0,0 +1,307 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_TPL_FUNCALL_HXX +#define CSV_TPL_FUNCALL_HXX + +// BASE CLASSES +#include <algorithm> + + + + +namespace csv +{ +namespace func +{ + + +/** @concept "csv:: Function Objects" + + A set of function objects that can be generated from any kind of + function or member function with none or one parameter by the + helper function ->make_func(). + + Naming Scheme + ============= + + The naming scheme consists of three variables + f - the kind of function + p - the parameter of the function + c - call operator() of the function object with these arguments + + Each of those may have the following values: + f: + f - free, no owning class + c - const member function of a class + m - modifying member function of a class + p: + n - no parameter + c - const parameter by reference + m - modifyable parameter by reference, + v - parameter by value + c: + n - none + o - the owning object on which the function shall be called + a - the argument of the function + b - both, the object on which the function shall be called + and the argument of the function + + Which gives the following 35 possible combinations: + ff_pn_cn + ff_pc_cn + ff_pc_ca + ff_pm_cn + ff_pm_ca + ff_pv_cn + ff_pv_ca + + fc_pn_cn + fc_pn_co + fc_pc_cn + fc_pc_co + fc_pc_ca + fc_pc_cb + fc_pm_cn + fc_pm_co + fc_pm_ca + fc_pm_cb + fc_pv_cn + fc_pv_co + fc_pv_ca + fc_pv_cb + + fm_pn_cn + fm_pn_co + fm_pc_cn + fm_pc_co + fm_pc_ca + fm_pc_cb + fm_pm_cn + fm_pm_co + fm_pm_ca + fm_pm_cb + fm_pv_cn + fm_pv_co + fm_pv_ca + fm_pv_cb + + These function objects are complicate to handle, so they can be created + with the overloaded function + <function_object> csv::make_func(<function_type>, <argument_types>); + + For the rare, but possible case that the owning class and the function + argument have the same type, these clarifying variations to make_func() + can be used: + make_func_callwith_obj(), make_func_callwith_arg(). +*/ + + +/** Function object. + + @concept ->"csv::func Function Objects" + @see csv::make_func() +*/ +template <class R> +struct ff_pn_cn +{ + typedef R result_type; + typedef R (* function_type )(); + + R operator()() const + { return (*f)(); } + + ff_pn_cn( + function_type i_f) + : f(i_f) {} + private: + function_type f; +}; + + +/** Function object. + + @concept ->"csv::func Function Objects" + @see csv::make_func() +*/ +template <class R, class C> +struct fc_pn_co +{ + typedef R result_type; + typedef R (C::* function_type )() const; + + R operator()( + const C & i_c ) const + { return (i_c.*f)(); } + + fc_pn_co( + function_type i_f) + : f(i_f) {} + private: + function_type f; +}; + + + +/** Function object. + + @concept ->"csv::func Function Objects" + @see csv::make_func() +*/ +template <class R, class C, class P> +struct fc_pm_co +{ + typedef R result_type; + typedef R (C::* function_type )(P&) const; + + R operator()( + const C & i_c ) const + { return (i_c.*f)(p); } + + fc_pm_co( + function_type i_f, + P & i_p) + : f(i_f), p(i_p) {} + private: + function_type f; + P & p; +}; + + + + + + + +} // namespace func + + +/** Creates a function object of type ff_pn_cn. + @concept ->"csv::func Function Objects" +*/ +template <class R> +inline func::ff_pn_cn<R> +make_func( R(*i_f)() ) +{ + return func::ff_pn_cn<R>(i_f); +} + +///** Creates a function object of type ff_py_cn. +// @concept ->"csv::func Function Objects" +//*/ +//template <class R, class P> +//inline func::ff_py_cn<R,P> +//make_func( R(*i_f)(P), P i_p ) +//{ +// return func::ff_py_cn<R,A>(i_f, i_p); +//} +// +///** Creates a function object of type ff_py_ca. +// @concept ->"csv::func Function Objects" +//*/ +//template <class R, class P> +//inline func::ff_py_ca<R,P> +//make_func( R(*i_f)(P) ) +//{ +// return func::ff_py_ca<R,P>(i_f); +//} + + +/** Creates a function object of type fc_pn_co. + @concept ->"csv::func Function Objects" +*/ +template <class R, class C> +inline func::fc_pn_co<R,C> +make_func( R(C::*i_f)() const ) +{ + return func::fc_pn_co<R,C>(i_f); +} + + + +/** Creates a function object of type fc_pm_co. + @concept ->"csv::func Function Objects" +*/ +template <class R, class C, class P> +inline func::fc_pm_co<R,C,P> +make_func( R(C::*i_f)(P &) const, P & i_p) +{ + return func::fc_pm_co<R,C,P>(i_f, i_p); +} + + + +/* Because std::for_each is defined as a non-modifying algorithm + it is redefined here. It is also provided for containers. +*/ + +template <class I, class F> +F +for_each(I i_itBegin, I i_itEnd, F io_functionToBeCalled) +{ + for (I it = i_itBegin; it != i_itEnd; ++it) + { + io_functionToBeCalled(*it); + } + return io_functionToBeCalled; +} + +template <class C, class F> +F +for_each_in(const C & i_container, F io_functionToBeCalled) +{ + typename C::const_iterator const + itEnd = i_container.end(); + for ( typename C::const_iterator it = i_container.begin(); + it != itEnd; + ++it ) + { + io_functionToBeCalled(*it); + } + return io_functionToBeCalled; +} + +template <class C, class F> +F +for_each_in(C & i_container, F io_functionToBeCalled) +{ + typename C::iterator const + itEnd = i_container.end(); + for ( typename C::iterator it = i_container.begin(); + it != itEnd; + ++it ) + { + io_functionToBeCalled(*it); + } + return io_functionToBeCalled; +} + + + + +} // namespace csv +#endif diff --git a/cosv/inc/cosv/tpl/processor.hxx b/cosv/inc/cosv/tpl/processor.hxx new file mode 100644 index 000000000000..fc9a8277568a --- /dev/null +++ b/cosv/inc/cosv/tpl/processor.hxx @@ -0,0 +1,183 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_TPL_PROCESSOR_HXX +#define CSV_TPL_PROCESSOR_HXX + +// USED SERVICES + + + + +namespace csv +{ + + +/** Implements an acyclic visitor pattern. This is the abstract + base for the classes doing the work (the "visitors"). +*/ +class ProcessorIfc +{ + public: + virtual ~ProcessorIfc() {} +}; + + + +/** Implements an acyclic visitor pattern. This is the abstract + base for the classes to be processed (the "visitables"). +*/ +class ConstProcessorClient +{ + public: + virtual ~ConstProcessorClient() {} + + void Accept( + ProcessorIfc & io_processor ) const + { do_Accept(io_processor); } + private: + virtual void do_Accept( + ProcessorIfc & io_processor ) const = 0; +}; + +/** Implements an acyclic visitor pattern. This is the abstract + base for the classes to be processed (the "visitables"). +*/ +class ProcessorClient +{ + public: + virtual ~ProcessorClient() {} + + void Accept( + ProcessorIfc & io_processor ) + { do_Accept(io_processor); } + private: + virtual void do_Accept( + ProcessorIfc & io_processor ) = 0; +}; + + + + + +/** Typed base for "visitor" classes, leaving the visited + object const. + + @see ProcessorIfc + @see Processor<> +*/ +template <typename X, typename R = void> +class ConstProcessor +{ + public: + virtual ~ConstProcessor() {} + + R Process( + const X & i_object ) + { return do_Process(i_object ); } + private: + virtual R do_Process( + const X & i_object ) = 0; +}; + + +/** Typed base for "visitor" classes which may change the visited + object. + + @see ProcessorIfc + @see ConstProcessor<> +*/ +template <typename X, typename R = void> +class Processor +{ + public: + virtual ~Processor() {} + + R Process( + X & i_object ) + { return do_Process(i_object ); } + private: + virtual R do_Process( + X & i_object ) = 0; +}; + + +template <class C> +inline void +CheckedCall( ProcessorIfc & io_processor, + const C & i_client ) +{ + ConstProcessor<C> * + pProcessor = dynamic_cast< csv::ConstProcessor<C> * > + (&io_processor); + if (pProcessor != 0) + pProcessor->Process(i_client); +} + +template <class C> +inline void +CheckedCall( ProcessorIfc & io_processor, + C & io_client ) +{ + Processor<C> * + pProcessor = dynamic_cast< csv::Processor<C> * > + (&io_processor); + if (pProcessor != 0) + pProcessor->Process(io_client); +} + +template <class C> +inline void +AssertedCall( ProcessorIfc & io_processor, + const C & i_client ) +{ + ConstProcessor<C> * + pProcessor = dynamic_cast< csv::ConstProcessor<C> * > + (&io_processor); + csv_assert( pProcessor != 0 + && "csv::AssertedCall() failed. Processed object did not match processor." ); + pProcessor->Process(i_client); +} + +template <class C> +inline void +AssertedCall( ProcessorIfc & io_processor, + C & io_client ) +{ + Processor<C> * + pProcessor = dynamic_cast< csv::Processor<C> * > + (&io_processor); + csv_assert( pProcessor != 0 + && "csv::AssertedCall() failed. Processed object did not match processor." ); + pProcessor->Process(io_client); +} + + + + +} // namespace csv +#endif diff --git a/cosv/inc/cosv/tpl/range.hxx b/cosv/inc/cosv/tpl/range.hxx new file mode 100644 index 000000000000..ea6ce84fa480 --- /dev/null +++ b/cosv/inc/cosv/tpl/range.hxx @@ -0,0 +1,191 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_RANGE_HXX +#define CSV_RANGE_HXX + +#include <cstring> // for std::size_t + + + + +namespace csv +{ + + +/** Represents a range of integer or iterator values. + + @tpl T + Has to be assignable, add- and subtractable. That is: + either it is + - an integral type + - or a random access iterator. +*/ +template <class T> +class range +{ + public: + typedef T element_type; /// Provided for generic programming. + typedef range<T> self; + + // LIFECYCLE + range( + T i_inclusiveLowerBorder, + T i_exclusiveUpperBorder ); + ~range(); + // INQUIRY + T begin() const; + T end() const; + std::size_t size() const; + + bool contains( + T i_value ) const; + bool contains( + const self & i_other ) const; + bool overlaps( + const self & i_other ) const; + /// @return i_other.begin() - this->end() + long distance_to( + const self & i_other ) const; + private: + // DATA + T nBegin; + T nEnd; +}; + + +template <class T> +inline range<T> +make_range(T i1, T i2) +{ + return range<T>(i1, i2); +} + +template <class T> +inline range<typename T::const_iterator> +range_of(const T & i_container) +{ + return make_range( i_container.begin(), + i_container.end() + ); +} + +template <class T> +inline range<typename T::iterator> +range_of(T & io_container) +{ + return make_range( io_container.begin(), + io_container.end() + ); +} + + + + + +// IMPLEMENTATION + +template <class T> +range<T>::range( T i_inclusiveLowerBorder, + T i_exclusiveUpperBorder ) + : nBegin(i_inclusiveLowerBorder), + nEnd(i_exclusiveUpperBorder) +{ + csv_assert( nBegin <= nEnd + && "Invalid parameters for range<> constructor."); +} + +template <class T> +range<T>::~range() +{ +} + +template <class T> +inline T +range<T>::begin() const +{ + return nBegin; +} + +template <class T> +inline T +range<T>::end() const +{ + return nEnd; +} + +template <class T> +inline std::size_t +range<T>::size() const +{ + csv_assert( nBegin <= nEnd + && "Invalid range limits in range<>::size()."); + return static_cast<std::size_t>( end() - begin() ); +} + +template <class T> +bool +range<T>::contains(T i_value ) const +{ + return begin() <= i_value + && i_value < end(); +} + +template <class T> +bool +range<T>::contains(const self & i_other) const +{ + // This is subtle, because this would be wrong: + // begin() <= i_other.begin() + // && i_other.end() <= end(); + // An empty range that begins and starts at my end() + // must not be contained. + + return contains(i_other.begin()) + && i_other.end() <= end(); +} + +template <class T> +bool +range<T>::overlaps(const self & i_other) const +{ + return contains(i_other.begin()) + || i_other.contains(begin()); +} + +template <class T> +long +range<T>::distance_to(const self & i_other) const +{ + return i_other.begin() - end(); +} + + + + +} // namespace csv +#endif diff --git a/cosv/inc/cosv/tpl/swelist.hxx b/cosv/inc/cosv/tpl/swelist.hxx new file mode 100644 index 000000000000..0a56fae1e16e --- /dev/null +++ b/cosv/inc/cosv/tpl/swelist.hxx @@ -0,0 +1,369 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_SWELIST_HXX +#define CSV_SWELIST_HXX + +// USED SERVICES + // BASE CLASSES + // COMPONENTS + // PARAMETERS +#include <cosv/tpl/dyn.hxx> + + +namespace csv +{ + + +template <class XX> +class SweListElement +{ + public: + typedef SweListElement<XX> self; + + SweListElement( + const XX & in_aObj ) + : aObj(in_aObj), pNext(0) {} + + const XX & Obj() const { return aObj; } + XX & Obj() { return aObj; } + self * Next() const { return pNext; } + + void SetNext( + self * i_pNext ) + { pNext = i_pNext; } + private: + XX aObj; + self * pNext; +}; + + + +template <class XX> class SweListIterator; +template <class XX> class SweListCIterator; + + +template <class XX> +class SweList +{ + public: + // TYPES + typedef SweList<XX> self; + typedef XX value_type; + typedef SweListIterator<XX> iterator; + typedef SweListCIterator<XX> const_iterator; + private: + typedef SweListElement<XX> elem; + + public: + // LIFECYCLE + SweList() : pTop(0), pTail(0) {} + ~SweList() { erase_all(); } + // OPERATIONS + void push_front( + const XX & i_aObj ); + void pop_front(); + void push_back( + const XX & i_aObj ); + void erase_all(); + + // INQUIRY + const_iterator begin() const { return pTop; } + iterator begin() { return pTop; } + const_iterator end() const { return (elem*)0; } + iterator end() { return (elem*)0; } + const XX & front() const { return pTop->Obj(); } + XX & front() { return pTop->Obj(); } + const XX & back() const { return pTail->Obj(); } + XX & back() { return pTail->Obj(); } + + bool empty() const { return pTop == 0; } + uintt size() const; + + + private: + // Forbiddden methods. + SweList( + const self & i_rList ); + self & operator=( + const self & i_rList ); + + // DATA + DYN elem * pTop; + elem * pTail; +}; + +template <class XX> +class SweList_dyn +{ + public: + // TYPES + typedef SweList_dyn<XX> self; + typedef SweListElement< XX* > elem; + typedef SweListIterator< XX* > iterator; + + // LIFECYCLE + SweList_dyn() : pTop(0), pTail(0) {} + ~SweList_dyn() { erase_all(); } + // OPERATIONS + void push_front( + XX * i_pObj ); + void push_back( + XX * i_pObj ); + void pop_front(); + void erase_all(); + + // INQUIRY + iterator begin() const { return pTop; } + iterator end() const { return (elem*)0; } + XX * front() const { return pTop->Obj(); } + XX * back() const { return pTail->Obj(); } + + bool empty() const { return pTop == 0; } + uintt size() const; + + private: + // Forbiddden methods. + SweList_dyn( + const self & i_rList ); + self & operator=( + const self & i_rList ); + + DYN elem * pTop; + elem * pTail; +}; + + + + +template<class XX> +class SweListIterator +{ + public: + typedef SweListIterator<XX> self; + typedef SweListElement<XX> elem; + + SweListIterator( + elem * i_pElem = 0) + : pElem(i_pElem) { } + + // OPERATORS + XX & operator*() const { return pElem->Obj(); } + self & operator++() { if (pElem != 0) pElem = pElem->Next(); + return *this; } + bool operator==( + const self & i_rIter ) const + { return pElem == i_rIter.pElem; } + bool operator!=( + const self & i_rIter ) const + { return pElem != i_rIter.pElem; } + private: + friend class SweListCIterator<XX>; + + elem * pElem; +}; + +template<class XX> +class SweListCIterator +{ + public: + typedef SweListCIterator<XX> self; + typedef SweListElement<XX> elem; + + SweListCIterator( + const elem * i_pElem = 0) + : pElem(i_pElem) { } + + // OPERATORS + self & operator=( + const SweListIterator<XX> & + i_rIter ) + { pElem = i_rIter.pElem; return *this; } + + const XX & operator*() const { return pElem->Obj(); } + self & operator++() { if (pElem != 0) pElem = pElem->Next(); + return *this; } + bool operator==( + const self & i_rIter ) const + { return pElem == i_rIter.pElem; } + bool operator!=( + const self & i_rIter ) const + { return pElem != i_rIter.pElem; } + private: + const elem * pElem; +}; + +// Implementierung + +template <class XX> +void +SweList<XX>::push_front( const XX & i_aObj ) +{ + DYN elem * dpNew = new elem(i_aObj); + dpNew->SetNext(pTop); + pTop = dpNew; + if (pTail == 0) + pTail = pTop; +} + +template <class XX> +void +SweList<XX>::push_back( const XX & i_aObj) +{ + if (pTail != 0) + { + pTail->SetNext(new elem(i_aObj)); + pTail = pTail->Next(); + } + else + { + pTop = pTail = new elem(i_aObj); + } +} + +template <class XX> +void +SweList<XX>::pop_front() +{ + if (pTop != 0) + { + elem * pDel = pTop; + pTop = pTop->Next(); + delete pDel; + if (pTop == 0) + pTail = 0; + } +} + +template <class XX> +uintt +SweList<XX>::size() const +{ + uintt ret = 0; + for ( const_iterator iter = begin(); + iter != end(); + ++iter ) + { + ++ret; + } + return ret; +} + + +template <class XX> +void +SweList<XX>::erase_all() +{ + for (pTail = pTop ; pTop != 0; pTail = pTop) + { + pTop = pTop->Next(); + delete pTail; + } + pTop = pTail = 0; +} + + +template <class XX> +void +SweList_dyn<XX>::push_front( XX * i_pObj ) +{ + DYN elem * dpNew = new elem(i_pObj); + dpNew->SetNext(pTop); + pTop = dpNew; + if (pTail == 0) + pTail = pTop; +} + +template <class XX> +void +SweList_dyn<XX>::push_back( XX * i_pObj ) +{ + if (pTail != 0) + { + pTail->SetNext(new elem(i_pObj)); + pTail = pTail->Next(); + } + else + { + pTop = pTail = new elem(i_pObj); + } +} + +template <class XX> +void +SweList_dyn<XX>::pop_front() +{ + if (pTop != 0) + { + elem * pDel = pTop; + pTop = pTop->Next(); + if (pDel->Obj() != 0) + Delete_dyn(pDel->Obj()); + delete pDel; + if (pTop == 0) + pTail = 0; + } +} + + +template <class XX> +void +SweList_dyn<XX>::erase_all() +{ + for (pTail = pTop ; pTop != 0; pTail = pTop) + { + pTop = pTop->Next(); + if (pTail->Obj() != 0) + { + delete pTail->Obj(); + } + delete pTail; + } + pTop = pTail = 0; +} + +template <class XX> +uintt +SweList_dyn<XX>::size() const +{ + uintt ret = 0; + for ( iterator iter = begin(); + iter != end(); + ++iter ) + { + ++ret; + } + return ret; +} + + +} // namespace csv + + +#endif + + diff --git a/cosv/inc/cosv/tpl/tpltools.hxx b/cosv/inc/cosv/tpl/tpltools.hxx new file mode 100644 index 000000000000..98d5190310d9 --- /dev/null +++ b/cosv/inc/cosv/tpl/tpltools.hxx @@ -0,0 +1,228 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_TPLTOOLS_HXX +#define CSV_TPLTOOLS_HXX + +#include <vector> +#include <map> + + + + +namespace csv +{ + + +template <class COLLECTION> +inline void erase_container( + COLLECTION & o_rCollection ); + +/// Version for std::map +template <class COLLECTION> +void erase_map_of_heap_ptrs( + COLLECTION & o_rCollection ); + +/// Version for other containers than std::map, with non-pair value_type. +template <class COLLECTION> +void erase_container_of_heap_ptrs( + COLLECTION & o_rCollection ); + +template <class VECTOR_ELEM> +void adjust_vector_size( + std::vector<VECTOR_ELEM> & + io_rVector, + uintt i_nSize, + const VECTOR_ELEM & i_nFill ); + + +template <class KEY, class VAL> +const VAL * find_in_map( /// Usable for all kinds of values + const std::map< KEY, VAL > & + i_rMap, + const KEY & i_rKey ); + + +/** @return the value in the map, if it is in there, else 0. + @precond VAL has to be convertable to "0". +*/ +template <class KEY, class VAL> +VAL value_from_map( + const std::map< KEY, VAL > & + i_rMap, + const KEY & i_rKey ); + +/** @return the value in the map, if it is in there, else i_notFound. +*/ +template <class KEY, class VAL> +VAL value_from_map( + const std::map< KEY, VAL > & + i_rMap, + const KEY & i_rKey, + VAL i_notFound ); + +template <class COLLECTION, class VALUE> +bool contains( + const COLLECTION & i_collection, + const VALUE & i_value ); + +// Object oriented for_each: +template <class COLLECTION, class CLASS, class MEMFUNC> +void call_for_each( + const COLLECTION & i_rList, + CLASS * io_pThis, + MEMFUNC i_fMethod ); + + + + +// IMPLEMENTATION +template <class COLLECTION> +inline void +erase_container( COLLECTION & o_rCollection ) +{ + o_rCollection.erase( o_rCollection.begin(), + o_rCollection.end() ); +} + +template <class COLLECTION> +void +erase_map_of_heap_ptrs( COLLECTION & o_rCollection ) +{ + typename COLLECTION::iterator itEnd = o_rCollection.end(); + for ( typename COLLECTION::iterator it = o_rCollection.begin(); + it != itEnd; + ++it ) + { + delete (*it).second; + } + + o_rCollection.erase( o_rCollection.begin(), + o_rCollection.end() ); +} + +template <class COLLECTION> +void +erase_container_of_heap_ptrs( COLLECTION & o_rCollection ) +{ + typename COLLECTION::iterator itEnd = o_rCollection.end(); + for ( typename COLLECTION::iterator it = o_rCollection.begin(); + it != itEnd; + ++it ) + { + delete *it; + } + + o_rCollection.erase( o_rCollection.begin(), + o_rCollection.end() ); +} + +template <class VECTOR_ELEM> +void +adjust_vector_size( std::vector<VECTOR_ELEM> & io_rVector, + uintt i_nSize, + const VECTOR_ELEM & i_nFill ) +{ + if ( io_rVector.size() > i_nSize ) + { + io_rVector.erase( io_rVector.begin() + i_nSize, io_rVector.end() ); + } + else + { + io_rVector.reserve(i_nSize); + while ( io_rVector.size() < i_nSize ) + io_rVector.push_back(i_nFill); + } +} + + +template <class KEY, class VAL> +const VAL * +find_in_map( const std::map< KEY, VAL > & i_rMap, + const KEY & i_rKey ) +{ + typename std::map< KEY, VAL >::const_iterator + ret = i_rMap.find(i_rKey); + return ret != i_rMap.end() + ? & (*ret).second + : (const VAL*)0; +} + +template <class KEY, class VAL> +VAL +value_from_map( const std::map< KEY, VAL > & i_rMap, + const KEY & i_rKey ) +{ + typename std::map< KEY, VAL >::const_iterator + ret = i_rMap.find(i_rKey); + return ret != i_rMap.end() + ? (*ret).second + : VAL(0); +} + +template <class KEY, class VAL> +VAL +value_from_map( const std::map< KEY, VAL > & i_rMap, + const KEY & i_rKey, + VAL i_notFound ) +{ + typename std::map< KEY, VAL >::const_iterator + ret = i_rMap.find(i_rKey); + return ret != i_rMap.end() + ? (*ret).second + : i_notFound; +} + +template <class COLLECTION, class VALUE> +bool +contains( const COLLECTION & i_collection, + const VALUE & i_value ) +{ + return std::find(i_collection.begin(), i_collection.end(), i_value) + != + i_collection.end(); +} + +template <class COLLECTION, class CLASS, class MEMFUNC> +void +call_for_each( const COLLECTION & i_rList, + CLASS * io_pThis, + MEMFUNC i_fMethod ) +{ + typename COLLECTION::const_iterator it = i_rList.begin(); + typename COLLECTION::const_iterator itEnd = i_rList.end(); + for ( ; it != itEnd; ++it ) + { + (io_pThis->*i_fMethod)(*it); + } +} + + + + +} // namespace csv +#endif diff --git a/cosv/inc/cosv/tpl/vvector.hxx b/cosv/inc/cosv/tpl/vvector.hxx new file mode 100644 index 000000000000..312a79d4f229 --- /dev/null +++ b/cosv/inc/cosv/tpl/vvector.hxx @@ -0,0 +1,539 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_VVECTOR_HXX +#define CSV_VVECTOR_HXX + +// USED SERVICES +#include <vector> +#include <cosv/tpl/tpltools.hxx> + + + + +namespace csv +{ +namespace vvector +{ + + +template <class TYPE> +struct delete_ptrs +{ + static void Destruct( + std::vector< TYPE* > & + v) + { csv::erase_container_of_heap_ptrs(v); } + + /// @precond ->it is a valid iterator within v + static void Erase( + std::vector< TYPE* > & + v, + typename std::vector< TYPE* >::iterator + it2erase ) + { delete *it2erase; v.erase(it2erase); } + + /// @precond ->v.size() > 0 + static void PopBack( + std::vector< TYPE* > & + v ) + { delete v.back(); v.pop_back(); } + + /// @precond ->it is a valid iterator + static void ReplacePtr( + typename std::vector< TYPE* >::iterator + it, + DYN TYPE * pass_new ) + { delete *it; *it = pass_new; } +}; + + +/** One helper class for the ->csv::VirtualVector. + Implements a +*/ +template <class TYPE> +struct keep_ptrs +{ + static void Destruct(std::vector< TYPE* > & v) + {} + + static void Erase( + std::vector< TYPE* > & + v, + typename std::vector< TYPE* >::iterator + it2erase ) + { v.erase(it2erase); } + + static void PopBack( + std::vector< TYPE* > & + v ) + { v.pop_back(); } + + /// @precond ->it is a valid iterator + static void ReplacePtr( + typename std::vector< TYPE* >::iterator + it, + TYPE * io_new ) + { *it = io_new; } +}; + + +} // namespace vvector + + + + +/** Implements a vector of different implementations of a base + class. + + Implementation has to be by pointers to get the polymorphic + behaviour, however access is by references to the base class. + + @tpl XX + The common base class of vector elements. + + @tpl PTRDEL + Has two possible values: + vvector::delete_ptrs<XX> Elements have to be on the heap and + are deleted when removed (default). + vvector::keep_ptrs<XX> Elements are only referenced and not + deleted when removed. + +*/ +template <class XX, class PTRDEL = vvector::delete_ptrs<XX> > +class VirtualVector +{ + public: + typedef VirtualVector<XX,PTRDEL> self; + typedef std::vector< DYN XX* > impl_type; + typedef typename impl_type::size_type size_type; + typedef ptrdiff_t difference_type; + + class const_iterator; + class iterator; + + // LIFECYCLE + VirtualVector(); + explicit VirtualVector( + int i_size ); + ~VirtualVector(); + + // OPERATORS + const XX & operator[]( + size_type i_pos ) const; + XX & operator[]( + size_type i_pos ); + + // OPERATIONS + void push_back( + DYN XX & i_drElement ); + void pop_back(); + + iterator insert( + iterator i_pos, + DYN XX & i_drElement ); + void erase( + iterator i_pos ); + void replace( + iterator i_pos, + DYN XX & i_drElement ); + void reserve( + size_type i_size ); + + // INQUIRY + bool empty() const; + size_t size() const; + const_iterator begin() const; + const_iterator end() const; + const XX & front() const; + const XX & back() const; + + // ACCESS + iterator begin(); + iterator end(); + XX & front(); + XX & back(); + + private: + // Forbidden: + VirtualVector(const VirtualVector&); + VirtualVector & operator=(const VirtualVector&); + + // DATA + std::vector< DYN XX* > + aData; +}; + + + + +/** Should be usable for all STL algorithms. + Implements the Random Access Iterator concept. +*/ +template <class XX, class PTRDEL> +class VirtualVector<XX,PTRDEL>:: + const_iterator + + // This derivation provides type information for the STL + // It introduces the types "value_type" and "difference_type". + : public std::iterator<std::random_access_iterator_tag, + const XX> +{ + public: + typedef VirtualVector<XX,PTRDEL> my_container; + typedef typename my_container::impl_type::const_iterator impl_iterator; + + // LIFECYCLE + const_iterator( + impl_iterator i_implIter ) + : itImpl(i_implIter) {} + + + /////////// STL ITERATOR CONCEPT IMPLEMENTATION ////////////// + + // Default Constructible functions: + const_iterator() + : itImpl() {} + + // Assignable functions: + // Assignment and copy constructor use the compiler generated versions. + + // Equality Comparable functions: + bool operator==( + const_iterator i_other ) const + { return itImpl == i_other.itImpl; } + bool operator!=( + const_iterator i_other ) const + { return itImpl != i_other.itImpl; } + + // Trivial Iterator functions: + const XX & operator*() const + { return *(*itImpl); } + + // Input Iterator functions: + const_iterator & operator++() + { ++itImpl; return *this; } + const_iterator operator++(int) + { return const_iterator(itImpl++); } + + // Bidirectional Iterator functions: + const_iterator & operator--() + { --itImpl; return *this; } + const_iterator operator--(int) + { return const_iterator(itImpl--); } + + // Less Than Comparable functions: + bool operator<( + const_iterator i_other ) const + { return itImpl < i_other.itImpl; } + + // Random Access Iterator functions: + const_iterator & operator+=( + difference_type i_diff ) + { itImpl += i_diff; return *this; } + const_iterator operator+( + difference_type i_diff ) const + { const_iterator ret(itImpl); + return ret += i_diff; } + const_iterator & operator-=( + difference_type i_diff ) + { itImpl -= i_diff; return *this; } + const_iterator operator-( + difference_type i_diff ) const + { const_iterator ret(itImpl); + return ret -= i_diff; } + difference_type operator-( + const_iterator i_it ) const + { return itImpl - i_it.itImpl; } + const XX & operator[]( + difference_type i_index ) + { return *(*itImpl[i_index]); } + + ////////////////////////////////////////////////////////////////////////// + + private: + friend class VirtualVector<XX,PTRDEL>; + impl_iterator ImplValue() const { return itImpl; } + + // DATA + impl_iterator itImpl; +}; + + + + +/** Should be usable for all STL algorithms. + Implements the Random Access Iterator concept. +*/ +template <class XX, class PTRDEL> +class VirtualVector<XX,PTRDEL>:: + iterator + + // This derivation provides type information for the STL + // It introduces the types "value_type" and "difference_type". + : public std::iterator<std::random_access_iterator_tag, + XX> +{ + public: + typedef VirtualVector<XX,PTRDEL> my_container; + typedef typename my_container::impl_type::iterator impl_iterator; + + // LIFECYCLE + iterator( + impl_iterator i_implIter ) + : itImpl(i_implIter) {} + + + /////////// STL ITERATOR CONCEPT IMPLEMENTATION ////////////// + + // Default Constructible functions: + iterator() + : itImpl() {} + + // Assignable functions: + // Assignment and copy constructor use the compiler generated versions. + + // Equality Comparable functions: + bool operator==( + iterator i_other ) const + { return itImpl == i_other.itImpl; } + bool operator!=( + iterator i_other ) const + { return itImpl != i_other.itImpl; } + + // Trivial Iterator functions: + XX & operator*() const + { return *(*itImpl); } + + // Input Iterator functions: + iterator & operator++() + { ++itImpl; return *this; } + iterator operator++(int) + { return iterator(itImpl++); } + + // Bidirectional Iterator functions: + iterator & operator--() + { --itImpl; return *this; } + iterator operator--(int) + { return iterator(itImpl--); } + + // Less Than Comparable functions: + bool operator<( + iterator i_other ) const + { return itImpl < i_other.itImpl; } + + // Random Access Iterator functions: + iterator & operator+=( + difference_type i_diff ) + { itImpl += i_diff; return *this; } + iterator operator+( + difference_type i_diff ) const + { iterator ret(itImpl); + return ret += i_diff; } + iterator & operator-=( + difference_type i_diff ) + { itImpl -= i_diff; return *this; } + iterator operator-( + difference_type i_diff ) const + { iterator ret(itImpl); + return ret -= i_diff; } + difference_type operator-( + iterator i_it ) const + { return itImpl - i_it.itImpl; } + XX & operator[]( + difference_type i_index ) + { return *(*itImpl[i_index]); } + + ////////////////////////////////////////////////////////////////////////// + + private: + friend class VirtualVector<XX,PTRDEL>; + impl_iterator ImplValue() const { return itImpl; } + + // DATA + impl_iterator itImpl; +}; + + + + +// IMPLEMENTATION +template <class XX, class PTRDEL> +inline +VirtualVector<XX,PTRDEL>::VirtualVector() + : aData() +{ +} + +template <class XX, class PTRDEL> +inline +VirtualVector<XX,PTRDEL>::VirtualVector(int i_size) + : aData(i_size, 0) +{ +} + +template <class XX, class PTRDEL> +inline +VirtualVector<XX,PTRDEL>::~VirtualVector() +{ + PTRDEL::Destruct(aData); +} + +template <class XX, class PTRDEL> +inline const XX & +VirtualVector<XX,PTRDEL>::operator[]( size_type i_pos ) const +{ + return *aData[i_pos]; +} + +template <class XX, class PTRDEL> +inline XX & +VirtualVector<XX,PTRDEL>::operator[]( size_type i_pos ) +{ + return *aData[i_pos]; +} + +template <class XX, class PTRDEL> +inline void +VirtualVector<XX,PTRDEL>::push_back( DYN XX & i_drElement ) +{ + aData.push_back(&i_drElement); +} + +template <class XX, class PTRDEL> +inline void +VirtualVector<XX,PTRDEL>::pop_back() +{ + if (NOT aData.empty()) + PTRDEL::PopBack(aData); +} + +template <class XX, class PTRDEL> +inline typename VirtualVector<XX,PTRDEL>::iterator +VirtualVector<XX,PTRDEL>::insert( iterator i_pos, + DYN XX & i_drElement ) +{ + return iterator(aData.insert(i_pos.ImplValue(), &i_drElement)); +} + +template <class XX, class PTRDEL> +inline void +VirtualVector<XX,PTRDEL>::erase( iterator i_pos ) +{ + PTRDEL::Erase(aData, i_pos.ImplValue()); +} + +template <class XX, class PTRDEL> +inline void +VirtualVector<XX,PTRDEL>::replace( iterator i_pos, + DYN XX & i_drElement ) +{ + PTRDEL::ReplacePtr(*i_pos, &i_drElement); +} + +template <class XX, class PTRDEL> +inline void +VirtualVector<XX,PTRDEL>::reserve( size_type i_size ) +{ + aData.reserve(i_size); +} + +template <class XX, class PTRDEL> +inline bool +VirtualVector<XX,PTRDEL>::empty() const +{ + return aData.empty(); +} + +template <class XX, class PTRDEL> +inline size_t +VirtualVector<XX,PTRDEL>::size() const +{ + return aData.size(); +} + +template <class XX, class PTRDEL> +inline typename VirtualVector<XX,PTRDEL>::const_iterator +VirtualVector<XX,PTRDEL>::begin() const +{ + return const_iterator(aData.begin()); +} + +template <class XX, class PTRDEL> +inline typename VirtualVector<XX,PTRDEL>::const_iterator +VirtualVector<XX,PTRDEL>::end() const +{ + return const_iterator(aData.end()); +} + +template <class XX, class PTRDEL> +inline const XX & +VirtualVector<XX,PTRDEL>::front() const +{ + return *aData.front(); +} + +template <class XX, class PTRDEL> +inline const XX & +VirtualVector<XX,PTRDEL>::back() const +{ + return *aData.back(); +} + +template <class XX, class PTRDEL> +inline typename VirtualVector<XX,PTRDEL>::iterator +VirtualVector<XX,PTRDEL>::begin() +{ + return iterator(aData.begin()); +} + +template <class XX, class PTRDEL> +inline typename VirtualVector<XX,PTRDEL>::iterator +VirtualVector<XX,PTRDEL>::end() +{ + return iterator(aData.end()); +} + +template <class XX, class PTRDEL> +inline XX & +VirtualVector<XX,PTRDEL>::front() +{ + return *aData.front(); +} + +template <class XX, class PTRDEL> +inline XX & +VirtualVector<XX,PTRDEL>::back() +{ + return *aData.back(); +} + + + + +} // namespace csv +#endif diff --git a/cosv/inc/cosv/x.hxx b/cosv/inc/cosv/x.hxx new file mode 100644 index 000000000000..a2532ab3cee3 --- /dev/null +++ b/cosv/inc/cosv/x.hxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CSV_X_HXX +#define CSV_X_HXX + +// USED SERVICES + // BASE CLASSES + // COMPONENTS +#include <cosv/string.hxx> + // PARAMETERS +#include <cosv/csv_ostream.hxx> + + +namespace csv +{ + +class Exception +{ + public: + virtual ~Exception() {} + virtual void GetInfo( + ostream & o_rOutputMedium ) const = 0; +}; + + +class X_Default : public Exception +{ + public: + X_Default( + const char * i_sMessage ) + : sMessage(i_sMessage) {} + virtual void GetInfo( // Implemented in comfunc.cxx + ostream & o_rOutputMedium ) const; + private: + String sMessage; +}; + + +} // namespace csv + + + +#endif + + + diff --git a/cosv/prj/build.lst b/cosv/prj/build.lst new file mode 100644 index 000000000000..f75303c0c6ca --- /dev/null +++ b/cosv/prj/build.lst @@ -0,0 +1,16 @@ +#==================================================================================== +cs cosv : soltools stlport NULL +cs cosv usr1 - all cs_mkout NULL +cs cosv\prj get - all cs_prj NULL +cs cosv\inc get - all cs_inc NULL +cs cosv\inc\cosv get - all cs_inc_cosv NULL +cs cosv\inc\cosv\template get - all cs_inc_templ NULL +cs cosv\source get - all cs_src NULL +cs cosv\source\inc get - all cs_src_inc NULL +cs cosv\source\service nmake - all cs_serv NULL +cs cosv\source\storage nmake - all cs_store NULL +cs cosv\source\strings nmake - all cs_string NULL +cs cosv\source\comphelp nmake - all cs_badcast NULL +cs cosv\util nmake - all cs_util cs_serv cs_store cs_string cs_badcast NULL +#============================================================================================== + diff --git a/cosv/prj/d.lst b/cosv/prj/d.lst new file mode 100644 index 000000000000..229161c173aa --- /dev/null +++ b/cosv/prj/d.lst @@ -0,0 +1,8 @@ +mkdir: %_DEST%\inc%_EXT%\cosv +mkdir: %_DEST%\inc%_EXT%\cosv\tpl + +..\%__SRC%\lib\cosv.lib %_DEST%\lib%_EXT%\cosv.lib +..\%__SRC%\lib\libcosv.a %_DEST%\lib%_EXT%\libcosv.a +..\inc\cosv\*.hxx %_DEST%\inc%_EXT%\cosv\*.hxx +..\inc\cosv\*.h %_DEST%\inc%_EXT%\cosv\*.h +..\inc\cosv\tpl\*.hxx %_DEST%\inc%_EXT%\cosv\tpl\*.hxx diff --git a/cosv/source/comphelp/badcast.cxx b/cosv/source/comphelp/badcast.cxx new file mode 100644 index 000000000000..f36d9875b52c --- /dev/null +++ b/cosv/source/comphelp/badcast.cxx @@ -0,0 +1,45 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + + +/* Include this for instantiating bad-cast, + due to problems with WNT-STL-headers. +*/ + +#if defined(WNT) && !defined(__MINGW32__) + +#define _NTSDK +#include<typeinfo> + +_STD_BEGIN +bad_cast G_Dummy_Inst_bad_cast; +_STD_END +#endif // WNT + + + diff --git a/cosv/source/comphelp/makefile.mk b/cosv/source/comphelp/makefile.mk new file mode 100644 index 000000000000..7c8fac8f2b0b --- /dev/null +++ b/cosv/source/comphelp/makefile.mk @@ -0,0 +1,55 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cosv +TARGET=cosv_badcast_wnt +TARGETTYPE=CUI + +# --- Settings ----------------------------------------------------- + +ENABLE_EXCEPTIONS=true + +.INCLUDE : settings.mk + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/badcast.obj + + + +# --- Targets ------------------------------------------------------ + + +.INCLUDE : target.mk + + + diff --git a/cosv/source/fullcpp.mk b/cosv/source/fullcpp.mk new file mode 100644 index 000000000000..ffbcb9805273 --- /dev/null +++ b/cosv/source/fullcpp.mk @@ -0,0 +1,57 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + + + +# --- Settings ----------------------------------------------------- +# Has to be inlcuded AFTER settings.mk ! + + +.IF "$(GUI)"=="WNT" + +# RTTI +CFLAGS+= -GR + +.IF "$(NP_LOCALBUILD)"!="" + +# Precompiled Headers +PCH_NAME= cosv +.IF "$(DBG_LEVEL)"<"2" +CFLAGS+= -YX"precomp.h" /Fp$(PRJ)$/$(INPATH)$/misc$/$(PCH_NAME).pch +.ELSE +CFLAGS+= -YX"precomp.h" /Fp$(PRJ)$/$(INPATH)$/misc$/$(PCH_NAME).pcd -DNP_LOCALBUILD +.ENDIF + +.ENDIF + +.ENDIF + +.IF "$(OS)"=="LINUX" +# RTTI +CFLAGSCXX+= -frtti +.ENDIF + diff --git a/cosv/source/inc/precomp.h b/cosv/source/inc/precomp.h new file mode 100644 index 000000000000..f280d522ac03 --- /dev/null +++ b/cosv/source/inc/precomp.h @@ -0,0 +1,36 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef CSV_PRECOMP_H +#define CSV_PRECOMP_H + + +#include <cosv/csv_precomp.h> + + + +#endif + diff --git a/cosv/source/service/comdline.cxx b/cosv/source/service/comdline.cxx new file mode 100644 index 000000000000..fc3003d20e79 --- /dev/null +++ b/cosv/source/service/comdline.cxx @@ -0,0 +1,57 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/comdline.hxx> + +// NOT FULLY DECLARED SERVICES + + +namespace csv +{ + + +bool +CommandLine_Ifc::CheckParameters() const +{ + if ( NOT inq_CheckParameters() ) + { + PrintUse(); + return false; + } + + return true; +} + + + + +} // namespace csv + + + + diff --git a/cosv/source/service/comfunc.cxx b/cosv/source/service/comfunc.cxx new file mode 100644 index 000000000000..ab8f274d90d8 --- /dev/null +++ b/cosv/source/service/comfunc.cxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> + +#include <ctype.h> +#include <cosv/comfunc.hxx> +#include <cosv/string.hxx> +#include <cosv/x.hxx> +#include <cosv/std_outp.hxx> + + + +namespace csv +{ + + +void +X_Default::GetInfo( ostream & o_rOutputMedium ) const +{ + o_rOutputMedium << "Error (general exception): "; + o_rOutputMedium << sMessage + << Endl; +} + +intt +count_chars(const char * str, char c) +{ + intt nCount = 0; + for ( const char * pSpc = strchr(str, c); + pSpc != 0; + pSpc = strchr(pSpc+1, c) ) + { + nCount++; + } + return nCount; +} + + + +// Zeit-Typecasts +bool +str2date(const char * str, int & out_day, int & out_month, int & out_year) +{ + const char * z = str; + out_day = 0; + out_month = 0; + out_year = 0; + + while (isdigit(*z)) + out_day = 10*out_day + *(z++) - '0'; + if (*z == 0) + return false; + z++; + while (isdigit(*z)) + out_month = 10*out_month + *(z++) - '0'; + if (*z == 0) + return false; + z++; + while (isdigit(*z)) + out_year = 10*out_year + *(z++) - '0'; + return true; +} + +void +date2str(String & out_Str, int day, int month, int year) +{ + char buf[11] = "00.00.0000"; + buf[0] = static_cast<char>(day/10 + '0'); + buf[1] = static_cast<char>(day%10 + '0'); + buf[3] = static_cast<char>(month/10 + '0'); + buf[4] = static_cast<char>(month%10 + '0'); + + if (year < 100) + { + buf[6] = static_cast<char>(year/10 + '0'); + buf[7] = static_cast<char>(year%10 + '0'); + buf[8] = 0; + } + else + { + buf[6] = static_cast<char>(year/1000 + '0'); + buf[7] = static_cast<char>(year%1000/100 + '0'); + buf[8] = static_cast<char>(year%100/10 + '0'); + buf[9] = static_cast<char>(year%10 + '0'); + } + out_Str = buf; +} + +bool +str2time(const char * str, int & out_hour, int & out_min, int & out_sec) +{ + const char * z = str; + out_hour = 0; + out_min = 0; + out_sec = 0; + + while (isdigit(*z)) + out_hour = 10*out_hour + *(z++) - '0'; + if (*z == 0) + return false; + z++; + while (isdigit(*z)) + out_min = 10*out_min + *(z++) - '0'; + if (*z == 0) + return false; + z++; + while (isdigit(*z)) + out_sec = 10*out_sec + *(z++) - '0'; + return true; +} + +void +time2str(String & out_Str, int hour, int min, int sec) +{ + char buf[9] = "00:00:00"; + buf[0] = static_cast<char>(hour/10 + '0'); + buf[1] = static_cast<char>(hour%10 + '0'); + buf[3] = static_cast<char>(min/10 + '0'); + buf[4] = static_cast<char>(min%10 + '0'); + buf[6] = static_cast<char>(sec/10 + '0'); + buf[7] = static_cast<char>(sec%10 + '0'); + out_Str = buf; +} + + + +} // namespace csv + + + diff --git a/cosv/source/service/commandline.cxx b/cosv/source/service/commandline.cxx new file mode 100644 index 000000000000..383811a9ac25 --- /dev/null +++ b/cosv/source/service/commandline.cxx @@ -0,0 +1,342 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/commandline.hxx> + +// NOT FULLY DECLARED SERVICES +#include <cosv/file.hxx> + + +namespace csv +{ + +namespace +{ + +const intt C_nNoOption = -1; + +const char * sIncludeOptionShort = "-A:"; +const char * sIncludeOptionLong = "--Arguments:"; +const uintt nIncludeOptionShort_Length = strlen(sIncludeOptionShort); +const uintt nIncludeOptionLong_Length = strlen(sIncludeOptionLong); + + +/** Analyses, if an option is the one to include a file with + further command line arguments. +*/ +bool IsIncludeOption( + const String & i_option ); + +/** Gets the file name from an include-arguments-option. +*/ +String IncludeFile_fromIncludeOption( + const String & i_option ); + + +bool +IsIncludeOption(const String & i_option) +{ + return strncmp(i_option, sIncludeOptionShort, nIncludeOptionShort_Length) == 0 + OR + strncmp(i_option, sIncludeOptionLong, nIncludeOptionLong_Length) == 0; +} + +String +IncludeFile_fromIncludeOption(const String & i_option) +{ + if ( strncmp(i_option, sIncludeOptionShort, nIncludeOptionShort_Length) + == 0 ) + { + return String(i_option, nIncludeOptionShort_Length, str::maxsize); + } + else + if ( strncmp(i_option, sIncludeOptionLong, nIncludeOptionLong_Length) + == 0 ) + { + return String(i_option, nIncludeOptionLong_Length, str::maxsize); + } + return String::Null_(); +} + + +} // end anonymous namespace + + + + +/** Local helper class for searching a possible option name in a vector of + ->OptionDescription. +*/ +struct CommandLine:: +FindOptionByText +{ + bool operator()( + const CommandLine::OptionDescription & + i_option ) + { return i_option.sText == sOption; } + + /// @param i_searchText [i_searchText != ""] + FindOptionByText( + const String & i_option ) + : sOption(i_option) { } + private: + const String sOption; +}; + + +typedef std::vector<StringVector::const_iterator> StringCIteratorList; +typedef std::vector<intt> OptionIdList; + +bool +CommandLine::Interpret( int argc, + char * argv[] ) +{ + Get_Arguments(argc,argv); + csv_assert(aOptionPoints.size() == aOptionIds.size()); + + StringVector::const_iterator + itNext = aCommandLine.begin(); + ++itNext; // Move 1 forward from program name. + StringVector::const_iterator + itEnd = aCommandLine.end(); + StringCIteratorList::const_iterator + itOptPtsEnd = aOptionPoints.end(); + + OptionIdList::const_iterator + itOptIds = aOptionIds.begin(); + for ( StringCIteratorList::const_iterator itOptPts = aOptionPoints.begin(); + itOptPts != itOptPtsEnd AND bIsOk; + ++itOptPts, ++itOptIds ) + { + // May be, there are arguments which do not belong to the last option: + // itNext != *is + Handle_FreeArguments(itNext, *itOptPts); + + itNext = do_HandleOption( *itOptIds, + *itOptPts + 1, + itOptPts+1 == itOptPtsEnd ? itEnd : *(itOptPts+1) ); + csv_assert(itNext <= itEnd); + } // end for (is) + Handle_FreeArguments(itNext, itEnd); + + return bIsOk; +} + +CommandLine::CommandLine() + : aOptions(), + aCommandLine(), + bIsOk(false) +{ +} + +void +CommandLine::Add_Option( intt i_id, + String i_text ) +{ + aOptions.push_back(OptionDescription( i_id, + i_text )); +} + +void +CommandLine::Get_Arguments( int argc, + char * argv[] ) +{ + aCommandLine.erase(aCommandLine.begin(),aCommandLine.end()); + aCommandLine.reserve(argc); + + char ** pArgEnd = argv + argc; + for ( char ** pArg = &argv[0]; + pArg != pArgEnd; + ++pArg ) + { + Store_Argument(*pArg); + } // end for + Find_OptionPoints(); + bIsOk = true; +} + +intt +CommandLine::Find_Option( const String & i_text ) const +{ + if (i_text.empty()) + return C_nNoOption; + + FindOptionByText aSearch(i_text); + OptionList::const_iterator + itFound = std::find_if( aOptions.begin(), + aOptions.end(), + aSearch ); + if (itFound != aOptions.end()) + { + return (*itFound).nId; + } + return C_nNoOption; +} + +bool +CommandLine::Store_Argument( const String & i_arg ) +{ + if ( NOT IsIncludeOption(i_arg) ) + { + aCommandLine.push_back(i_arg); + return true; + } + + return Try2Include_Options(i_arg); +} + +void +CommandLine::Find_OptionPoints() +{ + StringVector::const_iterator itEnd = aCommandLine.end(); + for ( StringVector::const_iterator it = aCommandLine.begin() + 1; + it != itEnd; + ++it ) + { + intt nOption = Find_Option(*it); + if (nOption != C_nNoOption) + { + aOptionPoints.push_back(it); + aOptionIds.push_back(nOption); + } + } // end for (i) +} + +void +CommandLine::Handle_FreeArguments( StringVector::const_iterator i_begin, + StringVector::const_iterator i_end ) +{ + for ( StringVector::const_iterator it = i_begin; + it != i_end AND bIsOk; + ++it ) + { + do_HandleFreeArgument(*it); + } +} + +bool +CommandLine::Try2Include_Options(const String & i_includeOption) +{ + static StringVector + aIncludedOptionFiles_; + + const String + aOptionFile(IncludeFile_fromIncludeOption(i_includeOption)); + + // Avoid recursion deadlock 1 + if ( std::find( aIncludedOptionFiles_.begin(), + aIncludedOptionFiles_.end(), + aOptionFile ) + != aIncludedOptionFiles_.end() ) + { + Cerr() << "\nError: Self inclusion of option file " + << aOptionFile + << ".\n" + << Endl(); + return false; + } + + // Avoid recursion deadlock 2 + aIncludedOptionFiles_.push_back(aOptionFile); + + bool ok = Include_Options(aOptionFile); + + // Avoid recursion deadlock 3 + aIncludedOptionFiles_.pop_back(); + + return ok; +} + +bool +CommandLine::Include_Options( const String & i_optionsFile ) +{ + StreamStr + aIncludedText(500); + bool ok = Load_Options(aIncludedText, i_optionsFile); + if (NOT ok) + return false; + + StringVector + aIncludedOptions; + Split(aIncludedOptions, aIncludedText.c_str()); + + StringVector::const_iterator itEnd = aIncludedOptions.end(); + for ( StringVector::const_iterator it = aIncludedOptions.begin(); + it != itEnd; + ++it ) + { + Store_Argument(*it); + } // end for + + return true; +} + +bool +CommandLine::Load_Options( StreamStr & o_text, + const String & i_optionsFile ) +{ + if (i_optionsFile.empty()) + return false; + + File + aOptionsFile(i_optionsFile, CFM_READ); + OpenCloseGuard + aOFGuard(aOptionsFile); + if (NOT aOFGuard) + { + Cerr() << "\nError: Options file " + << i_optionsFile + << " not found.\n" + << Endl(); + return false; + } + + StreamStr + aLoad(aOptionsFile); + o_text.swap(aLoad); + return true; +} + + + + +/****************** OptionDescription ***********************/ + + +CommandLine:: +OptionDescription::OptionDescription( intt i_id, + String i_text ) + : nId(i_id), + sText(i_text) +{ +} + + + + +} // namespace csv diff --git a/cosv/source/service/csv_ostream.cxx b/cosv/source/service/csv_ostream.cxx new file mode 100644 index 000000000000..30c5736343a2 --- /dev/null +++ b/cosv/source/service/csv_ostream.cxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/csv_ostream.hxx> + +// NOT FULLY DECLARED SERVICES + + +#ifndef CSV_NO_IOSTREAMS +#else + +#include <cosv/streamstr.hxx> + +namespace csv +{ + +ostream::~ostream() { } + +ostream & ostream::operator<<( + const char * i_s ) { *pData << i_s; return *this; } +ostream & ostream::operator<<( + char i_c ) { *pData << i_c; return *this; } +ostream & ostream::operator<<( + unsigned char i_c ) { *pData << i_c; return *this; } +ostream & ostream::operator<<( + signed char i_c ) { *pData << i_c; return *this; } + +ostream & ostream::operator<<( + short i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + unsigned short i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + int i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + unsigned int i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + long i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + unsigned long i_n ) { *pData << i_n; return *this; } + +ostream & ostream::operator<<( + float i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + double i_n ) { *pData << i_n; return *this; } + +ostream & +ostream::seekp( intt i_nOffset, + seek_dir i_eStart ) +{ + pData->seekp(i_nOffset, csv::seek_dir(int(i_eStart)) ); + return *this; +} + +ostream::ostream( uintt i_nStartSize ) + : pData( new StreamStr(i_nStartSize) ) +{ +} + + + +} // namespace csv + +#endif + + + + diff --git a/cosv/source/service/datetime.cxx b/cosv/source/service/datetime.cxx new file mode 100644 index 000000000000..00acabe6e1d7 --- /dev/null +++ b/cosv/source/service/datetime.cxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include <precomp.h> +#include <cosv/datetime.hxx> + + +// NOT FULLY DECLARED SERVICES + + +namespace csv +{ + + +Date::Date() + : nData( 0 ) +{ +} + +Date::Date( unsigned i_nDay, + unsigned i_nMonth, + unsigned i_nYear ) + : nData( (i_nDay << 24) + (i_nMonth << 16) + i_nYear ) +{ +} + +const Date & +Date::Null_() +{ + static const Date C_DateNull_(0,0,0); + return C_DateNull_; +} + + +Time::Time() + : nData( 0 ) +{ +} + +Time::Time( unsigned i_nHour, + unsigned i_nMinutes, + unsigned i_nSeconds, + unsigned i_nSeconds100 ) + : nData( (i_nHour << 24) + (i_nMinutes << 16) + (i_nSeconds << 8) + i_nSeconds100 ) +{ +} + +const Time & +Time::Null_() +{ + static const Time C_TimeNull_(0,0); + return C_TimeNull_; +} + + + +} // namespace csv + + diff --git a/cosv/source/service/makefile.mk b/cosv/source/service/makefile.mk new file mode 100644 index 000000000000..fc44f35e5ea3 --- /dev/null +++ b/cosv/source/service/makefile.mk @@ -0,0 +1,59 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cosv +TARGET=cosv_service + +ENABLE_EXCEPTIONS=true + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.INCLUDE : $(PRJ)$/source$/fullcpp.mk + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/comdline.obj \ + $(OBJ)$/comfunc.obj \ + $(OBJ)$/csv_ostream.obj \ + $(OBJ)$/datetime.obj \ + $(OBJ)$/std_outp.obj + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + + diff --git a/cosv/source/service/std_outp.cxx b/cosv/source/service/std_outp.cxx new file mode 100644 index 000000000000..315abec11978 --- /dev/null +++ b/cosv/source/service/std_outp.cxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/std_outp.hxx> + +// NOT FULLY DECLARED SERVICES +#include <stdlib.h> + + +namespace csv +{ + +#ifdef CSV_NO_IOSTREAMS +redirect_out * redirect_out::pStdOut_ = 0; +redirect_out * redirect_out::pStdErr_ = 0; +#endif // defined(CSV_NO_IOSTREAMS) + + +void +Endl( ostream & io_rStream, bool /*bUseRedirect*/, int* ) +{ +#ifndef CSV_NO_IOSTREAMS +// if (NOT bUseRedirect) + io_rStream << std::endl; +// else +#endif +// static_cast< redirect_out& >(io_rStream).re_endl(); +} + +void +Flush( ostream & io_rStream, bool /*bUseRedirect*/, int* ) +{ +#ifndef CSV_NO_IOSTREAMS +// if (NOT bUseRedirect) + io_rStream << std::flush; +// else +#endif +// static_cast< redirect_out& >(io_rStream).re_flush(); +} + +void +PerformAssertion(const char * condition, const char * file, unsigned line) +{ + Cout() << "assertion failed: " + << condition + << " in file: " + << file + << " at line: " + << line + << Endl; + + exit(3); +} + +} // namespace csv + diff --git a/cosv/source/storage/dirchain.cxx b/cosv/source/storage/dirchain.cxx new file mode 100644 index 000000000000..b183c0f990f7 --- /dev/null +++ b/cosv/source/storage/dirchain.cxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/dirchain.hxx> + +// NOT FULLY DECLARED SERVICES +#include <cosv/bstream.hxx> + + + + +namespace csv +{ +namespace ploc +{ + + +DirectoryChain::DirectoryChain() +{ +} + +DirectoryChain::DirectoryChain( const char * i_sSubPath, + bool i_bPathIsAlwaysDir, + const char * i_sDelimiter ) +{ + Set( i_sSubPath, i_bPathIsAlwaysDir, i_sDelimiter ); +} + +DirectoryChain::~DirectoryChain() +{ +} + +void +DirectoryChain::Set( const char * i_sSubPath, + bool i_bPathIsAlwaysDir, + const char * i_sDelimiter ) +{ + csv_assert(i_sDelimiter != 0); + if (i_sSubPath == 0) + return; + + const char * pRestPath = i_sSubPath; + if (*pRestPath == *i_sDelimiter) + ++pRestPath; + + for ( const char * pDirEnd = strchr(pRestPath,*i_sDelimiter); + pDirEnd != 0; + pDirEnd = strchr(pRestPath,*i_sDelimiter) ) + { + aPath.push_back( String(pRestPath, pDirEnd) ); + pRestPath = pDirEnd + 1; + } + if (*pRestPath != 0 AND i_bPathIsAlwaysDir) + aPath.push_back( String(pRestPath) ); +} + +void +DirectoryChain::PushFront( const String & i_sName ) +{ + aPath.insert( aPath.begin(), i_sName ); +} + +void +DirectoryChain::PushFront( const DirectoryChain & i_sPath ) +{ + aPath.insert( aPath.begin(), i_sPath.Begin(), i_sPath.End() ); +} + +void +DirectoryChain::PushBack( const String & i_sName ) +{ + aPath.push_back(i_sName); +} + +void +DirectoryChain::PushBack( const DirectoryChain & i_sPath ) +{ + aPath.insert( aPath.end(), i_sPath.Begin(), i_sPath.End() ); +} + +void +DirectoryChain::PopFront( uintt i_nCount ) +{ + if (i_nCount <= aPath.size()) + aPath.erase( aPath.begin(), aPath.begin() + i_nCount ); + else + aPath.erase( aPath.begin(), aPath.end() ); +} + +void +DirectoryChain::PopBack( uintt i_nCount ) +{ + if (i_nCount <= aPath.size()) + aPath.erase( aPath.end() - i_nCount, aPath.end() ); + else + aPath.erase( aPath.begin(), aPath.end() ); +} + +void +DirectoryChain::Get( ostream & o_rPath, + const char * i_sDelimiter ) const +{ + for ( std::vector<String>::const_iterator it = aPath.begin(); + it != aPath.end(); + ++it ) + { + o_rPath << (*it).c_str() << i_sDelimiter; + } +} + +void +DirectoryChain::Get( bostream & o_rPath, + const char * i_sDelimiter ) const +{ + uintt deliLen = strlen(i_sDelimiter); + + for ( std::vector<String>::const_iterator it = aPath.begin(); + it != aPath.end(); + ++it ) + { + o_rPath.write( (*it).c_str() ); + o_rPath.write( i_sDelimiter, deliLen); + } +} + + + + +} // namespace ploc +} // namespace csv diff --git a/cosv/source/storage/file.cxx b/cosv/source/storage/file.cxx new file mode 100644 index 000000000000..aa1190ec9fab --- /dev/null +++ b/cosv/source/storage/file.cxx @@ -0,0 +1,242 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/file.hxx> + +// NOT FULLY DECLARED SERVICES + + +namespace csv +{ + + +File::File( uintt i_nMode ) + : // aPath, + pStream(0), + nMode(i_nMode), + eLastIO(io_none) +{ +} + +File::File( const ploc::Path & i_rLocation, + uintt i_nMode ) + : aPath(i_rLocation), + pStream(0), + nMode(i_nMode), + eLastIO(io_none) +{ +} + +File::File( const char * i_sLocation, + uintt i_nMode ) + : aPath(i_sLocation), + pStream(0), + nMode(i_nMode), + eLastIO(io_none) +{ +} + +File::File( const String & i_sLocation, + uintt i_nMode ) + : aPath(i_sLocation), + pStream(0), + nMode(i_nMode), + eLastIO(io_none) +{ +} + +File::~File() +{ + if ( inq_is_open() ) + close(); +} + +bool +File::Assign( ploc::Path i_rLocation ) +{ + if (is_open() ) + return false; + + InvalidatePath(); + aPath = i_rLocation; + return true; +} + +bool +File::Assign( const char * i_sLocation ) +{ + if (is_open() ) + return false; + + InvalidatePath(); + aPath.Set( i_sLocation ); + return true; +} + +bool +File::Assign( const String & i_sLocation ) +{ + if (is_open() ) + return false; + + InvalidatePath(); + aPath.Set( i_sLocation ); + return true; +} + +uintt +File::do_read( void * out_pDest, + uintt i_nNrofBytes ) +{ + if ( NOT inq_is_open() ) + return 0; + + if ( eLastIO == io_write ) + ::fseek( pStream, 0, SEEK_CUR ); + uintt ret = position(); + int iRet= ::fread( out_pDest, 1, i_nNrofBytes, pStream ); + if ( iRet < 0 ) { + fprintf(stderr, "warning: read failed in %s line %d \n", __FILE__, __LINE__); + } + ret = position() - ret; + + eLastIO = io_read; + return ret; +} + +bool +File::inq_eod() const +{ + if ( NOT inq_is_open() ) + return true; + return feof(pStream) != 0; +} + +uintt +File::do_write( const void * i_pSrc, + uintt i_nNrofBytes ) +{ + if ( NOT inq_is_open() ) + return 0; + + if ( eLastIO == io_write ) + ::fseek( pStream, 0, SEEK_CUR ); + uintt ret = position(); + ::fwrite( i_pSrc, 1, i_nNrofBytes, pStream ); + ret = position() - ret; + + eLastIO = io_write; + return ret; +} + +uintt +File::do_seek( intt i_nDistance, + seek_dir i_eStartPoint ) +{ + if ( NOT inq_is_open() ) + return uintt(-1); + + static int eSearchDir[3] = { SEEK_SET, SEEK_CUR, SEEK_END }; + + ::fseek( pStream, + intt(i_nDistance), + eSearchDir[i_eStartPoint] ); + return position(); +} + +uintt +File::inq_position() const +{ + if ( inq_is_open() ) + return uintt( ::ftell(pStream) ); + else + return uintt(-1); +} + +bool +File::do_open( uintt i_nOpenMode ) +{ + if ( inq_is_open() ) + { + if ( i_nOpenMode == 0 OR i_nOpenMode == nMode ) + return true; + close(); + } + + if ( i_nOpenMode != 0 ) + nMode = i_nOpenMode; + + const char * sFacadeMode = ""; + switch ( nMode ) + { + case CFM_RW: sFacadeMode = "r+b"; + break; + case CFM_CREATE: sFacadeMode = "w+b"; + break; + case CFM_READ: sFacadeMode = "rb"; + break; + default: + sFacadeMode = "rb"; + } + + pStream = ::fopen( StrPath(), sFacadeMode ); + if ( pStream == 0 AND nMode == CFM_RW ) + { + sFacadeMode = "w+b"; + pStream = ::fopen( StrPath(), sFacadeMode ); + } + + return pStream != 0; +} + +void +File::do_close() +{ + if ( inq_is_open() ) + { + ::fclose(pStream); + pStream = 0; + } + eLastIO = io_none; +} + +bool +File::inq_is_open() const +{ + return pStream != 0; +} + +const ploc::Path & +File::inq_MyPath() const +{ + return aPath; +} + + +} // namespace csv + diff --git a/cosv/source/storage/makefile.mk b/cosv/source/storage/makefile.mk new file mode 100644 index 000000000000..84e396c425ba --- /dev/null +++ b/cosv/source/storage/makefile.mk @@ -0,0 +1,69 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cosv +TARGET=cosv_storage + +ENABLE_EXCEPTIONS=true + + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.INCLUDE : $(PRJ)$/source$/fullcpp.mk + + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/dirchain.obj \ + $(OBJ)$/file.obj \ + $(OBJ)$/mbstream.obj \ + $(OBJ)$/persist.obj \ + $(OBJ)$/ploc.obj \ + $(OBJ)$/ploc_dir.obj \ + $(OBJ)$/plocroot.obj + +#SLOFILES= \ +# $(SLO)$/file.obj \ +# $(SLO)$/csfileim.obj \ +# $(SLO)$/memstorg.obj + + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + + diff --git a/cosv/source/storage/mbstream.cxx b/cosv/source/storage/mbstream.cxx new file mode 100644 index 000000000000..5559d1f6d59a --- /dev/null +++ b/cosv/source/storage/mbstream.cxx @@ -0,0 +1,119 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/mbstream.hxx> + +// NOT FULLY DECLARED SERVICES +#include <string.h> + + +namespace csv +{ + + + +mbstream::mbstream( uintt i_nSize ) + : dpOwnedMemorySpace( new char[i_nSize+1] ), + nSize( i_nSize ), + nCurPosition( 0 ) +{ + dpOwnedMemorySpace[i_nSize] = '\0'; +} + +mbstream::~mbstream() +{ + delete [] dpOwnedMemorySpace; +} + +void +mbstream::resize( uintt i_nSize ) +{ + DYN char * pNew = new char[i_nSize]; + memcpy( pNew, dpOwnedMemorySpace, min(i_nSize,nSize) ); + delete [] dpOwnedMemorySpace; + dpOwnedMemorySpace = pNew; + nSize = i_nSize; +} + +uintt +mbstream::do_read( void * out_pDest, + uintt i_nNrofBytes ) +{ + uintt ret = min( i_nNrofBytes, nSize - nCurPosition ); + memcpy( out_pDest, dpOwnedMemorySpace, ret ); + nCurPosition += ret; + return ret; +} + +bool +mbstream::inq_eod() const +{ + return nCurPosition == nSize; +} + +uintt +mbstream::do_write( const void * i_pSrc, + uintt i_nNrofBytes ) +{ + resize( max( 3 * (nSize+1) / 2, nCurPosition + i_nNrofBytes) ); + memcpy( dpOwnedMemorySpace+nCurPosition, i_pSrc, i_nNrofBytes ); + nCurPosition += i_nNrofBytes; + return i_nNrofBytes; +} + +uintt +mbstream::do_seek( intt i_nDistance, + seek_dir i_eStartPoint ) +{ + switch ( i_eStartPoint ) + { + case beg: if ( uintt(i_nDistance) < nSize ) + nCurPosition = uintt(i_nDistance); + break; + case cur: if ( i_nDistance < 0 + ? uintt(-i_nDistance) <= nCurPosition + : uintt(i_nDistance) + nCurPosition < nSize ) + nCurPosition = uintt( intt(nCurPosition) + i_nDistance ); + break; + case end: if ( i_nDistance < 0 + AND uintt(-i_nDistance) < nSize - 1 ) + nCurPosition = uintt( intt(nSize) - 1 + i_nDistance ); + break; + } + return position(); +} + +uintt +mbstream::inq_position() const +{ + return nCurPosition; +} + + +} // namespace csv + diff --git a/cosv/source/storage/persist.cxx b/cosv/source/storage/persist.cxx new file mode 100644 index 000000000000..aa63767c1b0e --- /dev/null +++ b/cosv/source/storage/persist.cxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/persist.hxx> + +// NOT FULLY DECLARED SERVICES +#include <cosv/streamstr.hxx> +#include <cosv/ploc.hxx> + + +#ifdef WNT +#include <io.h> + +namespace csv +{ +namespace ploc +{ + +bool +Persistent::Exists() const +{ + return access( StrPath(), 00) == 0; +} + +} // namespace ploc +} // namespace csv + + +#elif defined(UNX) +#include <unistd.h> + +/* +#ifndef __SUNPRO_CC +#include <unistd.h> +#else +#define F_OK 0 // Test for existence of File +extern int access(const char *, int); +#endif +*/ + +namespace csv +{ +namespace ploc +{ + +bool +Persistent::Exists() const +{ + return access( StrPath(), F_OK ) == 0; +} + + +} // namespace ploc +} // namespace csv + +#else +#error For using csv::ploc there has to be defined: WNT or UNX. +#endif + +namespace csv +{ +namespace ploc +{ + +const char * +Persistent::StrPath() const +{ + if (sPath.empty() ) + { +#ifndef CSV_NO_MUTABLE + StreamStr & rsPath = sPath; +#else + StreamStr & rsPath = const_cast< StreamStr& >(sPath); +#endif + rsPath.seekp(0); + rsPath << MyPath(); + if (MyPath().IsDirectory()) + rsPath.pop_back(1); // Remove closing delimiter. + } + return sPath.c_str(); +} + +} // namespace ploc +} // namespace csv + + + + diff --git a/cosv/source/storage/ploc.cxx b/cosv/source/storage/ploc.cxx new file mode 100644 index 000000000000..66061cd8df55 --- /dev/null +++ b/cosv/source/storage/ploc.cxx @@ -0,0 +1,157 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/ploc.hxx> + +// NOT FULLY DECLARED SERVICES +#include <cosv/bstream.hxx> + + + + +namespace csv +{ +namespace ploc +{ + + +Path::Path( const char * i_sPath, + bool i_bPathIsAlwaysDir, + const char * i_sDelimiter ) + : pRoot(0) + // aPath, + // sFile +{ + Set(i_sPath, i_bPathIsAlwaysDir, i_sDelimiter ); +} + +Path::Path( const Path & i_rPath ) + : pRoot(i_rPath.pRoot->CreateCopy()), + aPath(i_rPath.aPath), + sFile(i_rPath.sFile) +{ +} + +Path::~Path() +{ +} + +Path & +Path::operator=( const Path & i_rPath ) +{ + pRoot = i_rPath.pRoot->CreateCopy(); + aPath = i_rPath.aPath; + sFile = i_rPath.sFile; + return *this; +} + + +void +Path::Set( const char * i_sPath, + bool i_bPathIsAlwaysDir, + const char * i_sDelimiter ) +{ + if ( *i_sDelimiter != '\\' AND *i_sDelimiter != '/' ) + return; + + const char * + restPath = 0; + pRoot = Root::Create_( restPath, i_sPath, i_sDelimiter ); + if (restPath == 0) + return; + + aPath.Set(restPath, i_bPathIsAlwaysDir, i_sDelimiter); + + if (NOT i_bPathIsAlwaysDir) + { + const char * + file = strrchr( restPath, *i_sDelimiter ); + if (file == 0) + file = restPath; + else + file++; + sFile = file; + } +} + +void +Path::SetFile( const String & i_sName ) +{ + sFile = i_sName; +} + +const char * +Path::FileExtension() const +{ + const char * + ext = strrchr(sFile, '.'); + if (ext != 0) + ++ext; + else + ext = ""; + return ext; +} + +bool +Path::IsValid() const +{ + return RootDir().OwnDelimiter() != 0; +} + +void +Path::Get( ostream & o_rPath ) const +{ + if (NOT IsValid()) + return; + + pRoot->Get( o_rPath ); + aPath.Get( o_rPath, pRoot->OwnDelimiter() ); + + if ( sFile.length() > 0 ) + o_rPath << sFile; + +} + +void +Path::Get( bostream & o_rPath ) const +{ + if (NOT IsValid()) + return; + + pRoot->Get( o_rPath ); + aPath.Get( o_rPath, pRoot->OwnDelimiter() ); + + if ( sFile.length() > 0 ) + o_rPath.write( sFile ); +} + + + + +} // namespace ploc +} // namespace csv diff --git a/cosv/source/storage/ploc_dir.cxx b/cosv/source/storage/ploc_dir.cxx new file mode 100644 index 000000000000..0f769a5f7e6f --- /dev/null +++ b/cosv/source/storage/ploc_dir.cxx @@ -0,0 +1,364 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/ploc_dir.hxx> + +// NOT FULLY DECLARED SERVICES +#include <cosv/ploc.hxx> + + +namespace csv +{ +namespace ploc +{ + +Directory::Directory() +{ +} + +Directory::Directory( const Path & i_rPath ) + : aPath(i_rPath) + // sPath +{ +} + +Directory::Directory( const Directory & i_rDir ) + : Persistent(), aPath(i_rDir.aPath) + // sPath +{ +} + +Directory::Directory( const char * i_rLocation ) + : aPath(i_rLocation, true) +{ +} + +Directory::Directory( const String & i_rLocation ) + : aPath(i_rLocation.c_str(), true) +{ +} + +Directory::~Directory() +{ +} + +Directory & +Directory::operator+=( const String & i_sName ) +{ + InvalidatePath(); + aPath.DirChain() += i_sName; + return *this; +} + +Directory & +Directory::operator+=( const DirectoryChain & i_sDirChain ) +{ + InvalidatePath(); + aPath.DirChain() += i_sDirChain; + return *this; +} + +Directory & +Directory::operator-=( uintt i_nLevels ) +{ + InvalidatePath(); + aPath.DirChain().PopBack(i_nLevels); + return *this; +} + +bool +Directory::PhysicalCreate( bool i_bCreateParentsIfNecessary ) const +{ + bool ret = PhysicalCreate_Dir( StrPath() ); + if ( ret OR NOT i_bCreateParentsIfNecessary ) + return ret; + + ret = Check_Parent(); + if (ret) + ret = PhysicalCreate_Dir( StrPath() ); + return ret; +} + +bool +Directory::Check_Parent() const +{ + // There is no parent of root directories: + if ( aPath.DirChain().Size() == 0 ) + return false; + + // Become my own parent: + String sLastToken = aPath.DirChain().Back(); + const_cast< Directory* >(this)->operator-=(1); + + // Begin behaving as parent: + bool ret = Exists(); + if (NOT ret) + { + ret = Check_Parent(); + if (ret) + ret = PhysicalCreate_Dir( StrPath() ); + } + // End behaving as parent. + + // Become myself again: + const_cast< Directory* >(this)->operator+=(sLastToken); + return ret; +} + +} // namespace ploc +} // namespace csv + + +#ifdef WNT +#include <direct.h> +#include <io.h> + +namespace csv +{ +namespace ploc +{ + +bool +Directory::PhysicalCreate_Dir( const char * i_sStr ) const +{ + return mkdir( i_sStr ) == 0; +} + +void +Directory::GetContainedDirectories( StringVector & o_rResult ) const +{ + const char * c_sANYDIR = "\\*.*"; + String sNew; + + StreamStr sFilter(200); + sFilter << StrPath() + << c_sANYDIR; + + struct _finddata_t + aEntry; + long hFile = _findfirst( sFilter.c_str(), &aEntry ); + + for ( int bFindMore = (hFile == -1 ? 1 : 0); + bFindMore == 0; + bFindMore = _findnext( hFile, &aEntry ) ) + { + if ( (aEntry.attrib & _A_SUBDIR) AND *aEntry.name != '.' ) + { + sNew = aEntry.name; + o_rResult.push_back( sNew ); + } + } // end for + _findclose(hFile); +} + +void +Directory::GetContainedFiles( StringVector & o_rResult, + const char * i_sFilter, + E_Recursivity i_eRecursivity ) const +{ + StreamStr sNew(240); + sNew << aPath; + StreamStr::size_type + nStartFilename = sNew.tellp(); + + StreamStr sFilter(200); + sFilter << StrPath() + << "\\" + << i_sFilter; + + struct _finddata_t + aEntry; + long hFile = _findfirst( sFilter.c_str(), &aEntry ); + for ( int bFindMore = (hFile == -1 ? 1 : 0); + bFindMore == 0; + bFindMore = _findnext( hFile, &aEntry ) ) + { + sNew.seekp(nStartFilename); + sNew << aEntry.name; + String sNewAsString( sNew.c_str() ); + o_rResult.push_back(sNewAsString); + } // end for + + _findclose(hFile); + if ( i_eRecursivity == flat ) + return; + + // gathering from subdirectories: + StringVector aSubDirectories; + GetContainedDirectories( aSubDirectories ); + + StringVector::const_iterator dEnd = aSubDirectories.end(); + for ( StringVector::const_iterator d = aSubDirectories.begin(); + d != dEnd; + ++d ) + { + Directory aSub(*this); + aSub += *d; + aSub.GetContainedFiles( o_rResult, + i_sFilter, + i_eRecursivity ); + } +} + +} // namespace ploc +} // namespace csv + + +#elif defined(UNX) +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> + +namespace csv +{ +namespace ploc +{ + +bool +Directory::PhysicalCreate_Dir( const char * i_sStr ) const +{ + return mkdir( i_sStr, 00777 ) == 0; +} + +void +Directory::GetContainedDirectories( StringVector & o_rResult ) const +{ + StreamStr sNew(240); + sNew << aPath; + StreamStr::size_type + nStartFilename = sNew.tellp(); + + DIR * pDir = opendir( StrPath() ); + dirent * pEntry = 0; + struct stat aEntryStatus; + + while ( (pEntry = readdir(pDir)) != 0 ) + { + sNew.seekp(nStartFilename); + sNew << pEntry->d_name; + + stat(sNew.c_str(), &aEntryStatus); + if ( (aEntryStatus.st_mode & S_IFDIR) == S_IFDIR + AND *pEntry->d_name != '.' ) + { + String sNew2(pEntry->d_name); + o_rResult.push_back(sNew2); + } // endif (aEntry.attrib == _A_SUBDIR) + } // end while + closedir( pDir ); +} + +void +Directory::GetContainedFiles( StringVector & o_rResult, + const char * i_sFilter, + E_Recursivity i_eRecursivity ) const +{ + StreamStr sNew(240); + sNew << aPath; + StreamStr::size_type + nStartFilename = sNew.tellp(); + + bool bUseFilter = strcmp( i_sFilter, "*.*" ) != 0 + AND strncmp( i_sFilter, "*.", 2) == 0; + + DIR * pDir = opendir( StrPath() ); + dirent * pEntry = 0; + struct stat aEntryStatus; + + while ( (pEntry = readdir(pDir)) != 0 ) + { + sNew.seekp(nStartFilename); + sNew << pEntry->d_name; + + stat(sNew.c_str(), &aEntryStatus); + if ( (aEntryStatus.st_mode & S_IFDIR) == S_IFDIR ) + continue; // Don't gather directories. + + if ( bUseFilter ) + { + const char * pEnding = strrchr(pEntry->d_name,'.'); + if (pEnding == 0) + continue; + if ( strcasecmp( pEnding + 1, i_sFilter + 2 ) != 0 ) + continue; + } + + sNew.seekp(nStartFilename); + sNew << pEntry->d_name; + String sNewAsString( sNew.c_str() ); + o_rResult.push_back(sNewAsString); + } // end while + + closedir( pDir ); + if ( i_eRecursivity == flat ) + return; + + // gathering from subdirectories: + StringVector aSubDirectories; + GetContainedDirectories( aSubDirectories ); + + StringVector::const_iterator dEnd = aSubDirectories.end(); + for ( StringVector::const_iterator d = aSubDirectories.begin(); + d != dEnd; + ++d ) + { + Directory aSub(*this); + aSub += *d; + aSub.GetContainedFiles( o_rResult, + i_sFilter, + i_eRecursivity ); + } +} + +} // namespace ploc +} // namespace csv + + +#else +#error For using csv::ploc there has to be defined: WNT or UNX. +#endif + + +namespace csv +{ +namespace ploc +{ + +const Path & +Directory::inq_MyPath() const +{ + return aPath; +} + + + +} // namespace ploc +} // namespace csv + + + diff --git a/cosv/source/storage/plocroot.cxx b/cosv/source/storage/plocroot.cxx new file mode 100644 index 000000000000..441a241b3a63 --- /dev/null +++ b/cosv/source/storage/plocroot.cxx @@ -0,0 +1,525 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/ploc.hxx> + +// NOT FULLY DECLARED SERVICES +#include <ctype.h> +#include <cosv/bstream.hxx> +#include <cosv/csv_ostream.hxx> + + +namespace csv +{ +namespace ploc +{ + + +class UnixRootDir : public Root +{ + public: + UnixRootDir(); + + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; +}; + +class WorkingDir : public Root +{ + public: + WorkingDir( + const char * i_sDelimiter = Delimiter() ); + + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; + private: + String sOwnDelimiter; +}; + +class WinRootDir : public Root +{ + public: + WinRootDir(); + + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; +}; + +class WinDrive : public Root +{ + public: + WinDrive( + char i_cDrive ); + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; + private: + char cDrive; +}; + +class WinDriveRootDir : public Root +{ + public: + WinDriveRootDir( + const char * i_sPath ); + WinDriveRootDir( + char i_cDrive ); + + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; + private: + char cDrive; +}; + +class UNCRoot : public Root +{ + public: + UNCRoot( + const char * i_sPath ); + UNCRoot( + const String & i_sComputer, + const String & i_sEntryPt ); + + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; + private: + String sComputer; + String sEntryPt; +}; + +class InvalidRoot : public Root +{ + public: + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; +}; + + +DYN Root * +Create_WindowsRoot( const char * & o_sPathAfterRoot, + const char * i_sPath ) +{ + if (i_sPath[0] == '\\') + { + if (i_sPath[1] == '\\') + { // UNC path name + o_sPathAfterRoot = strchr(i_sPath+2,'\\'); + if (o_sPathAfterRoot != 0) + { + o_sPathAfterRoot = strchr(o_sPathAfterRoot+1,'\\'); + if (o_sPathAfterRoot != 0) + ++o_sPathAfterRoot; + return new UNCRoot(i_sPath); + } + return new InvalidRoot; // Incomplete UNC root. + } + else + { + o_sPathAfterRoot = i_sPath+1; + return new WinRootDir; + } + } + else if (i_sPath[1] == ':') + { + if ( i_sPath[2] == '\\') + { + o_sPathAfterRoot = i_sPath + 3; + return new WinDriveRootDir(i_sPath); + } + else + { + o_sPathAfterRoot = i_sPath + 2; + return new WinDrive(*i_sPath); + } + } + else + { + o_sPathAfterRoot = i_sPath; + return new WorkingDir("\\"); + } +} + +DYN Root * +Create_UnixRoot( const char * & o_sPathAfterRoot, + const char * i_sPath ) +{ + if (*i_sPath == '/') + { + o_sPathAfterRoot = i_sPath + 1; + return new UnixRootDir; + } + else // + { + o_sPathAfterRoot = i_sPath; + return new WorkingDir("/"); + } // endif +} + + +//********************** Root ****************************// + +Root::~Root() +{ + +} + +DYN Root * +Root::Create_( const char * & o_sPathAfterRoot, + const char * i_sPath, + const char * i_sDelimiter ) +{ + if (i_sPath[0] == '.') + { + switch ( i_sPath[1] ) + { + case '\0': o_sPathAfterRoot = i_sPath + 1; + break; + case '\\': o_sPathAfterRoot = i_sPath + 2; + break; + case '/': o_sPathAfterRoot = i_sPath + 2; + break; + case '.': o_sPathAfterRoot = i_sPath; + break; + default: + o_sPathAfterRoot = 0; + return new InvalidRoot; + } // end switch (i_sPath[1]) + + return new WorkingDir; + } // end if (i_sPath[0] == '.') + + switch (*i_sDelimiter) + { + case '\\': return Create_WindowsRoot(o_sPathAfterRoot, i_sPath); + case '/': return Create_UnixRoot(o_sPathAfterRoot, i_sPath); + } + + o_sPathAfterRoot = 0; + return new InvalidRoot; +} + + + +//********************** UnixRootDir ****************************// + + +UnixRootDir::UnixRootDir() +{ +} + +void +UnixRootDir::Get( ostream & o_rPath ) const +{ + o_rPath << '/'; +} + +void +UnixRootDir::Get( bostream & o_rPath ) const +{ + o_rPath.write( "/", 1 ); +} + +DYN Root * +UnixRootDir::CreateCopy() const +{ + return new UnixRootDir; +} + +const char * +UnixRootDir::OwnDelimiter() const +{ + return "/"; +} + + +//********************** WorkingDir ****************************// + +WorkingDir::WorkingDir( const char * i_sDelimiter ) + : sOwnDelimiter(i_sDelimiter) +{ +} + +void +WorkingDir::Get( ostream & o_rPath ) const +{ + o_rPath << '.' << sOwnDelimiter; +} + +void +WorkingDir::Get( bostream & o_rPath ) const +{ + o_rPath.write( ".", 1 ); + o_rPath.write( sOwnDelimiter ); +} + +DYN Root * +WorkingDir::CreateCopy() const +{ + return new WorkingDir(sOwnDelimiter); +} + +const char * +WorkingDir::OwnDelimiter() const +{ + return sOwnDelimiter; +} + + +//********************** WinRootDir ****************************// + +WinRootDir::WinRootDir() +{ +} + +void +WinRootDir::Get( ostream & o_rPath ) const +{ + o_rPath << '\\'; +} + +void +WinRootDir::Get( bostream & o_rPath ) const +{ + o_rPath.write( "\\", 1 ); +} + +DYN Root * +WinRootDir::CreateCopy() const +{ + return new WinRootDir; +} + +const char * +WinRootDir::OwnDelimiter() const +{ + return "\\"; +} + + +//********************** WinDrive ****************************// + +WinDrive::WinDrive( char i_cDrive ) + : cDrive(static_cast< char >(toupper(i_cDrive))) +{ +} + +void +WinDrive::Get( ostream & o_rPath ) const +{ + o_rPath << cDrive << ':'; +} + +void +WinDrive::Get( bostream & o_rPath ) const +{ + static char buf_[3] = " :"; + buf_[0] = cDrive; + o_rPath.write( &buf_[0], 2 ); +} + +DYN Root * +WinDrive::CreateCopy() const +{ + return new WinDrive(cDrive); +} + +const char * +WinDrive::OwnDelimiter() const +{ + return "\\"; +} + + +//********************** WinDriveRootDir ****************************// + +WinDriveRootDir::WinDriveRootDir( const char * i_sPath ) + : cDrive(static_cast< char >(toupper(*i_sPath))) +{ + if ( 'A' > cDrive OR 'Z' < cDrive ) + cDrive = 0; +} + +WinDriveRootDir::WinDriveRootDir( char i_cDrive ) + : cDrive(i_cDrive) +{ +} + +void +WinDriveRootDir::Get( ostream & o_rPath ) const +{ + o_rPath << cDrive << ":\\"; +} + +void +WinDriveRootDir::Get( bostream & o_rPath ) const +{ + static char buf_[4] = " :\\"; + buf_[0] = cDrive; + o_rPath.write( &buf_[0], 3 ); +} + +DYN Root * +WinDriveRootDir::CreateCopy() const +{ + return new WinDriveRootDir(cDrive); +} + +const char * +WinDriveRootDir::OwnDelimiter() const +{ + return "\\"; +} + + +//********************** UNCRoot ****************************// + +UNCRoot::UNCRoot( const char * i_sPath ) +// : // sComputer, + // sEntryPt +{ + const char * pRestPath = i_sPath + 2; + const char * pDirEnd = strchr(pRestPath, '\\'); + csv_assert(pDirEnd != 0); + + sComputer = String(pRestPath, pDirEnd - pRestPath); + pRestPath = pDirEnd+1; + pDirEnd = strchr(pRestPath, '\\'); + + if ( pDirEnd != 0 ) + { + sEntryPt = String(pRestPath, pDirEnd - pRestPath); + } + else + { + sEntryPt = pRestPath; + } +} + +UNCRoot::UNCRoot( const String & i_sComputer, + const String & i_sEntryPt ) + : sComputer(i_sComputer), + sEntryPt(i_sEntryPt) +{ +} + +void +UNCRoot::Get( ostream & o_rPath ) const +{ + o_rPath << "\\\\" << sComputer << '\\' << sEntryPt << "\\"; +} + +void +UNCRoot::Get( bostream & o_rPath ) const +{ + o_rPath.write( "\\\\", 2 ); + o_rPath.write( sComputer ); + o_rPath.write( "\\", 1 ); + o_rPath.write( sEntryPt ); + o_rPath.write( "\\", 1 ); +} + +DYN Root * +UNCRoot::CreateCopy() const +{ + return new UNCRoot(sComputer,sEntryPt); +} + +const char * +UNCRoot::OwnDelimiter() const +{ + return "\\"; +} + + + +//********************** InvalidRoot ****************************// + +void +InvalidRoot::Get( ostream & ) const +{ +} + +void +InvalidRoot::Get( bostream & ) const +{ +} + +DYN Root * +InvalidRoot::CreateCopy() const +{ + return new InvalidRoot; +} + +const char * +InvalidRoot::OwnDelimiter() const +{ + return 0; +} + + + + +} // namespace ploc +} // namespace csv + + + diff --git a/cosv/source/strings/makefile.mk b/cosv/source/strings/makefile.mk new file mode 100644 index 000000000000..2bd9bab1ddc8 --- /dev/null +++ b/cosv/source/strings/makefile.mk @@ -0,0 +1,58 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cosv +TARGET=cosv_strings + +ENABLE_EXCEPTIONS=true + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.INCLUDE : $(PRJ)$/source$/fullcpp.mk + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/str_types.obj \ + $(OBJ)$/streamstr.obj \ + $(OBJ)$/string.obj + + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + + diff --git a/cosv/source/strings/str_types.cxx b/cosv/source/strings/str_types.cxx new file mode 100644 index 000000000000..5508d3517ecb --- /dev/null +++ b/cosv/source/strings/str_types.cxx @@ -0,0 +1,44 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/str_types.hxx> + + + +namespace csv +{ + +CharOrder_Table::CharOrder_Table( const int * i_pCharWeightsArray ) +{ + memcpy( cWeights, i_pCharWeightsArray, 256 * sizeof(int) ); +} + + +} // namespace csv + + diff --git a/cosv/source/strings/streamstr.cxx b/cosv/source/strings/streamstr.cxx new file mode 100644 index 000000000000..371d9b36c02a --- /dev/null +++ b/cosv/source/strings/streamstr.cxx @@ -0,0 +1,981 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/streamstr.hxx> + +// NOT FULLY DECLARED SERVICES +#include <string.h> +#include <stdio.h> +#include <stdarg.h> // both are needed to satisfy all compilers +#include <cstdarg> // std::va_list and friends + +#include <cosv/comfunc.hxx> +#include <cosv/tpl/swelist.hxx> + + + +namespace csv +{ + + +// Maximal sizes of resulting integers in text form: +const uintt C_short_max_size = sizeof(short) * 3; +const uintt C_int_max_size = sizeof(int) * 3; +const uintt C_long_max_size = sizeof(long) * 3; + + +inline void +StreamStr::Advance(size_type i_nAddedSize) +{ pCur += i_nAddedSize; } + + + +StreamStr::StreamStr( size_type i_nCapacity ) + : bostream(), + nCapacity1( i_nCapacity + 1 ), + dpData( new char [i_nCapacity + 1] ), + pEnd(dpData), + pCur(dpData), + eMode(str::overwrite) +{ + *pEnd = '\0'; +} + +StreamStr::StreamStr( const char * i_sInitStr, + size_type i_nCapacity ) + : bostream(), + nCapacity1(0), + dpData(0), + pEnd(0), + pCur(0), + eMode(str::overwrite) +{ + size_type nLength = strlen(i_sInitStr); + nCapacity1 = csv::max(nLength, i_nCapacity) + 1; + dpData = new char [nCapacity1]; + strcpy(dpData, i_sInitStr); // SAFE STRCPY (#100211# - checked) + pCur = dpData + nLength; + pEnd = pCur; +} + +StreamStr::StreamStr( size_type i_nGuessedCapacity, + const char * str1, + const char * str2, + ... ) + : bostream(), + nCapacity1( i_nGuessedCapacity + 1 ), + dpData( new char [i_nGuessedCapacity + 1] ), + pEnd(dpData), + pCur(dpData), + eMode(str::overwrite) +{ + *pEnd = '\0'; + + operator<<(str1); + operator<<(str2); + + ::va_list ap; + + va_start(ap, str2); + for ( const char * strAdd = va_arg(ap,const char*); + strAdd != 0; + strAdd = va_arg(ap,const char*) ) + { + size_type nLen = strlen(strAdd); + ProvideAddingSize( nLen ); + memcpy(pCur, strAdd, nLen); + Advance(nLen); + } // end for + va_end(ap); +} + +StreamStr::StreamStr( const self & i_rOther ) + : bostream(), + nCapacity1( i_rOther.nCapacity1 ), + dpData( new char [i_rOther.nCapacity1] ), + pEnd( dpData + strlen(i_rOther.dpData) ), + pCur( dpData + i_rOther.tellp() ), + eMode(i_rOther.eMode) +{ + strcpy( dpData, i_rOther.dpData ); // SAFE STRCPY (#100211# - checked) +} + +StreamStr::StreamStr(csv::bstream & i_source) + : bostream(), + nCapacity1(0), + dpData(0), + pEnd(0), + pCur(0), + eMode(str::overwrite) +{ + i_source.seek(0, csv::end); + nCapacity1 = static_cast<size_type>(i_source.position()) + 1; + i_source.seek(0); + + dpData = new char[nCapacity1]; + i_source.read(dpData, nCapacity1 - 1); + pCur = dpData + nCapacity1 - 1; + pEnd = pCur; + *pCur = '\0'; +} + +StreamStr::~StreamStr() +{ + delete [] dpData; +} + + +StreamStr & +StreamStr::operator=( const self & i_rOther ) +{ + delete [] dpData; + + nCapacity1 = i_rOther.nCapacity1; + dpData = new char [i_rOther.nCapacity1]; + pEnd = dpData + strlen(i_rOther.dpData); + strcpy( dpData, i_rOther.dpData ); // SAFE STRCPY (#100211# - checked) + pCur = dpData + i_rOther.tellp(); + eMode = i_rOther.eMode; + + return *this; +} + +StreamStr & +StreamStr::operator<<( const char * i_s ) +{ + size_type nLength = strlen(i_s); + + ProvideAddingSize( nLength ); + memcpy( pCur, i_s, nLength ); + Advance(nLength); + + return *this; +} + +StreamStr & +StreamStr::operator<<( const String & i_s ) +{ + size_type nLength = i_s.length(); + + ProvideAddingSize( nLength ); + memcpy( pCur, i_s.c_str(), nLength ); + Advance(nLength); + + return *this; +} + +StreamStr & +StreamStr::operator<<( char i_c ) +{ + ProvideAddingSize( 1 ); + *pCur = i_c; + Advance(1); + + return *this; +} + +StreamStr & +StreamStr::operator<<( unsigned char i_c ) +{ + return operator<<( char(i_c) ); +} + +StreamStr & +StreamStr::operator<<( signed char i_c ) +{ + return operator<<( char(i_c) ); +} + +StreamStr & +StreamStr::operator<<( short i_n ) +{ + char buf[C_short_max_size] = ""; + sprintf( buf, "%hi", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( unsigned short i_n ) +{ + char buf[C_short_max_size] = ""; + sprintf( buf, "%hu", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( int i_n ) +{ + char buf[C_int_max_size] = ""; + sprintf( buf, "%i", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( unsigned int i_n ) +{ + char buf[C_int_max_size] = ""; + sprintf( buf, "%u", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( long i_n ) +{ + char buf[C_long_max_size] = ""; + sprintf( buf, "%li", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( unsigned long i_n ) +{ + char buf[C_long_max_size] = ""; + sprintf( buf, "%lu", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( float i_n ) +{ + const int C_float_max_size = 20; + char buf[C_float_max_size] = ""; + sprintf( buf, "%.*g", C_float_max_size-8, i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( double i_n ) +{ + const int C_double_max_size = 30; + char buf[C_double_max_size] = ""; + sprintf( buf, "%.*lg", C_double_max_size-8, i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +const char & +StreamStr::operator[]( position_type i_nPosition ) const +{ + static const char aNull_ = '\0'; + + if ( position_type(pEnd - dpData) > i_nPosition ) + return dpData[i_nPosition]; + return aNull_; +} + +char & +StreamStr::operator[]( position_type i_nPosition ) +{ + static char aDummy_ = '\0'; + + if ( position_type(pEnd - dpData) > i_nPosition ) + return dpData[i_nPosition]; + return aDummy_; +} + +void +StreamStr::resize( size_type i_nMinimumCapacity ) +{ + if ( i_nMinimumCapacity <= capacity() ) + return; + + Resize(i_nMinimumCapacity); +} + +void +StreamStr::swap( StreamStr & io_swap ) +{ + size_type + n = io_swap.nCapacity1; + io_swap.nCapacity1 = nCapacity1; + nCapacity1 = n; + + char * + p = io_swap.dpData; + io_swap.dpData = dpData; + dpData = p; + + p = io_swap.pEnd; + io_swap.pEnd = pEnd; + pEnd = p; + + p = io_swap.pCur; + io_swap.pCur = pCur; + pCur = p; + + insert_mode + m = io_swap.eMode; + io_swap.eMode = eMode; + eMode = m; +} + +StreamStr & +StreamStr::seekp( seek_type i_nCount, + seek_dir i_eDirection ) +{ + seek_type nLength = seek_type( length() ); + seek_type nNewPos = tellp(); + + switch ( i_eDirection ) + { + case ::csv::beg: nNewPos = i_nCount; + break; + case ::csv::cur: nNewPos += i_nCount; + break; + case ::csv::end: nNewPos = nLength + i_nCount; + break; + } + + if ( in_range<seek_type>(0, nNewPos, nLength + 1) ) + { + pCur = dpData + nNewPos; + if (eMode == str::overwrite) + { + pEnd = pCur; + *pEnd = '\0'; + } + } + + return *this; +} + +StreamStr & +StreamStr::set_insert_mode( insert_mode i_eMode ) +{ + eMode = i_eMode; + return *this; +} + +void +StreamStr::push_front( const char * i_str ) +{ + insert_mode eOriginalMode = eMode; + char * pOriginalCur = pCur; + eMode = str::insert; + pCur = dpData; + + operator<<(i_str); + + eMode = eOriginalMode; + pCur = pOriginalCur + strlen(i_str); +} + +void +StreamStr::push_front( char i_c ) +{ + insert_mode eOriginalMode = eMode; + char * pOriginalCur = pCur; + eMode = str::insert; + pCur = dpData; + + operator<<(i_c); + + eMode = eOriginalMode; + pCur = pOriginalCur + 1; +} + +void +StreamStr::push_back( const char * i_str ) +{ + insert_mode eOriginalMode = eMode; + eMode = str::overwrite; + + operator<<(i_str); + + eMode = eOriginalMode; +} + +void +StreamStr::push_back( char i_c ) +{ + insert_mode eOriginalMode = eMode; + eMode = str::overwrite; + + operator<<(i_c); + + eMode = eOriginalMode; +} + +void +StreamStr::pop_front( size_type i_nCount ) +{ + size_type nCount = min(i_nCount, length()); + + MoveData( dpData + nCount, pEnd, -(seek_type(nCount)) ); + + pCur -= nCount; + pEnd -= nCount; + *pEnd = '\0'; +} + +void +StreamStr::pop_back( size_type i_nCount ) +{ + size_type nCount = min(i_nCount, length()); + pEnd -= nCount; + if (pCur > pEnd) + pCur = pEnd; + *pEnd = '\0'; +} + +StreamStr & +StreamStr::operator_join( std::vector<String>::const_iterator i_rBegin, + std::vector<String>::const_iterator i_rEnd, + const char * i_sLink ) +{ + std::vector<String>::const_iterator it = i_rBegin; + if ( it != i_rEnd ) + { + operator<<(*it); + for ( ++it; it != i_rEnd; ++it ) + { + operator<<(i_sLink); + operator<<(*it); + } + } + return *this; +} + +StreamStr & +StreamStr::operator_add_substr( const char * i_sText, + size_type i_nLength ) +{ + size_type nLength = csv::min<size_type>(i_nLength, strlen(i_sText)); + + ProvideAddingSize( nLength ); + memcpy( pCur, i_sText, nLength ); + Advance(nLength); + + return *this; +} + +StreamStr & +StreamStr::operator_add_token( const char * i_sText, + char i_cDelimiter ) +{ + const char * pTokenEnd = strchr(i_sText, i_cDelimiter); + if (pTokenEnd == 0) + operator<<(i_sText); + else + operator_add_substr(i_sText, pTokenEnd-i_sText); + return *this; +} + +StreamStr & +StreamStr::operator_read_line( bstream & i_src ) +{ + char c = 0; + intt nCount = 0; + for ( nCount = i_src.read(&c, 1); + nCount == 1 AND c != 13 AND c != 10; + nCount = i_src.read(&c, 1) ) + { + operator<<(c); + } + + bool bEndOfStream = nCount == 0; + // Check for line-end: + if ( NOT bEndOfStream AND c != 0 ) + { + char oldc = c; + if (i_src.read(&c, 1) == 1) + { + if ( (c != 13 AND c != 10) OR c == oldc) + i_src.seek(-1,::csv::cur); + } + } + return *this; +} + +void +StreamStr::strip_front(char i_cToRemove) +{ + const_iterator it = begin(); + for ( ; + it != end() ? *it == i_cToRemove : false; + ++it ) ; + pop_front(it - begin()); +} + +void +StreamStr::strip_back(char i_cToRemove) +{ + const_iterator it = end(); + for ( ; + it != begin() ? *(it-1) == i_cToRemove : false; + --it ) ; + pop_back(end() - it); +} + +void +StreamStr::strip_frontback(char i_cToRemove) +{ + strip_front(i_cToRemove); + strip_back(i_cToRemove); +} + +void +StreamStr::strip_front_whitespace() +{ + const_iterator it = begin(); + for ( ; + it != end() ? *it < 33 : false; + ++it ) ; + pop_front(it - begin()); +} + +void +StreamStr::strip_back_whitespace() +{ + const_iterator it = end(); + for ( ; + it != begin() ? *(it-1) < 33 : false; + --it ) ; + pop_back(end() - it); +} + +void +StreamStr::strip_frontback_whitespace() +{ + strip_front_whitespace(); + strip_back_whitespace(); +} + +void +StreamStr::remove( iterator i_begin, + iterator i_end ) +{ + csv_assert(i_begin >= dpData AND i_begin <= pEnd); + csv_assert(i_end >= dpData AND i_end <= pEnd); + csv_assert(i_end >= i_begin); + MoveData(i_end, pEnd, i_begin - i_end); + pCur = pEnd; +} + +void +StreamStr::replace( position_type i_nStart, + size_type i_nSize, + Area i_aReplacement ) +{ + if (i_nStart >= length() OR i_nSize < 1) + return; + + insert_mode eOldMode = eMode; + eMode = str::insert; + pCur = dpData + i_nStart; + + size_type anz = min( length() - i_nStart, i_nSize ); + + if ( anz < i_aReplacement.nLength ) + { + ProvideAddingSize( i_aReplacement.nLength - anz ); + } + else if ( anz > i_aReplacement.nLength ) + { + seek_type nMove = seek_type(anz - i_aReplacement.nLength); + + MoveData( dpData + i_nStart + anz, + pEnd, + -nMove ); + pEnd -= nMove; + *pEnd = '\0'; + } + + if (i_aReplacement.nLength > 0) + { + memcpy( dpData + i_nStart, i_aReplacement.sStr, i_aReplacement.nLength ); + Advance(i_aReplacement.nLength); + } + + eMode = eOldMode; + pCur = pEnd; +} + +void +StreamStr::replace_all( char i_cCarToSearch, + char i_cReplacement ) +{ + for ( char * p = dpData; p != pEnd; ++p ) + { + if (*p == i_cCarToSearch) + *p = i_cReplacement; + } +} + +void +StreamStr::replace_all( Area i_aStrToSearch, + Area i_aReplacement ) +{ + position_type p = 0; + const char * pSearch = i_aStrToSearch.sStr; + size_type nSearch = i_aStrToSearch.nLength; + + while ( p <= length() - nSearch ) + { + if ( strncmp(dpData+p, pSearch, nSearch) == 0 ) + { + replace( p, nSearch, i_aReplacement ); + p += i_aReplacement.nLength; + } + else + { + ++p; + } + } // end while +} + +StreamStr & +StreamStr::to_lower( position_type i_nStart, + size_type i_nLength ) +{ + static char cLower[128] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119,120,121,122, 91, 92, 93, 94, 95, + 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127 }; + + if ( i_nStart < length() ) + { + char * pStop = i_nStart + i_nLength < length() + ? dpData + i_nStart + i_nLength + : pEnd; + for ( char * pChange = dpData + i_nStart; + pChange != pStop; + ++pChange ) + { + *pChange = (static_cast< unsigned char >(*pChange) & 0x80) == 0 + ? cLower[ UINT8(*pChange) ] + : *pChange; + } + } + return *this; +} + +StreamStr & +StreamStr::to_upper( position_type i_nStart, + size_type i_nLength ) +{ + static char cUpper[128] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123,124,125,126,127 }; + + if ( i_nStart < length() ) + { + char * pStop = i_nStart + i_nLength < length() + ? dpData + i_nStart + i_nLength + : pEnd; + for ( char * pChange = dpData + i_nStart; + pChange != pStop; + ++pChange ) + { + *pChange = (static_cast< unsigned char >(*pChange) & 0x80) == 0 + ? cUpper[ UINT8(*pChange) ] + : *pChange; + } + } + return *this; +} + + +StreamStr::size_type +StreamStr::token_count( char i_cSplit ) const +{ + return count_chars(dpData, i_cSplit) + 1; +} + +String +StreamStr::token( position_type i_nNr, + char i_cSplit ) const +{ + // Find begin: + const char * pTokenBegin = dpData; + for ( position_type nNr = i_nNr; + nNr > 0; + --nNr ) + { + pTokenBegin = strchr(pTokenBegin,i_cSplit); + if (pTokenBegin == 0) + return String(""); + ++pTokenBegin; + } + + // Find end: + const char * pTokenEnd = strchr(pTokenBegin, i_cSplit); + if (pTokenEnd == 0) + pTokenEnd = pEnd; + + return String(pTokenBegin, size_type(pTokenEnd-pTokenBegin) ); +} + +class StreamStrPool +{ + public: + StreamStrPool(); + ~StreamStrPool(); + private: + // Non-copyable + StreamStrPool(StreamStrPool &); // not defined + void operator =(StreamStrPool &); // not defined + + // Interface to: + friend class StreamStrLock; + static StreamStr & AcquireFromPool_( + uintt i_nMinimalSize ); + static void ReleaseToPool_( + DYN StreamStr * let_dpUsedStr ); + + // DATA + SweList< DYN StreamStr* > + aPool; +}; + +StreamStrPool::StreamStrPool() +{ +} + +StreamStrPool::~StreamStrPool() +{ + for ( SweList< DYN StreamStr* >::iterator it = aPool.begin(); + it != aPool.end(); + ++it ) + { + delete (*it); + } +} + +namespace +{ + static StreamStrPool aPool_; +} + + +StreamStr & +StreamStrPool::AcquireFromPool_( uintt i_nMinimalSize ) +{ + if ( aPool_.aPool.empty() ) + { + return *new StreamStr(i_nMinimalSize); + } + + StreamStr & ret = *aPool_.aPool.front(); + aPool_.aPool.pop_front(); + ret.resize(i_nMinimalSize); + ret.seekp(0); + ret.set_insert_mode(str::overwrite); + return ret; +} + +void +StreamStrPool::ReleaseToPool_( DYN StreamStr * let_dpUsedStr ) +{ + aPool_.aPool.push_back( let_dpUsedStr ); +} + +StreamStrLock::StreamStrLock( uintt i_nMinimalSize ) + : pStr( &StreamStrPool::AcquireFromPool_(i_nMinimalSize) ) +{ +} + +StreamStrLock::~StreamStrLock() +{ + StreamStrPool::ReleaseToPool_(pStr); +} + + +UINT32 +StreamStr::do_write( const void * i_pSrc, + UINT32 i_nNrofBytes ) +{ + ProvideAddingSize( i_nNrofBytes ); + memcpy( pCur, i_pSrc, i_nNrofBytes ); + Advance(i_nNrofBytes); + + return i_nNrofBytes; +} + +void +StreamStr::ProvideAddingSize( size_type i_nSize2Add ) +{ + size_type nLength = length(); + if ( capacity() - nLength < i_nSize2Add ) + Resize( nLength + i_nSize2Add ); + + pEnd += i_nSize2Add; + *pEnd = '\0'; + + if (eMode == str::insert AND pCur != pEnd) + { + MoveData( pCur, pCur + i_nSize2Add, seek_type(i_nSize2Add) ); + } +} + +void +StreamStr::Resize( size_type i_nMinimumCapacity ) +{ + size_type nNewSize = nCapacity1 < 128 + ? nCapacity1 << 1 + : (nCapacity1 << 1) - (nCapacity1 >> 1); + nCapacity1 = csv::max( nNewSize, size_type(i_nMinimumCapacity + 1) ); + + char * pNew = new char[nCapacity1]; + strcpy ( pNew, dpData ); // SAFE STRCPY (#100211# - checked) + pEnd = pNew + (pEnd - dpData); + pCur = pNew + (pCur - dpData); + + delete [] dpData; + dpData = pNew; +} + +void +StreamStr::MoveData( char * i_pStart, + char * i_pEnd, + seek_type i_nDiff ) +{ + if (i_nDiff > 0) + { + register const char * pSrc = i_pEnd; + register char * pDest = i_pEnd + i_nDiff; + for ( ; pSrc != i_pStart; --pSrc, --pDest ) + { + *pDest = *pSrc; + } + *pDest = *pSrc; + } + else if (i_nDiff < 0) + { + const char * pSrc = i_pStart; + char * pDest = i_pStart + i_nDiff; + for ( ; pSrc != i_pEnd; ++pSrc, ++pDest ) + { + *pDest = *pSrc; + } + } +} + +// Does nothing, only the name of this function is needed. +void +c_str() +{ + // Does nothing. +} + + + +void +Split( std::vector<String> & o_list, + const char * i_text ) +{ + const char * + pCurrentToken = 0; + bool + white = false; + for (const char * p = i_text; *p != '\0'; ++p) + { + white = UINT8(*p) > 32; + if (pCurrentToken != 0) + { + if (white) + { + o_list.push_back(String(pCurrentToken, p)); + pCurrentToken = 0; + } + } + else + { + if ( NOT white) + pCurrentToken = p; + } // endif (bInToken) else + } // end for + + if (pCurrentToken != 0) + { + o_list.push_back(String(pCurrentToken)); + } +} + + + + +} // namespace csv diff --git a/cosv/source/strings/string.cxx b/cosv/source/strings/string.cxx new file mode 100644 index 000000000000..92ac305f8f32 --- /dev/null +++ b/cosv/source/strings/string.cxx @@ -0,0 +1,414 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/string.hxx> + +// NOT FULLY DECLARED SERVICES +#include <string.h> +#include <cosv/comfunc.hxx> + + + + +namespace csv +{ + + +inline const char * +str_from_StringOffset( const String & i_rStr, + str::size i_nOffset ) +{ + return i_nOffset < i_rStr.size() + ? i_rStr.c_str() + i_nOffset + : ""; +} + +inline const char * +str_from_ptr( const char * i_str ) +{ + + return valid_str(i_str); +} + + +//********************* String::S_Data **********************// + +inline String:: +S_Data::S_Data() + : nCount(1) +{ +} + +String:: +S_Data::S_Data( const char * i_sData, + size_type i_nValidLength ) + : aStr( str_from_ptr(i_sData), + (i_nValidLength != str::maxsize + ? i_nValidLength + : strlen(i_sData)) ), + nCount(1) +{ +} + +String:: +S_Data::~S_Data() +{ + csv_assert( nCount == 0 ); +} + +const String::S_Data * +String:: +S_Data::Acquire() const +{ +#ifdef CSV_NO_MUTABLE + ++ (const_cast< uintt& >(nCount)); +#else + ++nCount; +#endif + return this; +} + +void +String:: +S_Data::Release() const +{ +#ifdef CSV_NO_MUTABLE + -- (const_cast< uintt& >(nCount)); +#else + --nCount; +#endif + if (nCount == 0) + delete (const_cast< S_Data* >(this)); +} + + +//************************** String **************************// + + +String::String() + : pd( String::Null_().pd->Acquire() ) +{ +} + +String::String( const char * i_str ) + : pd( new S_Data(i_str) ) +{ +} + +String::String( const char * i_str, + size_type i_nLength ) + : pd( new S_Data(i_str, i_nLength) ) +{ +} + +/* For efficiency see the previous c'tor. +*/ +String::String( const self & i_rStr, + position_type i_nStartPosition, + size_type i_nLength ) + : pd( new S_Data(str_from_StringOffset(i_rStr, i_nStartPosition), i_nLength) ) +{ +} + +String::String( const_iterator i_itBegin, + const_iterator i_itEnd ) + : pd( new S_Data(i_itBegin, size_type(i_itEnd - i_itBegin)) ) +{ +} + +String::String( const self & i_rStr ) + : pd( i_rStr.pd->Acquire() ) +{ +} + +String::~String() +{ + pd->Release(); +} + + +String & +String::operator=( const self & i_rStr ) +{ + i_rStr.pd->Acquire(); + pd->Release(); + pd = i_rStr.pd; + + return *this; +} + +String & +String::operator=( const char * i_str ) +{ + const S_Data * + pTemp = new S_Data(i_str); + pd->Release(); + pd = pTemp; + + return *this; +} + +void +String::swap( self & i_rStr ) +{ + const S_Data * pTemp = pd; + pd = i_rStr.pd; + i_rStr.pd = pTemp; +} + +void +String::assign( const self & i_rStr, + position_type i_nStartPosition, + size_type i_nLength ) +{ + const S_Data * + pTemp = new S_Data( str_from_StringOffset(i_rStr, i_nStartPosition), + i_nLength ); + pd->Release(); + pd = pTemp; +} + +void +String::assign( const char * i_str ) +{ + const S_Data * + pTemp = new S_Data( i_str ); + pd->Release(); + pd = pTemp; +} + +void +String::assign( const char * i_str, + size_type i_nLength ) +{ + const S_Data * + pTemp = new S_Data( i_str, i_nLength ); + pd->Release(); + pd = pTemp; +} + +void +String::assign( const_iterator i_itBegin, + const_iterator i_itEnd ) +{ + const S_Data * + pTemp = new S_Data( i_itBegin, + size_type(i_itEnd - i_itBegin) ); + pd->Release(); + pd = pTemp; +} + + +int +String::compare( const self & i_rStr ) const +{ + return strcmp( c_str(), i_rStr.c_str() ); +} + +int +String::compare( const CharOrder_Table & i_rOrder, + const self & i_rStr ) const +{ + return csv::compare( i_rOrder, c_str(), i_rStr.c_str() ); +} + +String +String::substr( position_type i_nStartPosition, + size_type i_nLength ) const +{ + size_type nSize = size(); + + if ( i_nStartPosition < nSize ) + { + if ( i_nLength == str::maxsize + OR i_nLength >= nSize - i_nStartPosition ) + return String( c_str() + i_nStartPosition ); + else + return String( c_str() + i_nStartPosition, + i_nLength ); + } + + return Null_(); +} + +String::position_type +String::find( const char * i_strToSearch, + position_type i_nSearchStartPosition ) const +{ + csv_assert(i_strToSearch != 0); + + if ( i_nSearchStartPosition < length() + AND + *i_strToSearch != '\0' ) + { + const char * p = strstr(c_str() + i_nSearchStartPosition, i_strToSearch); + if (p != 0) + return static_cast<position_type>(p - c_str()); + } + return str::position(str::npos); +} + +String::position_type +String::find( char i_charToSearch, + position_type i_nSearchStartPosition ) const +{ + if (i_nSearchStartPosition <= length()) + { + const char * p = strchr(c_str() + i_nSearchStartPosition, i_charToSearch); + if (p != 0) + return static_cast<position_type>(p - c_str()); + } + return str::position(str::npos); +} + +const String & +String::Null_() +{ + // Must not use the default constructor! Because that one calls + // this function, which would create a circular dependency. + static const String aNull_(""); + return aNull_; +} + +const char & +String::Nulch_() +{ + static const char cNull_ = '\0'; + return cNull_; +} + + +int +compare( const String & i_s1, + csv::str::position i_nStartPosition1, + const char * i_s2, + csv::str::size i_nLength ) +{ + const char * pS1 = str_from_StringOffset( i_s1, i_nStartPosition1 ); + + if ( i_nLength != csv::str::maxsize ) + return strncmp( pS1, + i_s2, + i_nLength ); + else + return strcmp( pS1, + i_s2 ); +} + +int +compare( const char * i_s1, + const String & i_s2, + csv::str::position i_nStartPosition2, + csv::str::size i_nLength ) +{ + const char * pS2 = str_from_StringOffset( i_s2, i_nStartPosition2 ); + + if ( i_nLength != csv::str::maxsize ) + return strncmp( i_s1, + pS2, + i_nLength ); + else + return strcmp( i_s1, + pS2 ); +} + +int +compare( const CharOrder_Table & i_rOrder, + const char * i_s1, + const char * i_s2 ) +{ + const char * it1 = i_s1; + const char * it2 = i_s2; + for ( ; i_rOrder(*it1) == i_rOrder(*it2) AND *it1 != '\0'; ++it1, ++it2 ) + {} + return int( i_rOrder(*it1) - i_rOrder(*it2) ); +} + +int +compare( const CharOrder_Table & i_rOrder, + const String & i_s1, + csv::str::position i_nStartPosition1, + const char * i_s2, + csv::str::size i_nLength ) +{ + const char * pS1 = str_from_StringOffset( i_s1, i_nStartPosition1 ); + + if ( i_nLength != csv::str::maxsize ) + return compare( i_rOrder, + pS1, + i_s2, + i_nLength ); + else + return compare( i_rOrder, + pS1, + i_s2 ); +} + +int +compare( const CharOrder_Table & i_rOrder, + const char * i_s1, + const String & i_s2, + csv::str::position i_nStartPosition2, + csv::str::size i_nLength ) +{ + const char * pS2 = str_from_StringOffset( i_s2, i_nStartPosition2 ); + + if ( i_nLength != csv::str::maxsize ) + return compare( i_rOrder, + i_s1, + pS2, + i_nLength ); + else + return compare( i_rOrder, + i_s1, + pS2 ); +} + +int +compare( const CharOrder_Table & i_rOrder, + const char * i_s1, + const char * i_s2, + csv::str::size i_nLength ) +{ + const char * sEnd = i_s1 + i_nLength; + + const char * it1 = i_s1; + const char * it2 = i_s2; + for ( ; i_rOrder(*it1) == i_rOrder(*it2) AND *it1 != '\0' AND it1 != sEnd; ++it1, ++it2 ) + {} + + if ( it1 != sEnd ) + return int( i_rOrder(*it1) - i_rOrder(*it2) ); + else + return 0; +} + + + + +} // namespace csv diff --git a/cosv/source/unittest/file_ut.cxx b/cosv/source/unittest/file_ut.cxx new file mode 100644 index 000000000000..b1c2a0a17cb9 --- /dev/null +++ b/cosv/source/unittest/file_ut.cxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/file.hxx> + +// NOT FULLY DECLARED SERVICES +#include <ut.hxx> + +using csv::File; + + +/** @file + UnitTests for class File. +*/ + +FUT_DECL( File, Read ); +FUT_DECL( File, Write ); +FUT_DECL( File, Seek ); +FUT_DECL( File, SeekBack ); +FUT_DECL( File, SeekRelative ); + + +bool +classtest_File() +{ + csv::File aFile( "bigfile.txt", csv::CFM_RW, 0 ); + csv::File & rFile = aFile; + + rFile.Open(); + + bool ret = ftest_Read( rFile ); + ret = ftest_Write( rFile ) AND ret; + ret = ftest_SeekBack( rFile ) AND ret; + ret = ftest_SeekRelative( rFile ) AND ret; + + rFile.Close(); + + return ret; +} + + + +FUT_DECL( File, Read ) +{ + bool ret = true; + + rFile.SeekBack(0); + uintt nSourceSize = rFile.Position(); + rFile.Seek(0); + + char * pBuf = new char[nSourceSize+1]; + uintt nCount = rFile.Read(pBuf,nSourceSize); + + UT_CHECK( Read, nCount == nSourceSize ); + + return ret; +} + +FUT_DECL( File, Write ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( File, Seek ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( File, SeekBack ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( File, SeekRelative ) +{ + bool ret = true; + + + + return ret; +} + + + diff --git a/cosv/source/unittest/makefile.mk b/cosv/source/unittest/makefile.mk new file mode 100644 index 000000000000..173ce8c991fe --- /dev/null +++ b/cosv/source/unittest/makefile.mk @@ -0,0 +1,80 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cosv +TARGET=cosv_unittest +TARGETTYPE=CUI + +# --- Settings ----------------------------------------------------- + +ENABLE_EXCEPTIONS=true +PRJINC=$(PRJ)$/source + +.INCLUDE : settings.mk +.INCLUDE : static.mk + +.INCLUDE : $(PRJ)$/source$/fullcpp.mk + + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/file_ut.obj \ + $(OBJ)$/simplestring_ut.obj + + + + +APP1TARGET= $(TARGET) +APP1STACK= 1000000 +APP1OBJS= $(OBJ)$/ut_main.obj + +.IF "$(GUI)"=="WNT" +APP1STDLIBS= $(LIBSTLPORT) +.ELSE +.IF "$(OS)"=="MACOSX" +APP1STDLIBS= $(LIBSTLPORT) +.ENDIF +.ENDIF + + +APP1LIBS= $(LB)$/$(TARGET).lib $(LB)$/cosv.lib + + +APP1DEPN= $(LB)$/$(TARGET).lib $(LB)$/cosv.lib + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + + diff --git a/cosv/source/unittest/string_ut.cxx b/cosv/source/unittest/string_ut.cxx new file mode 100644 index 000000000000..690950d8ee97 --- /dev/null +++ b/cosv/source/unittest/string_ut.cxx @@ -0,0 +1,140 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/string.hxx> + +// NOT FULLY DECLARED SERVICES +#include <ut.hxx> + +using csv::SimpleString; + + +/** @file + UnitTests for class String. +*/ + +inline bool +check_value( const String & a, const char * b ) +{ + return strcmp( a.c_str(), b ) == 0; +} + + +bool +classtest_String( csv::SimpleString & rSimpleString ) +{ + bool ret = true; + + String x1; + UT_CHECK( String(), check_value(x1,"") ) + + const char * s2a = ""; + String x2a(s2a); + UT_CHECK( String(const char*), check_value(x2a,s2a) ) + + const char * s2b = "_zluoadninger prrg chiäßi(/%$##@\\\"'''fh kl"; + String x2b(s2b); + UT_CHECK( String(const char*), check_value(x2b,s2b) ) + + + bool ret = ftest_Read( rSimpleString ); + ret = ftest_Write( rSimpleString ) AND ret; + ret = ftest_SeekBack( rSimpleString ) AND ret; + ret = ftest_SeekRelative( rSimpleString ) AND ret; + + rSimpleString.Close(); + + return ret; +} + + + + +#if 0 +FUT_DECL( SimpleString, Ctor_Def ); +FUT_DECL( SimpleString, Seek ); +FUT_DECL( SimpleString, SeekBack ); +FUT_DECL( SimpleString, SeekRelative ); + + + +FUT_DECL( SimpleString, Read ) +{ + bool ret = true; + + rSimpleString.SeekBack(0); + uintt nSourceSize = rSimpleString.Position(); + rSimpleString.Seek(0); + + char * pBuf = new char[nSourceSize+1]; + uintt nCount = rSimpleString.Read(pBuf,nSourceSize); + + UT_CHECK( Read, nCount == nSourceSize ); + + return ret; +} + +FUT_DECL( SimpleString, Write ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( SimpleString, Seek ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( SimpleString, SeekBack ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( SimpleString, SeekRelative ) +{ + bool ret = true; + + + + return ret; +} + +#endif + + diff --git a/cosv/source/unittest/ut.hxx b/cosv/source/unittest/ut.hxx new file mode 100644 index 000000000000..b46d97f12bae --- /dev/null +++ b/cosv/source/unittest/ut.hxx @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef COSV_UNITTEST_UT_HXX +#define COSV_UNITTEST_UT_HXX + + +#define UT_CHECK( fname, cond ) \ + if ( NOT (cond) ) { std::cerr << "ftest_" << #fname << " " << #cond << endl; \ + ret = false; } + +#define CUT_DECL( nsp, cname ) \ + bool classtest_##cname() +#define FUT_DECL( cname, fname ) \ + bool ftest_##fname( cname & r##cname ) + +#define UT_RESULT( result ) \ + if (result ) std::cout << "All unit tests passed successfully." << std::endl; \ + else std::cout << "Errors in unit tests.\n" << std::endl + + + +CUT_DECL( csv, File ); +CUT_DECL( csv, String ); + +#endif + + + diff --git a/cosv/source/unittest/ut_main.cxx b/cosv/source/unittest/ut_main.cxx new file mode 100644 index 000000000000..750c628f32fb --- /dev/null +++ b/cosv/source/unittest/ut_main.cxx @@ -0,0 +1,47 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> + +#include <cosv/file.hxx> +#include <cosv/simplestring.hxx> +#include "ut.hxx" + + + +int _cdecl +main(int argc, char * argv[]) +{ + bool ret = classtest_File(); + ret = classtest_SimpleString AND ret; + + UT_RESULT( ret ); + + return 0; +} + + diff --git a/cosv/util/makefile.mk b/cosv/util/makefile.mk new file mode 100644 index 000000000000..71788e66f2d1 --- /dev/null +++ b/cosv/util/makefile.mk @@ -0,0 +1,58 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=.. + +PRJNAME=cosv +TARGET=cosv + +ENABLE_EXCEPTIONS=true + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + + +# --- Files -------------------------------------------------------- + +LIB1FILES= \ + $(LB)$/cosv_service.lib \ + $(LB)$/cosv_storage.lib \ + $(LB)$/cosv_strings.lib \ + $(LB)$/cosv_badcast_wnt.lib + + +# --- Targets ------------------------------------------------------ + +LIB1TARGET= $(LB)$/$(TARGET).lib +LIB1ARCHIV= $(LB)$/lib$(TARGET).a + + +.INCLUDE : target.mk + + |