diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2013-04-18 18:26:28 +0200 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2013-04-23 22:20:31 +0200 |
commit | b9337e22ce1dbf2eba0e8c8db294ae99f4111f91 (patch) | |
tree | 53ee1bd3dfd213815a21579151983cb997922b05 /include/cosv | |
parent | f4e1642a1761d5eab6ccdd89928869c2b2f1528a (diff) |
execute move of global headers
see https://gerrit.libreoffice.org/#/c/3367/
and Change-Id: I00c96fa77d04b33a6f8c8cd3490dfcd9bdc9e84a for details
Change-Id: I199a75bc4042af20817265d5ef85b1134a96ff5a
Diffstat (limited to 'include/cosv')
-rw-r--r-- | include/cosv/bstream.hxx | 143 | ||||
-rw-r--r-- | include/cosv/comdline.hxx | 63 | ||||
-rw-r--r-- | include/cosv/comfunc.hxx | 67 | ||||
-rw-r--r-- | include/cosv/csv_env.hxx | 148 | ||||
-rw-r--r-- | include/cosv/csv_ostream.hxx | 127 | ||||
-rw-r--r-- | include/cosv/csv_precomp.h | 40 | ||||
-rw-r--r-- | include/cosv/dirchain.hxx | 146 | ||||
-rw-r--r-- | include/cosv/file.hxx | 114 | ||||
-rw-r--r-- | include/cosv/openclose.hxx | 137 | ||||
-rw-r--r-- | include/cosv/persist.hxx | 98 | ||||
-rw-r--r-- | include/cosv/ploc.hxx | 106 | ||||
-rw-r--r-- | include/cosv/ploc_dir.hxx | 109 | ||||
-rw-r--r-- | include/cosv/plocroot.hxx | 73 | ||||
-rw-r--r-- | include/cosv/std_outp.hxx | 123 | ||||
-rw-r--r-- | include/cosv/str_types.hxx | 85 | ||||
-rw-r--r-- | include/cosv/streamstr.hxx | 310 | ||||
-rw-r--r-- | include/cosv/string.hxx | 501 | ||||
-rw-r--r-- | include/cosv/stringdata.hxx | 128 | ||||
-rw-r--r-- | include/cosv/tpl/dyn.hxx | 232 | ||||
-rw-r--r-- | include/cosv/tpl/processor.hxx | 129 | ||||
-rw-r--r-- | include/cosv/tpl/swelist.hxx | 362 | ||||
-rw-r--r-- | include/cosv/tpl/tpltools.hxx | 154 | ||||
-rw-r--r-- | include/cosv/tpl/vvector.hxx | 535 | ||||
-rw-r--r-- | include/cosv/x.hxx | 64 |
24 files changed, 3994 insertions, 0 deletions
diff --git a/include/cosv/bstream.hxx b/include/cosv/bstream.hxx new file mode 100644 index 000000000000..2d943bc02ce6 --- /dev/null +++ b/include/cosv/bstream.hxx @@ -0,0 +1,143 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/comdline.hxx b/include/cosv/comdline.hxx new file mode 100644 index 000000000000..80ebc763b9d9 --- /dev/null +++ b/include/cosv/comdline.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/comfunc.hxx b/include/cosv/comfunc.hxx new file mode 100644 index 000000000000..a294d81f2aae --- /dev/null +++ b/include/cosv/comfunc.hxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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) + + +// 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; } + +} // namespace csv + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/csv_env.hxx b/include/cosv/csv_env.hxx new file mode 100644 index 000000000000..f49ed54ea464 --- /dev/null +++ b/include/cosv/csv_env.hxx @@ -0,0 +1,148 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/csv_ostream.hxx b/include/cosv/csv_ostream.hxx new file mode 100644 index 000000000000..911fcb8c799e --- /dev/null +++ b/include/cosv/csv_ostream.hxx @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/csv_precomp.h b/include/cosv/csv_precomp.h new file mode 100644 index 000000000000..78f1378cda61 --- /dev/null +++ b/include/cosv/csv_precomp.h @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/dirchain.hxx b/include/cosv/dirchain.hxx new file mode 100644 index 000000000000..980937212690 --- /dev/null +++ b/include/cosv/dirchain.hxx @@ -0,0 +1,146 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 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 PushBack( + const String & i_sName ); + void PushBack( + const DirectoryChain & + i_sPath ); + 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( + 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::bostream & +operator<<( csv::bostream & o_rOut, + const csv::ploc::DirectoryChain & i_rSubPath ) +{ + i_rSubPath.Get(o_rOut, csv::ploc::Delimiter()); + return o_rOut; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/file.hxx b/include/cosv/file.hxx new file mode 100644 index 000000000000..86c880e73184 --- /dev/null +++ b/include/cosv/file.hxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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> + + +namespace csv +{ + + +/** @task + File is a class representing a file. +*/ +class File : public bstream, + public OpenClose, + public ploc::Persistent +{ + public: + // LIFECYCLE + File( + const char * i_sLocation, + uintt in_nMode = CFM_RW ); + File( + const String & i_sLocation, + uintt in_nMode = CFM_RW ); + virtual ~File(); + + // 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 + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/openclose.hxx b/include/cosv/openclose.hxx new file mode 100644 index 000000000000..c65ce5b753e2 --- /dev/null +++ b/include/cosv/openclose.hxx @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/persist.hxx b/include/cosv/persist.hxx new file mode 100644 index 000000000000..13ac4b5dab68 --- /dev/null +++ b/include/cosv/persist.hxx @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 paths 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 + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/ploc.hxx b/include/cosv/ploc.hxx new file mode 100644 index 000000000000..81f952de5223 --- /dev/null +++ b/include/cosv/ploc.hxx @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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; } + 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( + 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::bostream & +operator<<( csv::bostream & o_rOut, + const csv::ploc::Path & i_rPath ) +{ + i_rPath.Get(o_rOut); + return o_rOut; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/ploc_dir.hxx b/include/cosv/ploc_dir.hxx new file mode 100644 index 000000000000..e6c8f04538f2 --- /dev/null +++ b/include/cosv/ploc_dir.hxx @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 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 + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/plocroot.hxx b/include/cosv/plocroot.hxx new file mode 100644 index 000000000000..b079f04b1b9f --- /dev/null +++ b/include/cosv/plocroot.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/std_outp.hxx b/include/cosv/std_outp.hxx new file mode 100644 index 000000000000..08fe179e16ab --- /dev/null +++ b/include/cosv/std_outp.hxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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() {} + + 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: + // 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&); + +void Endl( ostream& ); + +void Flush( ostream& ); + + +} // 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 ); +#else + csv_assert( csv::redirect_out::useme_() ); + (*i_fFlushingFunc)( io_rStream, true, 0 ); +#endif + return io_rStream; +} + + +#endif + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/str_types.hxx b/include/cosv/str_types.hxx new file mode 100644 index 000000000000..ecf9c997c271 --- /dev/null +++ b/include/cosv/str_types.hxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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; + + static const position npos = -1; + static const size maxsize = -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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/streamstr.hxx b/include/cosv/streamstr.hxx new file mode 100644 index 000000000000..ec13f8ec63c6 --- /dev/null +++ b/include/cosv/streamstr.hxx @@ -0,0 +1,310 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef CSV_STREAMSTR_HXX +#define CSV_STREAMSTR_HXX + +#include "sal/config.h" + +#include "sal/types.h" + +// 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 ); + /// 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(); + + /** 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 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_whitespace(); /// removes space, tab and crlf. + void strip_back_whitespace(); + void strip_frontback_whitespace(); + + void replace_all( + char i_cCarToSearch, + char i_cReplacement ); + + // 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; + + // 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; +}; + +// IMPLEMENTATION + +inline const char * +StreamStr::operator<<( SAL_UNUSED_PARAMETER 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; } + +} // namespace csv +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/string.hxx b/include/cosv/string.hxx new file mode 100644 index 000000000000..756aa9a1492c --- /dev/null +++ b/include/cosv/string.hxx @@ -0,0 +1,501 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef COSV_STRING_HXX +#define COSV_STRING_HXX + +// USED SERVICES +#include <string.h> +#include <cosv/stringdata.hxx> +#include <cosv/str_types.hxx> +#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_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(); + + /// @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 ); + + // 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; + +//*********** 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 ); +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 ); +} // 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/stringdata.hxx b/include/cosv/stringdata.hxx new file mode 100644 index 000000000000..0187cb4265a9 --- /dev/null +++ b/include/cosv/stringdata.hxx @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/tpl/dyn.hxx b/include/cosv/tpl/dyn.hxx new file mode 100644 index 000000000000..46095c6c3b7c --- /dev/null +++ b/include/cosv/tpl/dyn.hxx @@ -0,0 +1,232 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 explicitly - 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/tpl/processor.hxx b/include/cosv/tpl/processor.hxx new file mode 100644 index 000000000000..a685acd5bed6 --- /dev/null +++ b/include/cosv/tpl/processor.hxx @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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; +}; + + +/** 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); +} + +} // namespace csv +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/tpl/swelist.hxx b/include/cosv/tpl/swelist.hxx new file mode 100644 index 000000000000..5c64efc29cc2 --- /dev/null +++ b/include/cosv/tpl/swelist.hxx @@ -0,0 +1,362 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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; +}; + +// IMPLEMENTATION + +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 + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/tpl/tpltools.hxx b/include/cosv/tpl/tpltools.hxx new file mode 100644 index 000000000000..487a74cf8237 --- /dev/null +++ b/include/cosv/tpl/tpltools.hxx @@ -0,0 +1,154 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 other containers than std::map, with non-pair value_type. +template <class COLLECTION> +void erase_container_of_heap_ptrs( + COLLECTION & o_rCollection ); + + +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 convertible 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 ); + + + + +// 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_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 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(); +} + + + + +} // namespace csv +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/tpl/vvector.hxx b/include/cosv/tpl/vvector.hxx new file mode 100644 index 000000000000..dec58642bf23 --- /dev/null +++ b/include/cosv/tpl/vvector.hxx @@ -0,0 +1,535 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef CSV_VVECTOR_HXX +#define CSV_VVECTOR_HXX + +#include <cstddef> // for ptrdiff_t + +// 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* > &) + {} + + 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 std::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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cosv/x.hxx b/include/cosv/x.hxx new file mode 100644 index 000000000000..755436317a39 --- /dev/null +++ b/include/cosv/x.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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 + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |