<commit_before>/*************************************************************************
 *
 *  $RCSfile: mscodec.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: obo $ $Date: 2004-08-11 08:54:04 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef SVX_MSCODEC_HXX
#define SVX_MSCODEC_HXX

#ifndef _RTL_CIPHER_H_
#include "rtl/cipher.h"
#endif
#ifndef _RTL_DIGEST_H_
#include "rtl/digest.h"
#endif

namespace svx {

// ============================================================================

/** Encodes and decodes data from protected MSO 95- documents.
 */
class MSCodec_Xor95
{
public:
    explicit            MSCodec_Xor95(int nRotateDistance);
    virtual            ~MSCodec_Xor95();

    /** Initializes the algorithm with the specified password.

        @param pPassData
            Character array containing the password. Must be zero terminated,
            which results in a maximum length of 15 characters.
     */
    void                InitKey( const sal_uInt8 pnPassData[ 16 ] );

    /** Verifies the validity of the password using the passed key and hash.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param nKey
            Password key value read from the file.
        @param nHash
            Password hash value read from the file.

        @return
            true = Test was successful.
     */
    bool                VerifyKey( sal_uInt16 nKey, sal_uInt16 nHash ) const;

    /** Reinitializes the codec to start a new memory block.

        Resets the internal key offset to 0.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.
     */
    void                InitCipher();

    /** Decodes a block of memory inplace.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param pnData
            Encrypted data block. Will contain the decrypted data afterwards.
        @param nBytes
            Size of the passed data block.
    */
    virtual void                Decode( sal_uInt8* pnData, sal_Size nBytes )=0;

    /** Lets the cipher skip a specific amount of bytes.

        This function sets the cipher to the same state as if the specified
        amount of data has been decoded with one or more calls of Decode().

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param nBytes
            Number of bytes to be skipped (cipher "seeks" forward).
     */
    void                Skip( sal_Size nBytes );

    // static -----------------------------------------------------------------

    /** Calculates the 16-bit hash value for the given password.

        The password data may be longer than 16 bytes. The array does not need
        to be terminated with a NULL byte (but it can without invalidating the
        result).
     */
    static sal_uInt16   GetHash( const sal_uInt8* pnPassData, sal_Size nSize );

protected:
    sal_uInt8           mpnKey[ 16 ];   /// Encryption key.
    sal_Size            mnOffset;       /// Key offset.

private:
                        MSCodec_Xor95( const MSCodec_Xor95& );
    MSCodec_Xor95&      operator=( const MSCodec_Xor95& );

    sal_uInt16          mnKey;          /// Base key from password.
    sal_uInt16          mnHash;         /// Hash value from password.
    int         mnRotateDistance;
};

/** Encodes and decodes data from protected MSO XLS 95- documents.
 */
class MSCodec_XorXLS95 : public MSCodec_Xor95
{
public:
    explicit            MSCodec_XorXLS95() : MSCodec_Xor95(2) {}

    /** Decodes a block of memory inplace.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param pnData
            Encrypted data block. Will contain the decrypted data afterwards.
        @param nBytes
            Size of the passed data block.
    */
    virtual void                Decode( sal_uInt8* pnData, sal_Size nBytes );
};

/** Encodes and decodes data from protected MSO Word 95- documents.
 */
class MSCodec_XorWord95 : public MSCodec_Xor95
{
public:
    explicit            MSCodec_XorWord95() : MSCodec_Xor95(7) {}

    /** Decodes a block of memory inplace.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param pnData
            Encrypted data block. Will contain the decrypted data afterwards.
        @param nBytes
            Size of the passed data block.
    */
    virtual void                Decode( sal_uInt8* pnData, sal_Size nBytes );
};

// ============================================================================

/** Encodes and decodes data from protected MSO 97+ documents.

    This is a wrapper class around low level cryptographic functions from RTL.
    Implementation is based on the wvDecrypt package by Caolan McNamara:
    http://www.csn.ul.ie/~caolan/docs/wvDecrypt.html
 */
class MSCodec_Std97
{
public:
    explicit            MSCodec_Std97();
                        ~MSCodec_Std97();

    /** Initializes the algorithm with the specified password and document ID.

        @param pPassData
            Wide character array containing the password. Must be zero
            terminated, which results in a maximum length of 15 characters.
        @param pUnique
            Unique document identifier read from or written to the file.
     */
    void                InitKey(
                            const sal_uInt16 pPassData[ 16 ],
                            const sal_uInt8 pUnique[ 16 ] );

    /** Verifies the validity of the password using the passed salt data.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param pSaltData
            Salt data block read from the file.
        @param pSaltDigest
            Salt digest read from the file.

        @return
            true = Test was successful.
     */
    bool                VerifyKey(
                            const sal_uInt8 pSaltData[ 16 ],
                            const sal_uInt8 pSaltDigest[ 16 ] );

    /** Rekeys the codec using the specified counter.

        After reading a specific amount of data the cipher algorithm needs to
        be rekeyed using a counter that counts the data blocks.

        The block size is for example 512 Bytes for Word files and 1024 Bytes
        for Excel files.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param nCounter
            Block counter used to rekey the cipher.
     */
    bool                InitCipher( sal_uInt32 nCounter );

    /** Decodes a block of memory.

        @see rtl_cipher_decode()

        @precond
            The codec must be initialized with InitKey() before this function
            can be used. The destination buffer must be able to take all
            encoded data from the source buffer (usually this means it must be
            as long as or longer than the source buffer).

        @param pData
            Encrypted source data block.
        @param nDatLen
            Size of the passed source data block.
        @param pBuffer
            Destination buffer for the decrypted data.
        @param nBufLen
            Size of the destination buffer.

        @return
            true = Decoding was successful (no error occured).
    */
    bool                Decode(
                            const void* pData, sal_Size nDatLen,
                            sal_uInt8* pBuffer, sal_Size nBufLen );

    /** Lets the cipher skip a specific amount of bytes.

        This function sets the cipher to the same state as if the specified
        amount of data has been decoded with one or more calls of Decode().

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param nDatLen
            Number of bytes to be skipped (cipher "seeks" forward).
     */
    bool                Skip( sal_Size nDatLen );

private:
                        MSCodec_Std97( const MSCodec_Std97& );
    MSCodec_Std97&      operator=( const MSCodec_Std97& );

    rtlCipher           m_hCipher;
    rtlDigest           m_hDigest;
    sal_uInt8           m_pDigestValue[ RTL_DIGEST_LENGTH_MD5 ];
};

// ============================================================================

} // namespace svx

#endif

<commit_msg>INTEGRATION: CWS visibility01 (1.2.118); FILE MERGED 2004/11/19 12:54:19 mmeeks 1.2.118.1: Issue number: #i35758# Submitted by: mnicel Reviewed by:  mmeeks<commit_after>/*************************************************************************
 *
 *  $RCSfile: mscodec.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: kz $ $Date: 2005-01-21 14:57:00 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef SVX_MSCODEC_HXX
#define SVX_MSCODEC_HXX

#ifndef _RTL_CIPHER_H_
#include "rtl/cipher.h"
#endif
#ifndef _RTL_DIGEST_H_
#include "rtl/digest.h"
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

namespace svx {

// ============================================================================

/** Encodes and decodes data from protected MSO 95- documents.
 */
class SVX_DLLPUBLIC MSCodec_Xor95
{
public:
    explicit            MSCodec_Xor95(int nRotateDistance);
    virtual            ~MSCodec_Xor95();

    /** Initializes the algorithm with the specified password.

        @param pPassData
            Character array containing the password. Must be zero terminated,
            which results in a maximum length of 15 characters.
     */
    void                InitKey( const sal_uInt8 pnPassData[ 16 ] );

    /** Verifies the validity of the password using the passed key and hash.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param nKey
            Password key value read from the file.
        @param nHash
            Password hash value read from the file.

        @return
            true = Test was successful.
     */
    bool                VerifyKey( sal_uInt16 nKey, sal_uInt16 nHash ) const;

    /** Reinitializes the codec to start a new memory block.

        Resets the internal key offset to 0.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.
     */
    void                InitCipher();

    /** Decodes a block of memory inplace.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param pnData
            Encrypted data block. Will contain the decrypted data afterwards.
        @param nBytes
            Size of the passed data block.
    */
    virtual void                Decode( sal_uInt8* pnData, sal_Size nBytes )=0;

    /** Lets the cipher skip a specific amount of bytes.

        This function sets the cipher to the same state as if the specified
        amount of data has been decoded with one or more calls of Decode().

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param nBytes
            Number of bytes to be skipped (cipher "seeks" forward).
     */
    void                Skip( sal_Size nBytes );

    // static -----------------------------------------------------------------

    /** Calculates the 16-bit hash value for the given password.

        The password data may be longer than 16 bytes. The array does not need
        to be terminated with a NULL byte (but it can without invalidating the
        result).
     */
    static sal_uInt16   GetHash( const sal_uInt8* pnPassData, sal_Size nSize );

protected:
    sal_uInt8           mpnKey[ 16 ];   /// Encryption key.
    sal_Size            mnOffset;       /// Key offset.

private:
                        SVX_DLLPRIVATE MSCodec_Xor95( const MSCodec_Xor95& );
    SVX_DLLPRIVATE MSCodec_Xor95&      operator=( const MSCodec_Xor95& );

    sal_uInt16          mnKey;          /// Base key from password.
    sal_uInt16          mnHash;         /// Hash value from password.
    int         mnRotateDistance;
};

/** Encodes and decodes data from protected MSO XLS 95- documents.
 */
class SVX_DLLPUBLIC MSCodec_XorXLS95 : public MSCodec_Xor95
{
public:
    explicit            MSCodec_XorXLS95() : MSCodec_Xor95(2) {}

    /** Decodes a block of memory inplace.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param pnData
            Encrypted data block. Will contain the decrypted data afterwards.
        @param nBytes
            Size of the passed data block.
    */
    virtual void                Decode( sal_uInt8* pnData, sal_Size nBytes );
};

/** Encodes and decodes data from protected MSO Word 95- documents.
 */
class SVX_DLLPUBLIC MSCodec_XorWord95 : public MSCodec_Xor95
{
public:
    explicit            MSCodec_XorWord95() : MSCodec_Xor95(7) {}

    /** Decodes a block of memory inplace.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param pnData
            Encrypted data block. Will contain the decrypted data afterwards.
        @param nBytes
            Size of the passed data block.
    */
    virtual void                Decode( sal_uInt8* pnData, sal_Size nBytes );
};

// ============================================================================

/** Encodes and decodes data from protected MSO 97+ documents.

    This is a wrapper class around low level cryptographic functions from RTL.
    Implementation is based on the wvDecrypt package by Caolan McNamara:
    http://www.csn.ul.ie/~caolan/docs/wvDecrypt.html
 */
class SVX_DLLPUBLIC MSCodec_Std97
{
public:
    explicit            MSCodec_Std97();
                        ~MSCodec_Std97();

    /** Initializes the algorithm with the specified password and document ID.

        @param pPassData
            Wide character array containing the password. Must be zero
            terminated, which results in a maximum length of 15 characters.
        @param pUnique
            Unique document identifier read from or written to the file.
     */
    void                InitKey(
                            const sal_uInt16 pPassData[ 16 ],
                            const sal_uInt8 pUnique[ 16 ] );

    /** Verifies the validity of the password using the passed salt data.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param pSaltData
            Salt data block read from the file.
        @param pSaltDigest
            Salt digest read from the file.

        @return
            true = Test was successful.
     */
    bool                VerifyKey(
                            const sal_uInt8 pSaltData[ 16 ],
                            const sal_uInt8 pSaltDigest[ 16 ] );

    /** Rekeys the codec using the specified counter.

        After reading a specific amount of data the cipher algorithm needs to
        be rekeyed using a counter that counts the data blocks.

        The block size is for example 512 Bytes for Word files and 1024 Bytes
        for Excel files.

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param nCounter
            Block counter used to rekey the cipher.
     */
    bool                InitCipher( sal_uInt32 nCounter );

    /** Decodes a block of memory.

        @see rtl_cipher_decode()

        @precond
            The codec must be initialized with InitKey() before this function
            can be used. The destination buffer must be able to take all
            encoded data from the source buffer (usually this means it must be
            as long as or longer than the source buffer).

        @param pData
            Encrypted source data block.
        @param nDatLen
            Size of the passed source data block.
        @param pBuffer
            Destination buffer for the decrypted data.
        @param nBufLen
            Size of the destination buffer.

        @return
            true = Decoding was successful (no error occured).
    */
    bool                Decode(
                            const void* pData, sal_Size nDatLen,
                            sal_uInt8* pBuffer, sal_Size nBufLen );

    /** Lets the cipher skip a specific amount of bytes.

        This function sets the cipher to the same state as if the specified
        amount of data has been decoded with one or more calls of Decode().

        @precond
            The codec must be initialized with InitKey() before this function
            can be used.

        @param nDatLen
            Number of bytes to be skipped (cipher "seeks" forward).
     */
    bool                Skip( sal_Size nDatLen );

private:
                        SVX_DLLPRIVATE MSCodec_Std97( const MSCodec_Std97& );
    SVX_DLLPRIVATE MSCodec_Std97&      operator=( const MSCodec_Std97& );

    rtlCipher           m_hCipher;
    rtlDigest           m_hDigest;
    sal_uInt8           m_pDigestValue[ RTL_DIGEST_LENGTH_MD5 ];
};

// ============================================================================

} // namespace svx

#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: dbgoutsw.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: hr $ $Date: 2004-09-08 14:49:14 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef __DBGOUTSW_HXX
#define __DBGOUTSW_HXX

#ifdef DEBUG

class String;
class SwNode;
class SwTxtAttr;
class SwpHints;
class SfxPoolItem;
class SfxItemSet;
struct SwPosition;
class SwPaM;
class SwNodeNum;
class SwUndos;
class SwRect;
class SwFrmFmt;
class SwNodes;
class SwRewriter;

#define DBG_OUT_HERE printf("%s(%d):", __FILE__, __LINE__)
#define DBG_OUT_HERE_FN printf("%s(%d) %s:", __FILE__, __LINE__, __FUNCTION__)
#define DBG_OUT_HERE_LN printf("%s(%d)\n", __FILE__, __LINE__)
#define DBG_OUT_HERE_FN_LN printf("%s(%d) %s\n", __FILE__, __LINE__, __FUNCTION__)
#define DBG_OUT(x) printf("%s\n", dbg_out(x))
#define DBG_OUT_LN(x) printf("%s(%d): %s\n", __FILE__, __LINE__, dbg_out(x))
#define DBG_OUT_FN_LN(x) printf("%s: %s\n", __FUNCTION__, dbg_out(x))

extern bool bDbgOutStdErr;
extern bool bDbgOutPrintAttrSet;

const char * dbg_out(const void * pVoid);
const char * dbg_out(const String & aStr);
const char * dbg_out(const SwRect & rRect);
const char * dbg_out(const SwFrmFmt & rFrmFmt);
const char * dbg_out(const SwNode & rNode);
const char * dbg_out(const SwTxtAttr & rAttr);
const char * dbg_out(const SwpHints &rHints);
const char * dbg_out(const SfxPoolItem & rItem);
const char * dbg_out(const SfxItemSet & rSet);
const char * dbg_out(SwNodes & rNodes);
const char * dbg_out(const SwPosition & rPos);
const char * dbg_out(const SwPaM & rPam);
const char * dbg_out(const SwNodeNum & rNum);
const char * dbg_out(const SwUndos & rUndos);
const char * dbg_out(const SwRewriter & rRewriter);

#endif // DEBUG
#endif // __DBGOUTSW_HXX
<commit_msg>INTEGRATION: CWS swqbugfixes09 (1.6.36); FILE MERGED 2004/11/10 14:54:46 hbrinkm 1.6.36.2: #i30310#,#118435# output for SwFormToken(s), hash map for name->numrule relation 2004/11/10 14:46:55 hbrinkm 1.6.36.1: #i30310#,#118435# output for SwFormToken(s), hash map for name->numrule relation<commit_after>/*************************************************************************
 *
 *  $RCSfile: dbgoutsw.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: obo $ $Date: 2004-11-16 15:36:54 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef __DBGOUTSW_HXX
#define __DBGOUTSW_HXX

#ifdef DEBUG

#include <hash_map>
#include <tox.hxx>

class String;
class SwNode;
class SwTxtAttr;
class SwpHints;
class SfxPoolItem;
class SfxItemSet;
struct SwPosition;
class SwPaM;
class SwNodeNum;
class SwUndos;
class SwRect;
class SwFrmFmt;
class SwNodes;
class SwRewriter;

#define DBG_OUT_HERE printf("%s(%d):", __FILE__, __LINE__)
#define DBG_OUT_HERE_FN printf("%s(%d) %s:", __FILE__, __LINE__, __FUNCTION__)
#define DBG_OUT_HERE_LN printf("%s(%d)\n", __FILE__, __LINE__)
#define DBG_OUT_HERE_FN_LN printf("%s(%d) %s\n", __FILE__, __LINE__, __FUNCTION__)
#define DBG_OUT(x) printf("%s\n", dbg_out(x))
#define DBG_OUT_LN(x) printf("%s(%d): %s\n", __FILE__, __LINE__, dbg_out(x))
#define DBG_OUT_FN_LN(x) printf("%s: %s\n", __FUNCTION__, dbg_out(x))

extern bool bDbgOutStdErr;
extern bool bDbgOutPrintAttrSet;

const char * dbg_out(const void * pVoid);
const char * dbg_out(const String & aStr);
const char * dbg_out(const SwRect & rRect);
const char * dbg_out(const SwFrmFmt & rFrmFmt);
const char * dbg_out(const SwNode & rNode);
const char * dbg_out(const SwTxtAttr & rAttr);
const char * dbg_out(const SwpHints &rHints);
const char * dbg_out(const SfxPoolItem & rItem);
const char * dbg_out(const SfxItemSet & rSet);
const char * dbg_out(SwNodes & rNodes);
const char * dbg_out(const SwPosition & rPos);
const char * dbg_out(const SwPaM & rPam);
const char * dbg_out(const SwNodeNum & rNum);
const char * dbg_out(const SwUndos & rUndos);
const char * dbg_out(const SwRewriter & rRewriter);
const char * dbg_out(const SwNumRuleTbl & rTbl);
const char * dbg_out(const SwFormToken & rToken);
const char * dbg_out(const SwFormTokens & rTokens);
#endif // DEBUG
#endif // __DBGOUTSW_HXX
<|endoftext|>


<commit_before>#include <fstream>
#include <iostream>
#include "statistical_key_facts.h"
#include "../src/transwarp.h"
#include <random>
#include <numeric>

namespace tw = transwarp;

namespace examples {

using data_const_t = std::shared_ptr<const std::vector<double>>;

data_const_t generate_gamma(std::size_t sample_size, double alpha, double beta, std::shared_ptr<std::mt19937> gen) {
    auto data = std::make_shared<std::vector<double>>(sample_size);
    std::gamma_distribution<double> dist(alpha, beta);
    for (auto& value : *data) {
        value = dist(*gen);
    }
    return data;
}

double average(data_const_t data) {
    return std::accumulate(data->begin(), data->end(), 0.) / static_cast<double>(data->size());
}

double stddev(data_const_t data, double average) {
    double sum = 0;
    std::for_each(data->begin(), data->end(),
                  [average,&sum](double x) { sum += std::pow(x - average, 2.); });
    return std::sqrt(sum / static_cast<double>(data->size()));
}

double median(data_const_t data) {
    auto copy = *data;
    std::sort(copy.begin(), copy.end());
    if(data->size() % 2 == 0)
        return (copy[data->size() / 2 - 1] + copy[data->size() / 2]) / 2;
    else
        return copy[data->size() / 2];
}

int mode(data_const_t data) {
    auto copy = *data;
    std::sort(copy.begin(), copy.end());
    int number = static_cast<int>(*copy.begin());
    int mode = number;
    int count = 1;
    int count_mode = 1;
    std::for_each(copy.begin() + 1, copy.end(),
                  [&number,&mode,&count,&count_mode](double x) {
                        if (static_cast<int>(x) == number) {
                            ++count;
                        } else {
                            if (count > count_mode) {
                                count_mode = count;
                                mode = number;
                            }
                            count = 1;
                            number = static_cast<int>(x);
                        }
                  });
    return mode;
}

struct result {
    double avg;
    double stddev;
    double median;
    int mode;
};

std::ostream& operator<<(std::ostream& os, const result& r) {
    os << "avg=" << r.avg << ", stddev=" << r.stddev << ", median=" << r.median << ", mode=" << r.mode;
    return os;
}

result aggregate_results(double avg, double stddev, double median, int mode) {
    return {avg, stddev, median, mode};
}

std::shared_ptr<tw::itask<result>> build_graph(std::size_t sample_size, double& alpha, double& beta) {
    auto gen = std::make_shared<std::mt19937>(1);
    auto gen_task = tw::make_task(tw::root, "rand gen", [gen] { return gen; });
    auto size_task = tw::make_task(tw::root, "sample size", [sample_size] { return sample_size; });
    auto alpha_task = tw::make_task(tw::root, "alpha", [&alpha] { return alpha; });
    auto beta_task = tw::make_task(tw::root, "beta", [&beta] { return beta; });

    auto data_task = tw::make_task(tw::consume, "generate gamma", generate_gamma,
                                   size_task, alpha_task, beta_task, gen_task);

    auto avg_task = tw::make_task(tw::consume, "average", average, data_task);
    auto stddev_task = tw::make_task(tw::consume, "stddev", stddev, data_task, avg_task);
    auto median_task = tw::make_task(tw::consume, "median", median, data_task);
    auto mode_task = tw::make_task(tw::consume, "mode", mode, data_task);

    return tw::make_task(tw::consume, "aggregate results", aggregate_results,
                         avg_task, stddev_task, median_task, mode_task);
}

// This example computes statistical key measures from numbers sampled
// from a gamma distribution. The example computes average, standard deviation,
// median, and mode for varying values of alpha and beta.
void statistical_key_facts(std::ostream& os, std::size_t sample_size, bool parallel) {
    os.precision(3);

    double alpha = 1;
    double beta = 1;
    result res;

    // building the graph and retrieving the final task
    auto final_task = build_graph(sample_size, alpha, beta);

    // output the graph for visualization
    const auto graph = final_task->get_graph();
    std::ofstream("statistical_key_facts.dot") << tw::make_dot(graph);

    // Creating the executor
    std::shared_ptr<tw::executor> executor;
    if (parallel) {
        executor = std::make_shared<tw::parallel>(4);
    } else {
        executor = std::make_shared<tw::sequential>();
    }

    // Now we start calculating stuff ...

    // First computation with initial values
    final_task->schedule_all(executor.get());
    res = final_task->get_future().get();
    os << res << std::endl;

    final_task->reset_all();

    // Second computation with new input
    alpha = 2;
    beta = 3;
    final_task->schedule_all(executor.get());
    res = final_task->get_future().get();
    os << res << std::endl;

    final_task->reset_all();

    // Third computation with new input
    alpha = 3;
    beta = 4;
    final_task->schedule_all(executor.get());
    res = final_task->get_future().get();
    os << res << std::endl;
}

}

#ifndef USE_LIBUNITTEST
int main() {
    std::cout << "Running example: statistical_key_facts ..." << std::endl;
    examples::statistical_key_facts(std::cout);
}
#endif
<commit_msg>improve example<commit_after>#include <fstream>
#include <iostream>
#include "statistical_key_facts.h"
#include "../src/transwarp.h"
#include <random>
#include <numeric>

namespace tw = transwarp;

namespace examples {

using data_const_t = std::shared_ptr<const std::vector<double>>;

data_const_t generate_gamma(std::size_t sample_size, double alpha, double beta, std::shared_ptr<std::mt19937> gen) {
    auto data = std::make_shared<std::vector<double>>(sample_size);
    std::gamma_distribution<double> dist(alpha, beta);
    for (auto& value : *data) {
        value = dist(*gen);
    }
    return data;
}

double average(data_const_t data) {
    return std::accumulate(data->begin(), data->end(), 0.) / static_cast<double>(data->size());
}

double stddev(data_const_t data, double average) {
    double sum = 0;
    std::for_each(data->begin(), data->end(),
                  [average,&sum](double x) { sum += std::pow(x - average, 2.); });
    return std::sqrt(sum / static_cast<double>(data->size()));
}

double median(data_const_t data) {
    auto copy = *data;
    std::sort(copy.begin(), copy.end());
    if(data->size() % 2 == 0)
        return (copy[data->size() / 2 - 1] + copy[data->size() / 2]) / 2;
    else
        return copy[data->size() / 2];
}

int mode(data_const_t data) {
    auto copy = *data;
    std::sort(copy.begin(), copy.end());
    int number = static_cast<int>(*copy.begin());
    int mode = number;
    int count = 1;
    int count_mode = 1;
    std::for_each(copy.begin() + 1, copy.end(),
                  [&number,&mode,&count,&count_mode](double x) {
                        if (static_cast<int>(x) == number) {
                            ++count;
                        } else {
                            if (count > count_mode) {
                                count_mode = count;
                                mode = number;
                            }
                            count = 1;
                            number = static_cast<int>(x);
                        }
                  });
    return mode;
}

struct result {
    double avg;
    double stddev;
    double median;
    int mode;
};

std::ostream& operator<<(std::ostream& os, const result& r) {
    os << "avg=" << r.avg << ", stddev=" << r.stddev << ", median=" << r.median << ", mode=" << r.mode;
    return os;
}

result aggregate_results(double avg, double stddev, double median, int mode) {
    return {avg, stddev, median, mode};
}

std::shared_ptr<tw::itask<result>> build_graph(std::size_t sample_size, double& alpha, double& beta) {
    auto gen = std::make_shared<std::mt19937>(1);
    auto gen_task = tw::make_task(tw::root, "rand gen", [gen] { return gen; });
    auto size_task = tw::make_task(tw::root, "sample size", [sample_size] { return sample_size; });
    auto alpha_task = tw::make_task(tw::root, "alpha", [&alpha] { return alpha; });
    auto beta_task = tw::make_task(tw::root, "beta", [&beta] { return beta; });

    auto data_task = tw::make_task(tw::consume, "generate gamma", generate_gamma,
                                   size_task, alpha_task, beta_task, gen_task);

    auto avg_task = tw::make_task(tw::consume, "average", average, data_task);
    auto stddev_task = tw::make_task(tw::consume, "stddev", stddev, data_task, avg_task);
    auto median_task = tw::make_task(tw::consume, "median", median, data_task);
    auto mode_task = tw::make_task(tw::consume, "mode", mode, data_task);

    return tw::make_task(tw::consume, "aggregate results", aggregate_results,
                         avg_task, stddev_task, median_task, mode_task);
}

// This example computes statistical key measures from numbers sampled
// from a gamma distribution. The example computes average, standard deviation,
// median, and mode for varying values of alpha and beta.
void statistical_key_facts(std::ostream& os, std::size_t sample_size, bool parallel) {
    os.precision(3);

    double alpha = 1;
    double beta = 1;

    // Building the graph and retrieving the final task
    auto final_task = build_graph(sample_size, alpha, beta);

    // Output the graph for visualization
    const auto graph = final_task->get_graph();
    std::ofstream("statistical_key_facts.dot") << tw::make_dot(graph);

    // Creating the executor
    std::shared_ptr<tw::executor> executor;
    if (parallel) {
        executor = std::make_shared<tw::parallel>(4);
    } else {
        executor = std::make_shared<tw::sequential>();
    }

    // Now we start calculating stuff ...
    double count = 1;
    while (count < 4) {
        final_task->schedule_all(executor.get());
        const result res = final_task->get_future().get();
        os << res << std::endl;
        final_task->reset_all();
        // Changing input
        alpha += count;
        beta += count;
        ++count;
    }

}

}

#ifndef USE_LIBUNITTEST
int main() {
    std::cout << "Running example: statistical_key_facts ..." << std::endl;
    examples::statistical_key_facts(std::cout);
}
#endif
<|endoftext|>


<commit_before><commit_msg>treat OOB as errors<commit_after><|endoftext|>


<commit_before>#include "Dictionary.h"
#include "Errors.h"

#include <list>

#include <iostream>
#include <limits>
#include <utility>

using namespace std;

// Static initialization
std::mutex Dictionary::mut_dicts;
Dictionary::DictionaryMap Dictionary::dicts;

// Constructor
Dictionary :: Dictionary( void ) :
    indexMap(),
    reverseMap(),
    orderMap(),
    nextID(0),
    modified(false),
    orderValid(false)
{ }

Dictionary :: Dictionary( const std::string name ) :
    indexMap(), reverseMap(), orderMap(),
    nextID(0), modified(false), orderValid(false)
{
    Load(name.c_str());
}

// Destructor
Dictionary :: ~Dictionary( void ) {
}

const char * Dictionary :: Dereference( IntType id ) const {
    IndexMap::const_iterator it = indexMap.find( id );
    if( it != indexMap.end() )
        return it->second.c_str();
    else {
      return "NULL";
    }
}

Dictionary::IntType Dictionary :: Lookup( const StringType& s, const IntType invalid ) const {
    ReverseMap::const_iterator it = reverseMap.find( s );
    if( it != reverseMap.end() )
        return it->second;
    else
        return invalid;
}

Dictionary::IntType Dictionary :: Lookup( const char * str, const IntType invalid ) const {
    StringType s(str);
    return Lookup( s, invalid );
}

Dictionary::IntType Dictionary :: Insert( StringType& s ) {
    modified = true;
    orderValid = false;

    indexMap[nextID] = s;
    reverseMap[s] = nextID;

    return nextID++;
}

Dictionary::IntType Dictionary :: Insert( const char * str, const IntType maxID ) {
    FATALIF( nextID > maxID, "Error: Unable to add new value [%s] to dictionary."
        " Next ID %u greater than specified maximum ID %u.", str, nextID, maxID );

    StringType s(str);
    return Insert( s );
}

void Dictionary :: Integrate( Dictionary& other, TranslationTable& trans ) {
    for( auto el : other.indexMap ) {
        IntType id = el.first;

        StringType str = el.second;
        auto revit = reverseMap.find(str);
        if( revit == reverseMap.end() ) {
            // This string isn't in my map.
            IntType myID = Insert( str );
            trans[id] = myID;
        } else {
            IntType myID = revit->second;
            if( myID != id ) {
                // The string is in my dictionary, but the IDs are different.
                trans[id] = myID;
            }
        }

        // Otherwise, both IDs are the same and we need no insertions or
        // translations
    }

    // Recompute sorted order
    ComputeOrder();
}

void Dictionary :: ComputeOrder( void ) {
    if( !orderValid ) {
        list<StringType> sortList;
        for( ReverseMap::const_iterator it = reverseMap.begin(); it != reverseMap.end(); ++it ) {
            const StringType& str = it->first;
            sortList.push_back(str);
        }

        sortList.sort();

        IntType curIndex = sortList.size() - 1;
        for( list<StringType>::const_reverse_iterator it = sortList.rbegin(); it != sortList.rend(); ++it ) {
            const StringType& str = *it;
            IntType ID = reverseMap[str];

            orderMap[ID] = curIndex--;
        }

        orderValid = true;
    }
}

Dictionary::DiffType Dictionary::Compare( IntType firstID, IntType secondID ) const {
    return orderMap.at(firstID) - orderMap.at(secondID);
}

Dictionary::const_iterator Dictionary::cbegin( void ) const {
    return indexMap.cbegin();
}

Dictionary::const_iterator Dictionary::cend( void ) const {
    return indexMap.cend();
}

Dictionary::const_iterator Dictionary::begin( void ) const {
    return indexMap.cbegin();
}

Dictionary::const_iterator Dictionary::end( void ) const {
    return indexMap.cend();
}

Dictionary & Dictionary :: GetDictionary( const std::string name ) {
    std::lock_guard guard{mut_dicts};
    if( dicts.find(name) == dicts.end() ) {
        dicts.insert( make_pair(name, Dictionary(name)) );
    }

    return dicts[name];
}
<commit_msg>lock_guard needs a template arg.<commit_after>#include "Dictionary.h"
#include "Errors.h"

#include <list>

#include <iostream>
#include <limits>
#include <utility>

using namespace std;

// Static initialization
std::mutex Dictionary::mut_dicts;
Dictionary::DictionaryMap Dictionary::dicts;

// Constructor
Dictionary :: Dictionary( void ) :
    indexMap(),
    reverseMap(),
    orderMap(),
    nextID(0),
    modified(false),
    orderValid(false)
{ }

Dictionary :: Dictionary( const std::string name ) :
    indexMap(), reverseMap(), orderMap(),
    nextID(0), modified(false), orderValid(false)
{
    Load(name.c_str());
}

// Destructor
Dictionary :: ~Dictionary( void ) {
}

const char * Dictionary :: Dereference( IntType id ) const {
    IndexMap::const_iterator it = indexMap.find( id );
    if( it != indexMap.end() )
        return it->second.c_str();
    else {
      return "NULL";
    }
}

Dictionary::IntType Dictionary :: Lookup( const StringType& s, const IntType invalid ) const {
    ReverseMap::const_iterator it = reverseMap.find( s );
    if( it != reverseMap.end() )
        return it->second;
    else
        return invalid;
}

Dictionary::IntType Dictionary :: Lookup( const char * str, const IntType invalid ) const {
    StringType s(str);
    return Lookup( s, invalid );
}

Dictionary::IntType Dictionary :: Insert( StringType& s ) {
    modified = true;
    orderValid = false;

    indexMap[nextID] = s;
    reverseMap[s] = nextID;

    return nextID++;
}

Dictionary::IntType Dictionary :: Insert( const char * str, const IntType maxID ) {
    FATALIF( nextID > maxID, "Error: Unable to add new value [%s] to dictionary."
        " Next ID %u greater than specified maximum ID %u.", str, nextID, maxID );

    StringType s(str);
    return Insert( s );
}

void Dictionary :: Integrate( Dictionary& other, TranslationTable& trans ) {
    for( auto el : other.indexMap ) {
        IntType id = el.first;

        StringType str = el.second;
        auto revit = reverseMap.find(str);
        if( revit == reverseMap.end() ) {
            // This string isn't in my map.
            IntType myID = Insert( str );
            trans[id] = myID;
        } else {
            IntType myID = revit->second;
            if( myID != id ) {
                // The string is in my dictionary, but the IDs are different.
                trans[id] = myID;
            }
        }

        // Otherwise, both IDs are the same and we need no insertions or
        // translations
    }

    // Recompute sorted order
    ComputeOrder();
}

void Dictionary :: ComputeOrder( void ) {
    if( !orderValid ) {
        list<StringType> sortList;
        for( ReverseMap::const_iterator it = reverseMap.begin(); it != reverseMap.end(); ++it ) {
            const StringType& str = it->first;
            sortList.push_back(str);
        }

        sortList.sort();

        IntType curIndex = sortList.size() - 1;
        for( list<StringType>::const_reverse_iterator it = sortList.rbegin(); it != sortList.rend(); ++it ) {
            const StringType& str = *it;
            IntType ID = reverseMap[str];

            orderMap[ID] = curIndex--;
        }

        orderValid = true;
    }
}

Dictionary::DiffType Dictionary::Compare( IntType firstID, IntType secondID ) const {
    return orderMap.at(firstID) - orderMap.at(secondID);
}

Dictionary::const_iterator Dictionary::cbegin( void ) const {
    return indexMap.cbegin();
}

Dictionary::const_iterator Dictionary::cend( void ) const {
    return indexMap.cend();
}

Dictionary::const_iterator Dictionary::begin( void ) const {
    return indexMap.cbegin();
}

Dictionary::const_iterator Dictionary::end( void ) const {
    return indexMap.cend();
}

Dictionary & Dictionary :: GetDictionary( const std::string name ) {
    std::lock_guard<std::mutex> guard{mut_dicts};
    if( dicts.find(name) == dicts.end() ) {
        dicts.insert( make_pair(name, Dictionary(name)) );
    }

    return dicts[name];
}
<|endoftext|>


<commit_before>#include <coffee/core/CUnitTesting>
#include <coffee/core/CFiles>

using namespace Coffee;

const cstring small_map_test = "file_map_small.bin";

byte_t sample_storage[Unit_kB*100] = {
    "I'M THE TRASHMAN!\n"
};

bool filewrite_test()
{
    CResources::Resource rsc(small_map_test);
    rsc.data = sample_storage;
    rsc.size = sizeof(sample_storage);
    return CResources::FileCommit(rsc);
}

bool filemap_test()
{
    CResources::Resource rsc(small_map_test);
    CResources::FileMap(rsc);
    bool status = MemCmp(sample_storage,rsc.data,sizeof(sample_storage));
    CResources::FileUnmap(rsc);
    return status;
}

const cstring big_map_test = "file_map_large.bin";

void* large_data = nullptr;

bool filewrite_large_test()
{
    CResources::Resource rsc(big_map_test);
    rsc.size = Unit_GB*5;
    rsc.data = Alloc(rsc.size);
    large_data = rsc.data;
    byte_t* data = (byte_t*)large_data;
    cstring test_string = "I'M THE TRASHMAN!\n";
    MemCpy(data,test_string,StrLen(test_string));
    bool stat = CResources::FileCommit(rsc);
    return stat;
}

bool filemap_large_test()
{
    CResources::Resource rsc(big_map_test);
    CResources::FileMap(rsc);
    bool stat = MemCmp(large_data,rsc.data,rsc.size);
    CFree(large_data);
    CResources::FileUnmap(rsc);
    return stat;
}

const constexpr CoffeeTest::Test _tests[4] = {
    {filewrite_test,"File writing","Really just prepares for the next test"},
    {filemap_test,"File mapping"},
    {filewrite_large_test,"Large file writing","Allocates 5GB of data and writes it to disk",true},
    {filemap_large_test,"Large file mapping","Mapping a large file into memory",true}
};

COFFEE_RUN_TESTS(_tests);<commit_msg> - Add more explicit file handling in file mapping test, required for Windows<commit_after>#include <coffee/core/CUnitTesting>
#include <coffee/core/CFiles>

using namespace Coffee;

const cstring small_map_test = "file_map_small.bin";

byte_t sample_storage[Unit_kB*100] = {
    "I'M THE TRASHMAN!\n"
};

bool filewrite_test()
{
    CResources::Resource rsc(small_map_test);
    rsc.data = sample_storage;
    rsc.size = sizeof(sample_storage);
    return CResources::FileCommit(rsc,false,ResourceAccess::WriteOnly|ResourceAccess::Discard);
}

bool filemap_test()
{
    CResources::Resource rsc(small_map_test);
    CResources::FileMap(rsc);
    bool status = MemCmp(sample_storage,rsc.data,sizeof(sample_storage));
    CResources::FileUnmap(rsc);
    return status;
}

const cstring big_map_test = "file_map_large.bin";

void* large_data = nullptr;

bool filewrite_large_test()
{
    CResources::Resource rsc(big_map_test);
    rsc.size = Unit_GB*5;
    rsc.data = Alloc(rsc.size);
    large_data = rsc.data;
    byte_t* data = (byte_t*)large_data;
    cstring test_string = "I'M THE TRASHMAN!\n";
    MemCpy(data,test_string,StrLen(test_string));
    bool stat = CResources::FileCommit(rsc,false, ResourceAccess::WriteOnly | ResourceAccess::Discard);
    return stat;
}

bool filemap_large_test()
{
    CResources::Resource rsc(big_map_test);
    CResources::FileMap(rsc);
    bool stat = MemCmp(large_data,rsc.data,rsc.size);
    CFree(large_data);
    CResources::FileUnmap(rsc);
    return stat;
}

const constexpr CoffeeTest::Test _tests[4] = {
    {filewrite_test,"File writing","Really just prepares for the next test"},
    {filemap_test,"File mapping"},
    {filewrite_large_test,"Large file writing","Allocates 5GB of data and writes it to disk",true},
    {filemap_large_test,"Large file mapping","Mapping a large file into memory",true}
};

COFFEE_RUN_TESTS(_tests);<|endoftext|>


<commit_before>/**
 * Copyright (C)  2006  Brad Hards <bradh@frogmouth.net>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <QtCrypto>
#include <QtNetwork>
#include <QtTest/QtTest>

class TlsTest : public QObject
{
    Q_OBJECT
public:
    TlsTest()
    {
        sock = new QTcpSocket( this );
        connect(sock, SIGNAL(connected()), SLOT(sock_connected()));
        connect(sock, SIGNAL(readyRead()), SLOT(sock_readyRead()));

        ssl = new QCA::TLS( this );
        connect(ssl, SIGNAL(handshaken()), SLOT(ssl_handshaken()));
        connect(ssl, SIGNAL(readyReadOutgoing()),
                SLOT(ssl_readyReadOutgoing()));

        sync = new QCA::Synchronizer( this );
    }

    ~TlsTest()
    {
        delete ssl;
        delete sock;
    }

    void start(const QString &_host, int port)
    {
        host = _host;
        sock->connectToHost(host, port);
    }

    void waitForHandshake( int timeout = 20000 )
    {
        sync->waitForCondition( timeout );
    }

    bool isHandshaken()
    {
        return ssl->isHandshaken();
    }

private slots:
    void sock_connected()
    {
        QCA::CertificateCollection rootCerts;
        QCA::ConvertResult resultRootCert;
        QCA::Certificate rootCert = QCA::Certificate::fromPEMFile( "root.crt", &resultRootCert);
        QCOMPARE( resultRootCert, QCA::ConvertGood );
        rootCerts.addCertificate( rootCert );

        ssl->setTrustedCertificates(rootCerts);

        ssl->startClient(host);
    }

    void sock_readyRead()
    {
        ssl->writeIncoming(sock->readAll());
    }

    void ssl_handshaken()
    {
        QCA::TLS::IdentityResult r = ssl->peerIdentityResult();

        QCOMPARE( r,  QCA::TLS::Valid );

        sync->conditionMet();
    }

    void ssl_readyReadOutgoing()
    {
        sock->write(ssl->readOutgoing());
    }

private:
    QString host;
    QTcpSocket *sock;
    QCA::TLS *ssl;
    QCA::Certificate cert;
    QCA::Synchronizer *sync;
};

class VeloxUnitTest : public QObject
{
    Q_OBJECT

private slots:
    void initTestCase();
    void cleanupTestCase();
    void sniAlice();
    void sniBob();
    void sniCarol();
    void sniDave();
    void sniMallory();
    void sniIvan();
private:
    QCA::Initializer* m_init;
    QCA::CertificateCollection rootCerts;
};

void VeloxUnitTest::initTestCase()
{
    m_init = new QCA::Initializer;
#include "../fixpaths.include"
}

void VeloxUnitTest::cleanupTestCase()
{
    delete m_init;
}

void VeloxUnitTest::sniAlice()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "alice.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

void VeloxUnitTest::sniBob()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "bob.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

void VeloxUnitTest::sniCarol()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "carol.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

void VeloxUnitTest::sniDave()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "dave.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

void VeloxUnitTest::sniMallory()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "mallory.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

void VeloxUnitTest::sniIvan()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "ivan.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

QTEST_MAIN(VeloxUnitTest)

#include "veloxunittest.moc"
<commit_msg>rearranged includes to follow Qt's 'include Qt headers first' - rule. This fixes a compile problem with msvc<commit_after>/**
 * Copyright (C)  2006  Brad Hards <bradh@frogmouth.net>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <QtNetwork>
#include <QtTest/QtTest>
#include <QtCrypto>

class TlsTest : public QObject
{
    Q_OBJECT
public:
    TlsTest()
    {
        sock = new QTcpSocket( this );
        connect(sock, SIGNAL(connected()), SLOT(sock_connected()));
        connect(sock, SIGNAL(readyRead()), SLOT(sock_readyRead()));

        ssl = new QCA::TLS( this );
        connect(ssl, SIGNAL(handshaken()), SLOT(ssl_handshaken()));
        connect(ssl, SIGNAL(readyReadOutgoing()),
                SLOT(ssl_readyReadOutgoing()));

        sync = new QCA::Synchronizer( this );
    }

    ~TlsTest()
    {
        delete ssl;
        delete sock;
    }

    void start(const QString &_host, int port)
    {
        host = _host;
        sock->connectToHost(host, port);
    }

    void waitForHandshake( int timeout = 20000 )
    {
        sync->waitForCondition( timeout );
    }

    bool isHandshaken()
    {
        return ssl->isHandshaken();
    }

private slots:
    void sock_connected()
    {
        QCA::CertificateCollection rootCerts;
        QCA::ConvertResult resultRootCert;
        QCA::Certificate rootCert = QCA::Certificate::fromPEMFile( "root.crt", &resultRootCert);
        QCOMPARE( resultRootCert, QCA::ConvertGood );
        rootCerts.addCertificate( rootCert );

        ssl->setTrustedCertificates(rootCerts);

        ssl->startClient(host);
    }

    void sock_readyRead()
    {
        ssl->writeIncoming(sock->readAll());
    }

    void ssl_handshaken()
    {
        QCA::TLS::IdentityResult r = ssl->peerIdentityResult();

        QCOMPARE( r,  QCA::TLS::Valid );

        sync->conditionMet();
    }

    void ssl_readyReadOutgoing()
    {
        sock->write(ssl->readOutgoing());
    }

private:
    QString host;
    QTcpSocket *sock;
    QCA::TLS *ssl;
    QCA::Certificate cert;
    QCA::Synchronizer *sync;
};

class VeloxUnitTest : public QObject
{
    Q_OBJECT

private slots:
    void initTestCase();
    void cleanupTestCase();
    void sniAlice();
    void sniBob();
    void sniCarol();
    void sniDave();
    void sniMallory();
    void sniIvan();
private:
    QCA::Initializer* m_init;
    QCA::CertificateCollection rootCerts;
};

void VeloxUnitTest::initTestCase()
{
    m_init = new QCA::Initializer;
#include "../fixpaths.include"
}

void VeloxUnitTest::cleanupTestCase()
{
    delete m_init;
}

void VeloxUnitTest::sniAlice()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "alice.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

void VeloxUnitTest::sniBob()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "bob.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

void VeloxUnitTest::sniCarol()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "carol.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

void VeloxUnitTest::sniDave()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "dave.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

void VeloxUnitTest::sniMallory()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "mallory.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

void VeloxUnitTest::sniIvan()
{
    if(!QCA::isSupported("tls", "qca-openssl"))
	QWARN("TLS not supported for qca-openssl");
    else {
        TlsTest *s = new TlsTest;
        s->start( "ivan.sni.velox.ch", 443 );
        s->waitForHandshake();
        QVERIFY( s->isHandshaken() );
    }
}

QTEST_MAIN(VeloxUnitTest)

#include "veloxunittest.moc"
<|endoftext|>


<commit_before>/* -*- 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 INCLUDED_WW8_DOCUMENT_HXX
#define INCLUDED_WW8_DOCUMENT_HXX

#include <boost/shared_ptr.hpp>
#include <sal/types.h>
#include <com/sun/star/uno/Reference.hxx>
#include <resourcemodel/SubSequence.hxx>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>

#include <resourcemodel/WW8ResourceModel.hxx>
#include <resourcemodel/OutputWithDepth.hxx>

#include <WriterFilterDllApi.hxx>

namespace writerfilter {
namespace doctok {

using namespace ::com::sun::star;

/**
   A stream containing a WW8 document.

   The content of the stream is a sequence of unsigned bytes. The
   stream consists of substreams that are identified by string
   identifiers.
*/
class WW8Stream
{
public:
    /**
       Pointer to a WW8Stream.
    */
    typedef boost::shared_ptr<WW8Stream> Pointer_t;

    /**
       Type for the content of the stream
     */
    typedef SubSequence<sal_uInt8> Sequence;

    virtual ~WW8Stream();

    /**
       Returns pointer to a substream.

       @param rSid     identifier of substream to return

       @return    the substream
     */
    virtual Pointer_t getSubStream(const OUString & rSid) = 0;

    /**
       Return a continious part of the stream.

       @param nOffset     offset in the stream where the part starts
       @param nCount      length of the part (number of bytes)

       @return    sequence of unsigned bytes
     */
    virtual Sequence get(sal_uInt32 nOffset, sal_uInt32 nCount)
        const = 0;

    // Returns the names of substreams contained in the stream
    virtual string getSubStreamNames() const = 0;

    virtual uno::Sequence<OUString> getSubStreamUNames() const = 0;

    /**
       Dumps content of stream to output.

       @param o     the target output
    */
    virtual void dump(OutputWithDepth<string> & o) const = 0;

    //virtual bool put(sal_uInt32 nOffset, const Sequence & rSeq) = 0;
};

/**
   A property.

*/
class WRITERFILTER_DOCTOK_DLLPUBLIC WW8Property
{
public:
    /**
       Ponter to a property.
    */
    typedef boost::shared_ptr<WW8Property> Pointer_t;

    virtual ~WW8Property();

    virtual sal_uInt32 getId() const = 0;
    virtual sal_uInt32 getParam() const = 0;
    virtual WW8Stream::Sequence getParams() const = 0;

    virtual string toString() const = 0;

    /**
       Dumps this object to an output.

    */
    virtual void dump(OutputWithDepth<string> & o) const = 0;
};

/**
   An iterator for traversal of a set of properties.

   Sample code for use of iterator:

   \code
   Return_t function(WW8PropertySet::tPointer pSet)
   {
       do_something;

       WW8PropertySetIterator::tPointer pIt = pSet->begin();
       WW8PropertySetIterator::tPointer pItEnd = pSet->end();

       while ((*pIt) != (*pItEnd))
       {
           do_something();

           ++(*pIt);
       }

       do_something;
   }
   \endcode
*/
class WRITERFILTER_DOCTOK_DLLPUBLIC WW8PropertySetIterator
{
public:
    typedef boost::shared_ptr<WW8PropertySetIterator> Pointer_t;

    virtual ~WW8PropertySetIterator();

    /**
       Advance iterator to the next property.
    */
    virtual WW8PropertySetIterator & operator++() = 0;

    /**
       Returns a pointer to the property the iterator references.
    */
    virtual WW8Property::Pointer_t get() const = 0;

    /**
       Checks if the iterator is equal to another one.
    */
    virtual bool equal(const WW8PropertySetIterator & rIt) const = 0;

    /**
       Returns string representation of iterator.
     */
    virtual string toString() const = 0;
};

/**
   Checks if two property set iterators are not equal.
*/
bool operator != (const WW8PropertySetIterator & rA,
                  const WW8PropertySetIterator & rB);

/**
   A set of properties.
*/
class WRITERFILTER_DOCTOK_DLLPUBLIC WW8PropertySet
{
public:
    typedef boost::shared_ptr<WW8PropertySet> Pointer_t;

    virtual ~WW8PropertySet();

    /**
       Returns iterator to the start of the set.
     */
    virtual WW8PropertySetIterator::Pointer_t begin() = 0;

    /**
       Returns iterator to the end of the set.
    */
    virtual WW8PropertySetIterator::Pointer_t end() = 0;

    /**
       Dumps property set to output stream.

       @param o    output stream to dump property set to
    */
    virtual void dump(OutputWithDepth<string> & o) const = 0;

    /**
       Iterate through property set and for each element dump a dot
       output stream.

       @param o      output stream to dump dots to
     */
    virtual void dots(ostream & o) = 0;

    virtual bool isPap() const = 0;
    virtual sal_uInt32 get_istd() const = 0;

    /**
       Insert another property set into this property set.

       @param pSet   the set to insert
     */
    virtual void insert(const WW8PropertySet::Pointer_t pSet) = 0;
};

enum PropertyType {
    /** Auxiliary type for character positions defined in piece table */
    PROP_DOC,

    /** properties are section properies */
    PROP_SEC,

    /** properties are paragraph properties */
    PROP_PAP,

    /** properties are character properties */
    PROP_CHP,

    /** a footnote reference */
    PROP_FOOTNOTE,

    /** an endnote reference */
    PROP_ENDNOTE,

    /** an annotaion reference */
    PROP_ANNOTATION,

    /** the start of a bookmark */
    PROP_BOOKMARKSTART,

    /** the end of a bookmark */
    PROP_BOOKMARKEND,

    /** a field character (start, separator or end) */
    PROP_FLD,

    /** a shape character */
    PROP_SHP,

    /** a break character */
    PROP_BRK
};

/**
   An iterator for traversal of the character positions of a Word
   document.

   The use of the iterator is analogous to WW8PropertySetIterator.
*/
class WW8DocumentIterator
{
public:
    typedef boost::shared_ptr<WW8DocumentIterator> Pointer_t;

    virtual ~WW8DocumentIterator();

    /**
       Advance iterator to next character position of the document.
    */
    virtual WW8DocumentIterator & operator++() = 0;

    /**
       Recedes iterator to previous character postion of the document.
     */
    virtual WW8DocumentIterator & operator--() = 0;

    /**
       Returns properties set at the character position the iterator
       points to.

       @return pointer to set of properties
     */
    virtual writerfilter::Reference<Properties>::Pointer_t getProperties()
        const = 0;

    virtual writerfilter::Reference<Stream>::Pointer_t getSubDocument()
        const = 0;

    /**
       Returns text run at the character position the iterator points
       to.
     */
    virtual WW8Stream::Sequence getText() = 0;

    /**
       Return pointer to the shape at character position the iterator
       is pointing to.
     */
    virtual writerfilter::Reference<Properties>::Pointer_t getShape() const = 0;

    /**
       Checks if the characters of the entity the iterator points to
       are complex.

       Complex characters in a Word document are byte size
       characters. Non-complex characters are word size characters.

       @retval true      The characters are complex.
       @retval false     The characters are non-complex.
     */
    virtual bool isComplex() const = 0;

    /**
       Returns the property type of the entity the iterator points to.
     */
    virtual PropertyType getPropertyType() const = 0;

    /**
       Checks is the iterator is equal to another one.

       @param rIt    iterator to check against

       @retval true    the iterators are equal
       @retval false   else
    */
    virtual bool equal(const WW8DocumentIterator & rIt) const = 0;

    /**
       Returns string representation of the iterator.
    */
    virtual string toString() const = 0;

    /**
       Dumps the iterator to an output stream.

       @param o    the output stream to dump the iterator to
     */
    virtual void dump(ostream & o) const = 0;
};

/**
   Checks if two document iterators are equal.

   @param rA     first iterator
   @param rB     second iterator

   @retval true    the document iterators are equal
   @retval false   else
 */
bool operator == (const WW8DocumentIterator & rA,
                  const WW8DocumentIterator & rB);

class SubDocumentId
{
public:
    enum eType { FOOTNOTES, HEADERS, FOOTERS };

private:
    eType mnType;
    sal_uInt8 mnIndex;

public:
    SubDocumentId(eType nType, sal_uInt8 nIndex)
    : mnType(nType), mnIndex(nIndex)
    {
    }

    eType getType() const { return mnType; }
    sal_uInt8 getIndex() const { return mnIndex; }
};

/**
   A Word 8 document.
*/
class WW8Document :
    public writerfilter::Reference<Stream>
{
public:
    typedef boost::shared_ptr<WW8Document> Pointer_t;

    virtual ~WW8Document();

    /**
       Get a subdocument.

       A subdocument can be

       - a header
       - a footer
       - a footnode

       @param nId identifier of the subdocumen
    */
    virtual Pointer_t getSubDocument(SubDocumentId nId) = 0;

    /**
       Returns iterator to beginning of document.
     */
    virtual WW8DocumentIterator::Pointer_t begin() = 0;

    /**
       Returns iterator to end of document.
     */
    virtual WW8DocumentIterator::Pointer_t end() = 0;
};

}}

#endif // INCLUDED_WW8_DOCUMENT_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>writerfilter: these classes can be private<commit_after>/* -*- 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 INCLUDED_WW8_DOCUMENT_HXX
#define INCLUDED_WW8_DOCUMENT_HXX

#include <boost/shared_ptr.hpp>
#include <sal/types.h>
#include <com/sun/star/uno/Reference.hxx>
#include <resourcemodel/SubSequence.hxx>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>

#include <resourcemodel/WW8ResourceModel.hxx>
#include <resourcemodel/OutputWithDepth.hxx>

#include <WriterFilterDllApi.hxx>

namespace writerfilter {
namespace doctok {

using namespace ::com::sun::star;

/**
   A stream containing a WW8 document.

   The content of the stream is a sequence of unsigned bytes. The
   stream consists of substreams that are identified by string
   identifiers.
*/
class WW8Stream
{
public:
    /**
       Pointer to a WW8Stream.
    */
    typedef boost::shared_ptr<WW8Stream> Pointer_t;

    /**
       Type for the content of the stream
     */
    typedef SubSequence<sal_uInt8> Sequence;

    virtual ~WW8Stream();

    /**
       Returns pointer to a substream.

       @param rSid     identifier of substream to return

       @return    the substream
     */
    virtual Pointer_t getSubStream(const OUString & rSid) = 0;

    /**
       Return a continious part of the stream.

       @param nOffset     offset in the stream where the part starts
       @param nCount      length of the part (number of bytes)

       @return    sequence of unsigned bytes
     */
    virtual Sequence get(sal_uInt32 nOffset, sal_uInt32 nCount)
        const = 0;

    // Returns the names of substreams contained in the stream
    virtual string getSubStreamNames() const = 0;

    virtual uno::Sequence<OUString> getSubStreamUNames() const = 0;

    /**
       Dumps content of stream to output.

       @param o     the target output
    */
    virtual void dump(OutputWithDepth<string> & o) const = 0;

    //virtual bool put(sal_uInt32 nOffset, const Sequence & rSeq) = 0;
};

/**
   A property.

*/
class WW8Property
{
public:
    /**
       Ponter to a property.
    */
    typedef boost::shared_ptr<WW8Property> Pointer_t;

    virtual ~WW8Property();

    virtual sal_uInt32 getId() const = 0;
    virtual sal_uInt32 getParam() const = 0;
    virtual WW8Stream::Sequence getParams() const = 0;

    virtual string toString() const = 0;

    /**
       Dumps this object to an output.

    */
    virtual void dump(OutputWithDepth<string> & o) const = 0;
};

/**
   An iterator for traversal of a set of properties.

   Sample code for use of iterator:

   \code
   Return_t function(WW8PropertySet::tPointer pSet)
   {
       do_something;

       WW8PropertySetIterator::tPointer pIt = pSet->begin();
       WW8PropertySetIterator::tPointer pItEnd = pSet->end();

       while ((*pIt) != (*pItEnd))
       {
           do_something();

           ++(*pIt);
       }

       do_something;
   }
   \endcode
*/
class WW8PropertySetIterator
{
public:
    typedef boost::shared_ptr<WW8PropertySetIterator> Pointer_t;

    virtual ~WW8PropertySetIterator();

    /**
       Advance iterator to the next property.
    */
    virtual WW8PropertySetIterator & operator++() = 0;

    /**
       Returns a pointer to the property the iterator references.
    */
    virtual WW8Property::Pointer_t get() const = 0;

    /**
       Checks if the iterator is equal to another one.
    */
    virtual bool equal(const WW8PropertySetIterator & rIt) const = 0;

    /**
       Returns string representation of iterator.
     */
    virtual string toString() const = 0;
};

/**
   Checks if two property set iterators are not equal.
*/
bool operator != (const WW8PropertySetIterator & rA,
                  const WW8PropertySetIterator & rB);

/**
   A set of properties.
*/
class WW8PropertySet
{
public:
    typedef boost::shared_ptr<WW8PropertySet> Pointer_t;

    virtual ~WW8PropertySet();

    /**
       Returns iterator to the start of the set.
     */
    virtual WW8PropertySetIterator::Pointer_t begin() = 0;

    /**
       Returns iterator to the end of the set.
    */
    virtual WW8PropertySetIterator::Pointer_t end() = 0;

    /**
       Dumps property set to output stream.

       @param o    output stream to dump property set to
    */
    virtual void dump(OutputWithDepth<string> & o) const = 0;

    /**
       Iterate through property set and for each element dump a dot
       output stream.

       @param o      output stream to dump dots to
     */
    virtual void dots(ostream & o) = 0;

    virtual bool isPap() const = 0;
    virtual sal_uInt32 get_istd() const = 0;

    /**
       Insert another property set into this property set.

       @param pSet   the set to insert
     */
    virtual void insert(const WW8PropertySet::Pointer_t pSet) = 0;
};

enum PropertyType {
    /** Auxiliary type for character positions defined in piece table */
    PROP_DOC,

    /** properties are section properies */
    PROP_SEC,

    /** properties are paragraph properties */
    PROP_PAP,

    /** properties are character properties */
    PROP_CHP,

    /** a footnote reference */
    PROP_FOOTNOTE,

    /** an endnote reference */
    PROP_ENDNOTE,

    /** an annotaion reference */
    PROP_ANNOTATION,

    /** the start of a bookmark */
    PROP_BOOKMARKSTART,

    /** the end of a bookmark */
    PROP_BOOKMARKEND,

    /** a field character (start, separator or end) */
    PROP_FLD,

    /** a shape character */
    PROP_SHP,

    /** a break character */
    PROP_BRK
};

/**
   An iterator for traversal of the character positions of a Word
   document.

   The use of the iterator is analogous to WW8PropertySetIterator.
*/
class WW8DocumentIterator
{
public:
    typedef boost::shared_ptr<WW8DocumentIterator> Pointer_t;

    virtual ~WW8DocumentIterator();

    /**
       Advance iterator to next character position of the document.
    */
    virtual WW8DocumentIterator & operator++() = 0;

    /**
       Recedes iterator to previous character postion of the document.
     */
    virtual WW8DocumentIterator & operator--() = 0;

    /**
       Returns properties set at the character position the iterator
       points to.

       @return pointer to set of properties
     */
    virtual writerfilter::Reference<Properties>::Pointer_t getProperties()
        const = 0;

    virtual writerfilter::Reference<Stream>::Pointer_t getSubDocument()
        const = 0;

    /**
       Returns text run at the character position the iterator points
       to.
     */
    virtual WW8Stream::Sequence getText() = 0;

    /**
       Return pointer to the shape at character position the iterator
       is pointing to.
     */
    virtual writerfilter::Reference<Properties>::Pointer_t getShape() const = 0;

    /**
       Checks if the characters of the entity the iterator points to
       are complex.

       Complex characters in a Word document are byte size
       characters. Non-complex characters are word size characters.

       @retval true      The characters are complex.
       @retval false     The characters are non-complex.
     */
    virtual bool isComplex() const = 0;

    /**
       Returns the property type of the entity the iterator points to.
     */
    virtual PropertyType getPropertyType() const = 0;

    /**
       Checks is the iterator is equal to another one.

       @param rIt    iterator to check against

       @retval true    the iterators are equal
       @retval false   else
    */
    virtual bool equal(const WW8DocumentIterator & rIt) const = 0;

    /**
       Returns string representation of the iterator.
    */
    virtual string toString() const = 0;

    /**
       Dumps the iterator to an output stream.

       @param o    the output stream to dump the iterator to
     */
    virtual void dump(ostream & o) const = 0;
};

/**
   Checks if two document iterators are equal.

   @param rA     first iterator
   @param rB     second iterator

   @retval true    the document iterators are equal
   @retval false   else
 */
bool operator == (const WW8DocumentIterator & rA,
                  const WW8DocumentIterator & rB);

class SubDocumentId
{
public:
    enum eType { FOOTNOTES, HEADERS, FOOTERS };

private:
    eType mnType;
    sal_uInt8 mnIndex;

public:
    SubDocumentId(eType nType, sal_uInt8 nIndex)
    : mnType(nType), mnIndex(nIndex)
    {
    }

    eType getType() const { return mnType; }
    sal_uInt8 getIndex() const { return mnIndex; }
};

/**
   A Word 8 document.
*/
class WW8Document :
    public writerfilter::Reference<Stream>
{
public:
    typedef boost::shared_ptr<WW8Document> Pointer_t;

    virtual ~WW8Document();

    /**
       Get a subdocument.

       A subdocument can be

       - a header
       - a footer
       - a footnode

       @param nId identifier of the subdocumen
    */
    virtual Pointer_t getSubDocument(SubDocumentId nId) = 0;

    /**
       Returns iterator to beginning of document.
     */
    virtual WW8DocumentIterator::Pointer_t begin() = 0;

    /**
       Returns iterator to end of document.
     */
    virtual WW8DocumentIterator::Pointer_t end() = 0;
};

}}

#endif // INCLUDED_WW8_DOCUMENT_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>


<commit_before>#include "vec3.h"

namespace fd {
namespace core {
namespace math {

vec3d::vec3d() : x(0), y(0), z(0) {}

vec3d::vec3d(float64 x, float64 y, float64 z) : x(x), y(y), z(z) {}

//float64
vec3d& vec3d::Add(const vec3d& v) {
	__m256d vxmm = _mm256_set_pd(0, v.z, v.y, v.x);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_add_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Sub(const vec3d& v) {
	__m256d vxmm = _mm256_set_pd(0, v.z, v.y, v.x);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_sub_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Mul(const vec3d& v) {
	__m256d vxmm = _mm256_set_pd(0, v.z, v.y, v.x);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_mul_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Div(const vec3d& v) {
	__m256d vxmm = _mm256_set_pd(0, v.z, v.y, v.x);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_div_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Add(float64 v) {
	__m256d vxmm = _mm256_set_pd(0, v, v, v);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_add_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Sub(float64 v) {
	__m256d vxmm = _mm256_set_pd(0, v, v, v);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_sub_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Mul(float64 v) {
	__m256d vxmm = _mm256_set_pd(0, v, v, v);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_mul_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Div(float64 v) {
	__m256d vxmm = _mm256_set_pd(0, v, v, v);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_div_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

float64 vec3d::Length() const {
	return sqrt(x * x + y * y + z * z);
}

vec3d& vec3d::Normalize() {
	return Mul(1.0 / Length());
}

vec3d vec3d::Cross(const vec3d& v) const {
	__m256d xmm0 = _mm256_set_pd(0, x, z, y);
	__m256d vxmm0 = _mm256_set_pd(0, v.y, v.x, v.z);

	__m256d xmm1 = _mm256_set_pd(0, y, x, z);
	__m256d vxmm1 = _mm256_set_pd(0, v.x, v.z, v.y);

	xmm0 = _mm256_mul_pd(xmm0, vxmm0);
	xmm1 = _mm256_mul_pd(xmm1, vxmm1);

	xmm0 = _mm256_sub_pd(xmm0, xmm1);

	return vec3d(xmm0.m256d_f64[0], xmm0.m256d_f64[1], xmm0.m256d_f64[2]);
}

float64 vec3d::Dot(const vec3d& v) const {
	__m256d xmm = _mm256_set_pd(0, v.z, v.y, v.x);
	xmm = _mm256_mul_pd(xmm, _mm256_set_pd(0, y, z, x));
	return M256D(xmm, 0) + M256D(xmm, 1) + M256D(xmm, 2);
}

}
}
}<commit_msg>I'm stupid again<commit_after>#include "vec3.h"

namespace fd {
namespace core {
namespace math {

vec3d::vec3d() : x(0), y(0), z(0) {}

vec3d::vec3d(float64 x, float64 y, float64 z) : x(x), y(y), z(z) {}

//float64
vec3d& vec3d::Add(const vec3d& v) {
	__m256d vxmm = _mm256_set_pd(0, v.z, v.y, v.x);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_add_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Sub(const vec3d& v) {
	__m256d vxmm = _mm256_set_pd(0, v.z, v.y, v.x);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_sub_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Mul(const vec3d& v) {
	__m256d vxmm = _mm256_set_pd(0, v.z, v.y, v.x);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_mul_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Div(const vec3d& v) {
	__m256d vxmm = _mm256_set_pd(0, v.z, v.y, v.x);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_div_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Add(float64 v) {
	__m256d vxmm = _mm256_set_pd(0, v, v, v);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_add_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Sub(float64 v) {
	__m256d vxmm = _mm256_set_pd(0, v, v, v);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_sub_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Mul(float64 v) {
	__m256d vxmm = _mm256_set_pd(0, v, v, v);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_mul_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

//float64
vec3d& vec3d::Div(float64 v) {
	__m256d vxmm = _mm256_set_pd(0, v, v, v);
	__m256d xmm = _mm256_set_pd(0, z, y, x);
	xmm = _mm256_div_pd(xmm, vxmm);

	x = M256D(xmm, 0);
	y = M256D(xmm, 1);
	z = M256D(xmm, 2);

	return *this;
}

float64 vec3d::Length() const {
	return sqrt(x * x + y * y + z * z);
}

vec3d& vec3d::Normalize() {
	return Mul(1.0 / Length());
}

vec3d vec3d::Cross(const vec3d& v) const {
	__m256d xmm0 = _mm256_set_pd(0, x, z, y);
	__m256d vxmm0 = _mm256_set_pd(0, v.y, v.x, v.z);

	__m256d xmm1 = _mm256_set_pd(0, y, x, z);
	__m256d vxmm1 = _mm256_set_pd(0, v.x, v.z, v.y);

	xmm0 = _mm256_mul_pd(xmm0, vxmm0);
	xmm1 = _mm256_mul_pd(xmm1, vxmm1);

	xmm0 = _mm256_sub_pd(xmm0, xmm1);

	return vec3d(M256D(xmm0, 0), M256D(xmm0, 1), M256D(xmm0, 2));
}

float64 vec3d::Dot(const vec3d& v) const {
	__m256d xmm = _mm256_set_pd(0, v.z, v.y, v.x);
	xmm = _mm256_mul_pd(xmm, _mm256_set_pd(0, y, z, x));
	return M256D(xmm, 0) + M256D(xmm, 1) + M256D(xmm, 2);
}

}
}
}<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: core_resource.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: vg $ $Date: 2006-04-07 14:12:14 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include "core_resource.hxx"

#ifndef _TOOLS_SIMPLERESMGR_HXX_
#include <tools/simplerm.hxx>
#endif

// ---- needed as long as we have no contexts for components ---
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
//---------------------------------------------------

#ifndef _SOLAR_HRC
#include <svtools/solar.hrc>
#endif

//.........................................................................
namespace dbaccess
{

    //==================================================================
    //= ResourceManager
    //==================================================================
    SimpleResMgr* ResourceManager::m_pImpl = NULL;

    //------------------------------------------------------------------
    ResourceManager::EnsureDelete::~EnsureDelete()
    {
        delete ResourceManager::m_pImpl;
    }

    //------------------------------------------------------------------
    void ResourceManager::ensureImplExists()
    {
        if (m_pImpl)
            return;

        ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();

        ByteString sFileName("dba");
        sFileName += ByteString::CreateFromInt32( (sal_Int32)SOLARUPD );

        m_pImpl = SimpleResMgr::Create(sFileName.GetBuffer(), aLocale);

        if (m_pImpl)
        {
            // now that we have an impl class make sure it's deleted on unloading the library
            static ResourceManager::EnsureDelete    s_aDeleteTheImplClass;
        }
    }

    //------------------------------------------------------------------
    ::rtl::OUString ResourceManager::loadString(sal_uInt16 _nResId)
    {
        ::rtl::OUString sReturn;

        ensureImplExists();
        if (m_pImpl)
            sReturn = m_pImpl->ReadString(_nResId);

        return sReturn;
    }

//.........................................................................
}
//.........................................................................

<commit_msg>INTEGRATION: CWS qiq (1.7.20); FILE MERGED 2006/06/09 11:55:55 fs 1.7.20.1: #i51143# +loadString with placeholder replacement<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: core_resource.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: obo $ $Date: 2006-07-10 15:17:48 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include "core_resource.hxx"

#ifndef _TOOLS_SIMPLERESMGR_HXX_
#include <tools/simplerm.hxx>
#endif

// ---- needed as long as we have no contexts for components ---
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
//---------------------------------------------------

#ifndef _SOLAR_HRC
#include <svtools/solar.hrc>
#endif

//.........................................................................
namespace dbaccess
{

    //==================================================================
    //= ResourceManager
    //==================================================================
    SimpleResMgr* ResourceManager::m_pImpl = NULL;

    //------------------------------------------------------------------
    ResourceManager::EnsureDelete::~EnsureDelete()
    {
        delete ResourceManager::m_pImpl;
    }

    //------------------------------------------------------------------
    void ResourceManager::ensureImplExists()
    {
        if (m_pImpl)
            return;

        ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();

        ByteString sFileName("dba");
        sFileName += ByteString::CreateFromInt32( (sal_Int32)SOLARUPD );

        m_pImpl = SimpleResMgr::Create(sFileName.GetBuffer(), aLocale);

        if (m_pImpl)
        {
            // now that we have an impl class make sure it's deleted on unloading the library
            static ResourceManager::EnsureDelete    s_aDeleteTheImplClass;
        }
    }

    //------------------------------------------------------------------
    ::rtl::OUString ResourceManager::loadString(sal_uInt16 _nResId)
    {
        ::rtl::OUString sReturn;

        ensureImplExists();
        if (m_pImpl)
            sReturn = m_pImpl->ReadString(_nResId);

        return sReturn;
    }

    //------------------------------------------------------------------
    ::rtl::OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii, const ::rtl::OUString& _rReplace )
    {
        String sString( loadString( _nResId ) );
        sString.SearchAndReplaceAscii( _pPlaceholderAscii, _rReplace );
        return sString;
    }

//.........................................................................
}
//.........................................................................

<|endoftext|>