<commit_before>/******************************************************************************
* Copyright (c) 2012, Michael P. Gerlek (mpg@flaxen.com)
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * 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.
*     * Neither the name of Hobu, Inc. or Flaxen Consulting LLC nor the
*       names of its contributors may be used to endorse or promote
*       products derived from this software without specific prior
*       written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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
* COPYRIGHT OWNER OR CONTRIBUTORS 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 <boost/test/unit_test.hpp>
#include <boost/cstdint.hpp>

#include <boost/uuid/uuid_io.hpp>

#include <pdal/PointBuffer.hpp>

#include <pdal/drivers/nitf/Reader.hpp>
#include <pdal/drivers/las/Reader.hpp>
#include <pdal/filters/Chipper.hpp>
#include <pdal/drivers/pipeline/Reader.hpp>

#include "Support.hpp"

#include <iostream>

#ifdef PDAL_COMPILER_GCC
#pragma GCC diagnostic ignored "-Wfloat-equal"
#pragma GCC diagnostic ignored "-Wsign-compare"
#endif

#include <boost/property_tree/xml_parser.hpp>

using namespace pdal;

BOOST_AUTO_TEST_SUITE(NitfReaderTest)

BOOST_AUTO_TEST_CASE(test_one)
{
    //
    // read NITF
    //
    pdal::Option nitf_opt("filename", Support::datapath("nitf/autzen-utm10.ntf"));
    pdal::Options nitf_opts;
    nitf_opts.add(nitf_opt);

    pdal::drivers::nitf::Reader nitf_reader(nitf_opts);
    nitf_reader.initialize();

    BOOST_CHECK_EQUAL(nitf_reader.getDescription(), "NITF Reader");

    // check metadata
    {
        pdal::Metadata metadata = nitf_reader.getMetadata();
        /////////////////////////////////////////////////BOOST_CHECK_EQUAL(metadatums.size(), 80u);
        BOOST_CHECK_EQUAL(metadata.toPTree().get<std::string>("metadata.FH_FDT.value"), "20120323002946");
    }

    const Schema& nitf_schema = nitf_reader.getSchema();

    PointBuffer nitf_data(nitf_schema, 750);

    StageSequentialIterator* nitf_iter = nitf_reader.createSequentialIterator(nitf_data);
    const boost::uint32_t nitf_numRead = nitf_iter->read(nitf_data);

    //
    // read LAS
    //
    pdal::Option las_opt("filename", Support::datapath("nitf/autzen-utm10.las"));
    pdal::Options las_opts;
    las_opts.add(las_opt);

    pdal::drivers::las::Reader las_reader(las_opts);
    las_reader.initialize();
    const Schema& las_schema = las_reader.getSchema();

    PointBuffer las_data(las_schema, 750);

    StageSequentialIterator* las_iter = las_reader.createSequentialIterator(las_data);
    const boost::uint32_t las_numRead = las_iter->read(las_data);

    //
    // compare the two buffers
    //
    BOOST_CHECK_EQUAL(las_numRead, nitf_numRead);

    Dimension const& nitf_dimX = nitf_schema.getDimension("X");
    Dimension const& nitf_dimY = nitf_schema.getDimension("Y");
    Dimension const& nitf_dimZ = nitf_schema.getDimension("Z");

    Dimension const& las_dimX = las_schema.getDimension("X");
    Dimension const& las_dimY = las_schema.getDimension("Y");
    Dimension const& las_dimZ = las_schema.getDimension("Z");

    for (boost::uint32_t i=0; i<las_numRead; i++)
    {
        const double nitf_x = nitf_data.getField<double>(nitf_dimX, i);
        const double nitf_y = nitf_data.getField<double>(nitf_dimY, i);
        const double nitf_z = nitf_data.getField<double>(nitf_dimZ, i);

        const double las_x = las_data.getField<double>(las_dimX, i);
        const double las_y = las_data.getField<double>(las_dimY, i);
        const double las_z = las_data.getField<double>(las_dimZ, i);

        BOOST_CHECK_CLOSE(nitf_x, las_x, 0.00001);
        BOOST_CHECK_CLOSE(nitf_y, las_y, 0.00001);
        BOOST_CHECK_CLOSE(nitf_z, las_z, 0.00001);
    }

    delete nitf_iter;
    delete las_iter;

    return;
}

BOOST_AUTO_TEST_CASE(test_chipper)
{
    //
    // read NITF
    //

    pdal::Option option("filename", Support::datapath("nitf/chipper.xml"));
    pdal::Options options(option);

    pdal::drivers::pipeline::Reader reader(options);
    reader.initialize();

    pdal::filters::Chipper* chipper = static_cast<pdal::filters::Chipper*>(reader.getManager().getStage());

    const Schema& schema = reader.getSchema();

    PointBuffer data(schema, 25);

    StageSequentialIterator* iter = reader.createSequentialIterator(data);
    const boost::uint32_t num_read = iter->read(data);
    BOOST_CHECK_EQUAL(num_read, 13u);

    boost::uint32_t num_blocks = chipper->GetBlockCount();
    BOOST_CHECK_EQUAL(num_blocks, 8u);

    return;
}

BOOST_AUTO_TEST_SUITE_END()
<commit_msg>fix mem leaks<commit_after>/******************************************************************************
* Copyright (c) 2012, Michael P. Gerlek (mpg@flaxen.com)
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * 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.
*     * Neither the name of Hobu, Inc. or Flaxen Consulting LLC nor the
*       names of its contributors may be used to endorse or promote
*       products derived from this software without specific prior
*       written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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
* COPYRIGHT OWNER OR CONTRIBUTORS 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 <boost/test/unit_test.hpp>
#include <boost/cstdint.hpp>

#include <boost/uuid/uuid_io.hpp>

#include <pdal/PointBuffer.hpp>

#include <pdal/drivers/nitf/Reader.hpp>
#include <pdal/drivers/las/Reader.hpp>
#include <pdal/filters/Chipper.hpp>
#include <pdal/drivers/pipeline/Reader.hpp>

#include "Support.hpp"

#include <iostream>

#ifdef PDAL_COMPILER_GCC
#pragma GCC diagnostic ignored "-Wfloat-equal"
#pragma GCC diagnostic ignored "-Wsign-compare"
#endif

#include <boost/property_tree/xml_parser.hpp>

using namespace pdal;

BOOST_AUTO_TEST_SUITE(NitfReaderTest)

BOOST_AUTO_TEST_CASE(test_one)
{
    //
    // read NITF
    //
    pdal::Option nitf_opt("filename", Support::datapath("nitf/autzen-utm10.ntf"));
    pdal::Options nitf_opts;
    nitf_opts.add(nitf_opt);

    pdal::drivers::nitf::Reader nitf_reader(nitf_opts);
    nitf_reader.initialize();

    BOOST_CHECK_EQUAL(nitf_reader.getDescription(), "NITF Reader");

    // check metadata
    {
        pdal::Metadata metadata = nitf_reader.getMetadata();
        /////////////////////////////////////////////////BOOST_CHECK_EQUAL(metadatums.size(), 80u);
        BOOST_CHECK_EQUAL(metadata.toPTree().get<std::string>("metadata.FH_FDT.value"), "20120323002946");
    }

    const Schema& nitf_schema = nitf_reader.getSchema();

    PointBuffer nitf_data(nitf_schema, 750);

    StageSequentialIterator* nitf_iter = nitf_reader.createSequentialIterator(nitf_data);
    const boost::uint32_t nitf_numRead = nitf_iter->read(nitf_data);

    //
    // read LAS
    //
    pdal::Option las_opt("filename", Support::datapath("nitf/autzen-utm10.las"));
    pdal::Options las_opts;
    las_opts.add(las_opt);

    pdal::drivers::las::Reader las_reader(las_opts);
    las_reader.initialize();
    const Schema& las_schema = las_reader.getSchema();

    PointBuffer las_data(las_schema, 750);

    StageSequentialIterator* las_iter = las_reader.createSequentialIterator(las_data);
    const boost::uint32_t las_numRead = las_iter->read(las_data);

    //
    // compare the two buffers
    //
    BOOST_CHECK_EQUAL(las_numRead, nitf_numRead);

    Dimension const& nitf_dimX = nitf_schema.getDimension("X");
    Dimension const& nitf_dimY = nitf_schema.getDimension("Y");
    Dimension const& nitf_dimZ = nitf_schema.getDimension("Z");

    Dimension const& las_dimX = las_schema.getDimension("X");
    Dimension const& las_dimY = las_schema.getDimension("Y");
    Dimension const& las_dimZ = las_schema.getDimension("Z");

    for (boost::uint32_t i=0; i<las_numRead; i++)
    {
        const double nitf_x = nitf_data.getField<double>(nitf_dimX, i);
        const double nitf_y = nitf_data.getField<double>(nitf_dimY, i);
        const double nitf_z = nitf_data.getField<double>(nitf_dimZ, i);

        const double las_x = las_data.getField<double>(las_dimX, i);
        const double las_y = las_data.getField<double>(las_dimY, i);
        const double las_z = las_data.getField<double>(las_dimZ, i);

        BOOST_CHECK_CLOSE(nitf_x, las_x, 0.00001);
        BOOST_CHECK_CLOSE(nitf_y, las_y, 0.00001);
        BOOST_CHECK_CLOSE(nitf_z, las_z, 0.00001);
    }

    delete nitf_iter;
    delete las_iter;

    return;
}

BOOST_AUTO_TEST_CASE(test_chipper)
{
    //
    // read NITF
    //

    pdal::Option option("filename", Support::datapath("nitf/chipper.xml"));
    pdal::Options options(option);

    pdal::drivers::pipeline::Reader reader(options);
    reader.initialize();

    pdal::filters::Chipper* chipper = static_cast<pdal::filters::Chipper*>(reader.getManager().getStage());

    const Schema& schema = reader.getSchema();

    PointBuffer data(schema, 25);

    StageSequentialIterator* iter = reader.createSequentialIterator(data);
    const boost::uint32_t num_read = iter->read(data);
    BOOST_CHECK_EQUAL(num_read, 13u);

    boost::uint32_t num_blocks = chipper->GetBlockCount();
    BOOST_CHECK_EQUAL(num_blocks, 8u);

    delete iter;

    return;
}

BOOST_AUTO_TEST_SUITE_END()
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: tdoc_datasupplier.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: ihi $ $Date: 2007-06-05 18:16:37 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_ucb.hxx"

/**************************************************************************
                                TODO
 **************************************************************************

 *************************************************************************/

#include <vector>

#include "osl/diagnose.h"
#include "ucbhelper/contentidentifier.hxx"

#include "tdoc_datasupplier.hxx"
#include "tdoc_content.hxx"

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

namespace tdoc_ucp
{

//=========================================================================
//
// struct ResultListEntry.
//
//=========================================================================

struct ResultListEntry
{
    rtl::OUString                             aURL;
    uno::Reference< ucb::XContentIdentifier > xId;
    uno::Reference< ucb::XContent >           xContent;
    uno::Reference< sdbc::XRow >              xRow;

    ResultListEntry( const rtl::OUString& rURL ) : aURL( rURL ) {}
};

//=========================================================================
//
// ResultList.
//
//=========================================================================

typedef std::vector< ResultListEntry* > ResultList;

//=========================================================================
//
// struct DataSupplier_Impl.
//
//=========================================================================

struct DataSupplier_Impl
{
    osl::Mutex                                   m_aMutex;
    ResultList                                   m_aResults;
    rtl::Reference< Content >                    m_xContent;
    uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
    uno::Sequence< rtl::OUString > *             m_pNamesOfChildren;
    sal_Int32                                    m_nOpenMode;
    bool                                         m_bCountFinal;
    bool                                         m_bThrowException;

    DataSupplier_Impl(
            const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
            const rtl::Reference< Content >& rContent,
            sal_Int32 nOpenMode )
    : m_xContent( rContent ), m_xSMgr( rxSMgr ),
      m_pNamesOfChildren( 0 ), m_nOpenMode( nOpenMode ),
      m_bCountFinal( false ), m_bThrowException( false )
    {}
    ~DataSupplier_Impl();
};

//=========================================================================
DataSupplier_Impl::~DataSupplier_Impl()
{
    ResultList::const_iterator it  = m_aResults.begin();
    ResultList::const_iterator end = m_aResults.end();

    while ( it != end )
    {
        delete (*it);
        it++;
    }

    delete m_pNamesOfChildren;
}

}

//=========================================================================
//=========================================================================
//
// DataSupplier Implementation.
//
//=========================================================================
//=========================================================================

ResultSetDataSupplier::ResultSetDataSupplier(
                const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
                const rtl::Reference< Content >& rContent,
                sal_Int32 nOpenMode )
: m_pImpl( new DataSupplier_Impl( rxSMgr, rContent, nOpenMode ) )
{
}

//=========================================================================
// virtual
ResultSetDataSupplier::~ResultSetDataSupplier()
{
    delete m_pImpl;
}

//=========================================================================
// virtual
rtl::OUString
ResultSetDataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( nIndex < m_pImpl->m_aResults.size() )
    {
        rtl::OUString aId = m_pImpl->m_aResults[ nIndex ]->aURL;
        if ( aId.getLength() )
        {
            // Already cached.
            return aId;
        }
    }

    if ( getResult( nIndex ) )
    {
        // Note: getResult fills m_pImpl->m_aResults[ nIndex ]->aURL.
        return m_pImpl->m_aResults[ nIndex ]->aURL;
    }
    return rtl::OUString();
}

//=========================================================================
// virtual
uno::Reference< ucb::XContentIdentifier >
ResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( nIndex < m_pImpl->m_aResults.size() )
    {
        uno::Reference< ucb::XContentIdentifier > xId
                                = m_pImpl->m_aResults[ nIndex ]->xId;
        if ( xId.is() )
        {
            // Already cached.
            return xId;
        }
    }

    rtl::OUString aId = queryContentIdentifierString( nIndex );
    if ( aId.getLength() )
    {
        uno::Reference< ucb::XContentIdentifier > xId
            = new ::ucbhelper::ContentIdentifier( aId );
        m_pImpl->m_aResults[ nIndex ]->xId = xId;
        return xId;
    }
    return uno::Reference< ucb::XContentIdentifier >();
}

//=========================================================================
// virtual
uno::Reference< ucb::XContent >
ResultSetDataSupplier::queryContent( sal_uInt32 nIndex )
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( nIndex < m_pImpl->m_aResults.size() )
    {
        uno::Reference< ucb::XContent > xContent
                                = m_pImpl->m_aResults[ nIndex ]->xContent;
        if ( xContent.is() )
        {
            // Already cached.
            return xContent;
        }
    }

    uno::Reference< ucb::XContentIdentifier > xId
        = queryContentIdentifier( nIndex );
    if ( xId.is() )
    {
        try
        {
            uno::Reference< ucb::XContent > xContent
                = m_pImpl->m_xContent->getProvider()->queryContent( xId );
            m_pImpl->m_aResults[ nIndex ]->xContent = xContent;
            return xContent;

        }
        catch ( ucb::IllegalIdentifierException const & )
        {
        }
    }
    return uno::Reference< ucb::XContent >();
}

//=========================================================================
// virtual
sal_Bool ResultSetDataSupplier::getResult( sal_uInt32 nIndex )
{
    osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( m_pImpl->m_aResults.size() > nIndex )
    {
        // Result already present.
        return sal_True;
    }

    // Result not (yet) present.

    if ( m_pImpl->m_bCountFinal )
        return sal_False;

    // Try to obtain result...

    sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
    bool bFound = false;

    if ( queryNamesOfChildren() )
    {
        for ( sal_uInt32 n = nOldCount;
              n < sal::static_int_cast<sal_uInt32>(
                      m_pImpl->m_pNamesOfChildren->getLength());
              ++n )
        {
            const rtl::OUString & rName
                = m_pImpl->m_pNamesOfChildren->getConstArray()[ n ];

            if ( !rName.getLength() )
            {
                OSL_ENSURE( sal_False,
                            "ResultDataSupplier::getResult - Empty name!" );
                break;
            }

            // Assemble URL for child.
            rtl::OUString aURL = assembleChildURL( rName );

            m_pImpl->m_aResults.push_back( new ResultListEntry( aURL ) );

            if ( n == nIndex )
            {
                // Result obtained.
                bFound = true;
                break;
            }
        }
    }

    if ( !bFound )
        m_pImpl->m_bCountFinal = sal_True;

    rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
    if ( xResultSet.is() )
    {
        // Callbacks follow!
        aGuard.clear();

        if ( nOldCount < m_pImpl->m_aResults.size() )
            xResultSet->rowCountChanged( nOldCount, m_pImpl->m_aResults.size() );

        if ( m_pImpl->m_bCountFinal )
            xResultSet->rowCountFinal();
    }

    return bFound;
}

//=========================================================================
// virtual
sal_uInt32 ResultSetDataSupplier::totalCount()
{
    osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( m_pImpl->m_bCountFinal )
        return m_pImpl->m_aResults.size();

    sal_uInt32 nOldCount = m_pImpl->m_aResults.size();

    if ( queryNamesOfChildren() )
    {
        for ( sal_uInt32 n = nOldCount;
              n < sal::static_int_cast<sal_uInt32>(
                      m_pImpl->m_pNamesOfChildren->getLength());
              ++n )
        {
            const rtl::OUString & rName
                = m_pImpl->m_pNamesOfChildren->getConstArray()[ n ];

            if ( !rName.getLength() )
            {
                OSL_ENSURE( sal_False,
                            "ResultDataSupplier::getResult - Empty name!" );
                break;
            }

            // Assemble URL for child.
            rtl::OUString aURL = assembleChildURL( rName );

            m_pImpl->m_aResults.push_back( new ResultListEntry( aURL ) );
        }
    }

    m_pImpl->m_bCountFinal = sal_True;

    rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
    if ( xResultSet.is() )
    {
        // Callbacks follow!
        aGuard.clear();

        if ( nOldCount < m_pImpl->m_aResults.size() )
            xResultSet->rowCountChanged( nOldCount, m_pImpl->m_aResults.size() );

        xResultSet->rowCountFinal();
    }

    return m_pImpl->m_aResults.size();
}

//=========================================================================
// virtual
sal_uInt32 ResultSetDataSupplier::currentCount()
{
    return m_pImpl->m_aResults.size();
}

//=========================================================================
// virtual
sal_Bool ResultSetDataSupplier::isCountFinal()
{
    return m_pImpl->m_bCountFinal;
}

//=========================================================================
// virtual
uno::Reference< sdbc::XRow >
ResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex  )
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( nIndex < m_pImpl->m_aResults.size() )
    {
        uno::Reference< sdbc::XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow;
        if ( xRow.is() )
        {
            // Already cached.
            return xRow;
        }
    }

    if ( getResult( nIndex ) )
    {
        uno::Reference< sdbc::XRow > xRow = Content::getPropertyValues(
                        m_pImpl->m_xSMgr,
                        getResultSet()->getProperties(),
                        m_pImpl->m_xContent->getContentProvider().get(),
                        queryContentIdentifierString( nIndex ) );
        m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
        return xRow;
    }

    return uno::Reference< sdbc::XRow >();
}

//=========================================================================
// virtual
void ResultSetDataSupplier::releasePropertyValues( sal_uInt32 nIndex )
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( nIndex < m_pImpl->m_aResults.size() )
        m_pImpl->m_aResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
}

//=========================================================================
// virtual
void ResultSetDataSupplier::close()
{
}

//=========================================================================
// virtual
void ResultSetDataSupplier::validate()
    throw( ucb::ResultSetException )
{
    if ( m_pImpl->m_bThrowException )
        throw ucb::ResultSetException();
}

//=========================================================================
bool ResultSetDataSupplier::queryNamesOfChildren()
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( m_pImpl->m_pNamesOfChildren == 0 )
    {
        uno::Sequence< rtl::OUString > * pNamesOfChildren
            = new uno::Sequence< rtl::OUString >();

        if ( !m_pImpl->m_xContent->getContentProvider()->queryNamesOfChildren(
                m_pImpl->m_xContent->getIdentifier()->getContentIdentifier(),
                *pNamesOfChildren ) )
        {
            OSL_ENSURE( false, "Got no list of children!" );
            m_pImpl->m_bThrowException = sal_True;
            return false;
        }
        else
        {
            m_pImpl->m_pNamesOfChildren = pNamesOfChildren;
        }
    }
    return true;
}

//=========================================================================
::rtl::OUString
ResultSetDataSupplier::assembleChildURL( const ::rtl::OUString& aName )
{
    rtl::OUString aContURL
        = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier();
    rtl::OUString aURL( aContURL );

    sal_Int32 nUrlEnd = aURL.lastIndexOf( '/' );
    if ( nUrlEnd != aURL.getLength() - 1 )
        aURL += rtl::OUString::createFromAscii( "/" );

    aURL += aName;
    return aURL;
}
<commit_msg>INTEGRATION: CWS changefileheader (1.6.72); FILE MERGED 2008/03/31 15:30:27 rt 1.6.72.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: tdoc_datasupplier.cxx,v $
 * $Revision: 1.7 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_ucb.hxx"

/**************************************************************************
                                TODO
 **************************************************************************

 *************************************************************************/

#include <vector>

#include "osl/diagnose.h"
#include "ucbhelper/contentidentifier.hxx"

#include "tdoc_datasupplier.hxx"
#include "tdoc_content.hxx"

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

namespace tdoc_ucp
{

//=========================================================================
//
// struct ResultListEntry.
//
//=========================================================================

struct ResultListEntry
{
    rtl::OUString                             aURL;
    uno::Reference< ucb::XContentIdentifier > xId;
    uno::Reference< ucb::XContent >           xContent;
    uno::Reference< sdbc::XRow >              xRow;

    ResultListEntry( const rtl::OUString& rURL ) : aURL( rURL ) {}
};

//=========================================================================
//
// ResultList.
//
//=========================================================================

typedef std::vector< ResultListEntry* > ResultList;

//=========================================================================
//
// struct DataSupplier_Impl.
//
//=========================================================================

struct DataSupplier_Impl
{
    osl::Mutex                                   m_aMutex;
    ResultList                                   m_aResults;
    rtl::Reference< Content >                    m_xContent;
    uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
    uno::Sequence< rtl::OUString > *             m_pNamesOfChildren;
    sal_Int32                                    m_nOpenMode;
    bool                                         m_bCountFinal;
    bool                                         m_bThrowException;

    DataSupplier_Impl(
            const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
            const rtl::Reference< Content >& rContent,
            sal_Int32 nOpenMode )
    : m_xContent( rContent ), m_xSMgr( rxSMgr ),
      m_pNamesOfChildren( 0 ), m_nOpenMode( nOpenMode ),
      m_bCountFinal( false ), m_bThrowException( false )
    {}
    ~DataSupplier_Impl();
};

//=========================================================================
DataSupplier_Impl::~DataSupplier_Impl()
{
    ResultList::const_iterator it  = m_aResults.begin();
    ResultList::const_iterator end = m_aResults.end();

    while ( it != end )
    {
        delete (*it);
        it++;
    }

    delete m_pNamesOfChildren;
}

}

//=========================================================================
//=========================================================================
//
// DataSupplier Implementation.
//
//=========================================================================
//=========================================================================

ResultSetDataSupplier::ResultSetDataSupplier(
                const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
                const rtl::Reference< Content >& rContent,
                sal_Int32 nOpenMode )
: m_pImpl( new DataSupplier_Impl( rxSMgr, rContent, nOpenMode ) )
{
}

//=========================================================================
// virtual
ResultSetDataSupplier::~ResultSetDataSupplier()
{
    delete m_pImpl;
}

//=========================================================================
// virtual
rtl::OUString
ResultSetDataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( nIndex < m_pImpl->m_aResults.size() )
    {
        rtl::OUString aId = m_pImpl->m_aResults[ nIndex ]->aURL;
        if ( aId.getLength() )
        {
            // Already cached.
            return aId;
        }
    }

    if ( getResult( nIndex ) )
    {
        // Note: getResult fills m_pImpl->m_aResults[ nIndex ]->aURL.
        return m_pImpl->m_aResults[ nIndex ]->aURL;
    }
    return rtl::OUString();
}

//=========================================================================
// virtual
uno::Reference< ucb::XContentIdentifier >
ResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( nIndex < m_pImpl->m_aResults.size() )
    {
        uno::Reference< ucb::XContentIdentifier > xId
                                = m_pImpl->m_aResults[ nIndex ]->xId;
        if ( xId.is() )
        {
            // Already cached.
            return xId;
        }
    }

    rtl::OUString aId = queryContentIdentifierString( nIndex );
    if ( aId.getLength() )
    {
        uno::Reference< ucb::XContentIdentifier > xId
            = new ::ucbhelper::ContentIdentifier( aId );
        m_pImpl->m_aResults[ nIndex ]->xId = xId;
        return xId;
    }
    return uno::Reference< ucb::XContentIdentifier >();
}

//=========================================================================
// virtual
uno::Reference< ucb::XContent >
ResultSetDataSupplier::queryContent( sal_uInt32 nIndex )
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( nIndex < m_pImpl->m_aResults.size() )
    {
        uno::Reference< ucb::XContent > xContent
                                = m_pImpl->m_aResults[ nIndex ]->xContent;
        if ( xContent.is() )
        {
            // Already cached.
            return xContent;
        }
    }

    uno::Reference< ucb::XContentIdentifier > xId
        = queryContentIdentifier( nIndex );
    if ( xId.is() )
    {
        try
        {
            uno::Reference< ucb::XContent > xContent
                = m_pImpl->m_xContent->getProvider()->queryContent( xId );
            m_pImpl->m_aResults[ nIndex ]->xContent = xContent;
            return xContent;

        }
        catch ( ucb::IllegalIdentifierException const & )
        {
        }
    }
    return uno::Reference< ucb::XContent >();
}

//=========================================================================
// virtual
sal_Bool ResultSetDataSupplier::getResult( sal_uInt32 nIndex )
{
    osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( m_pImpl->m_aResults.size() > nIndex )
    {
        // Result already present.
        return sal_True;
    }

    // Result not (yet) present.

    if ( m_pImpl->m_bCountFinal )
        return sal_False;

    // Try to obtain result...

    sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
    bool bFound = false;

    if ( queryNamesOfChildren() )
    {
        for ( sal_uInt32 n = nOldCount;
              n < sal::static_int_cast<sal_uInt32>(
                      m_pImpl->m_pNamesOfChildren->getLength());
              ++n )
        {
            const rtl::OUString & rName
                = m_pImpl->m_pNamesOfChildren->getConstArray()[ n ];

            if ( !rName.getLength() )
            {
                OSL_ENSURE( sal_False,
                            "ResultDataSupplier::getResult - Empty name!" );
                break;
            }

            // Assemble URL for child.
            rtl::OUString aURL = assembleChildURL( rName );

            m_pImpl->m_aResults.push_back( new ResultListEntry( aURL ) );

            if ( n == nIndex )
            {
                // Result obtained.
                bFound = true;
                break;
            }
        }
    }

    if ( !bFound )
        m_pImpl->m_bCountFinal = sal_True;

    rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
    if ( xResultSet.is() )
    {
        // Callbacks follow!
        aGuard.clear();

        if ( nOldCount < m_pImpl->m_aResults.size() )
            xResultSet->rowCountChanged( nOldCount, m_pImpl->m_aResults.size() );

        if ( m_pImpl->m_bCountFinal )
            xResultSet->rowCountFinal();
    }

    return bFound;
}

//=========================================================================
// virtual
sal_uInt32 ResultSetDataSupplier::totalCount()
{
    osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( m_pImpl->m_bCountFinal )
        return m_pImpl->m_aResults.size();

    sal_uInt32 nOldCount = m_pImpl->m_aResults.size();

    if ( queryNamesOfChildren() )
    {
        for ( sal_uInt32 n = nOldCount;
              n < sal::static_int_cast<sal_uInt32>(
                      m_pImpl->m_pNamesOfChildren->getLength());
              ++n )
        {
            const rtl::OUString & rName
                = m_pImpl->m_pNamesOfChildren->getConstArray()[ n ];

            if ( !rName.getLength() )
            {
                OSL_ENSURE( sal_False,
                            "ResultDataSupplier::getResult - Empty name!" );
                break;
            }

            // Assemble URL for child.
            rtl::OUString aURL = assembleChildURL( rName );

            m_pImpl->m_aResults.push_back( new ResultListEntry( aURL ) );
        }
    }

    m_pImpl->m_bCountFinal = sal_True;

    rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
    if ( xResultSet.is() )
    {
        // Callbacks follow!
        aGuard.clear();

        if ( nOldCount < m_pImpl->m_aResults.size() )
            xResultSet->rowCountChanged( nOldCount, m_pImpl->m_aResults.size() );

        xResultSet->rowCountFinal();
    }

    return m_pImpl->m_aResults.size();
}

//=========================================================================
// virtual
sal_uInt32 ResultSetDataSupplier::currentCount()
{
    return m_pImpl->m_aResults.size();
}

//=========================================================================
// virtual
sal_Bool ResultSetDataSupplier::isCountFinal()
{
    return m_pImpl->m_bCountFinal;
}

//=========================================================================
// virtual
uno::Reference< sdbc::XRow >
ResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex  )
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( nIndex < m_pImpl->m_aResults.size() )
    {
        uno::Reference< sdbc::XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow;
        if ( xRow.is() )
        {
            // Already cached.
            return xRow;
        }
    }

    if ( getResult( nIndex ) )
    {
        uno::Reference< sdbc::XRow > xRow = Content::getPropertyValues(
                        m_pImpl->m_xSMgr,
                        getResultSet()->getProperties(),
                        m_pImpl->m_xContent->getContentProvider().get(),
                        queryContentIdentifierString( nIndex ) );
        m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
        return xRow;
    }

    return uno::Reference< sdbc::XRow >();
}

//=========================================================================
// virtual
void ResultSetDataSupplier::releasePropertyValues( sal_uInt32 nIndex )
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( nIndex < m_pImpl->m_aResults.size() )
        m_pImpl->m_aResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
}

//=========================================================================
// virtual
void ResultSetDataSupplier::close()
{
}

//=========================================================================
// virtual
void ResultSetDataSupplier::validate()
    throw( ucb::ResultSetException )
{
    if ( m_pImpl->m_bThrowException )
        throw ucb::ResultSetException();
}

//=========================================================================
bool ResultSetDataSupplier::queryNamesOfChildren()
{
    osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );

    if ( m_pImpl->m_pNamesOfChildren == 0 )
    {
        uno::Sequence< rtl::OUString > * pNamesOfChildren
            = new uno::Sequence< rtl::OUString >();

        if ( !m_pImpl->m_xContent->getContentProvider()->queryNamesOfChildren(
                m_pImpl->m_xContent->getIdentifier()->getContentIdentifier(),
                *pNamesOfChildren ) )
        {
            OSL_ENSURE( false, "Got no list of children!" );
            m_pImpl->m_bThrowException = sal_True;
            return false;
        }
        else
        {
            m_pImpl->m_pNamesOfChildren = pNamesOfChildren;
        }
    }
    return true;
}

//=========================================================================
::rtl::OUString
ResultSetDataSupplier::assembleChildURL( const ::rtl::OUString& aName )
{
    rtl::OUString aContURL
        = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier();
    rtl::OUString aURL( aContURL );

    sal_Int32 nUrlEnd = aURL.lastIndexOf( '/' );
    if ( nUrlEnd != aURL.getLength() - 1 )
        aURL += rtl::OUString::createFromAscii( "/" );

    aURL += aName;
    return aURL;
}
<|endoftext|>


<commit_before>#ifndef KEYEVENTINPUTQUEUE_HPP
#define KEYEVENTINPUTQUEUE_HPP

#include "base.hpp"
#include "IntervalChecker.hpp"
#include "KeyCode.hpp"
#include "TimerWrapper.hpp"

namespace org_pqrs_KeyRemap4MacBook {
  class KeyEventInputQueue {
  public:
    class Remap;
    friend class Remap;

    static void initialize(IOWorkLoop& workloop);
    static void terminate(void);

    static void add(OSObject* target,
                    EventType eventType,
                    Flags flags,
                    KeyCode key,
                    CharCode charCode,
                    CharSet charSet,
                    OrigCharCode origCharCode,
                    OrigCharSet origCharSet,
                    KeyboardType keyboardType,
                    bool repeat,
                    AbsoluteTime ts,
                    OSObject* sender,
                    void* refcon);

    struct Item {
      OSObject* target;
      EventType eventType;
      Flags flags;
      KeyCode key;
      CharCode charCode;
      CharSet charSet;
      OrigCharCode origCharCode;
      OrigCharSet origCharSet;
      KeyboardType keyboardType;
      bool repeat;
      AbsoluteTime ts;
      OSObject* sender;
      void* refcon;

      bool active;
      bool dropped;
      bool isremapped;
      UInt32 delayMS;
    };

    class Remap {
    public:
      Remap(void) : active1_(false), active2_(false) {}
      void push(Item* base, KeyCode key);

      void remap(KeyCode fromKeyCode1, KeyCode fromKeyCode2, KeyCode toKeyCode1, KeyCode toKeyCode2, KeyCode toKeyCode3, KeyCode toKeyCode4, KeyCode toKeyCode5);
      void remap(KeyCode fromKeyCode1, KeyCode fromKeyCode2, KeyCode toKeyCode1, KeyCode toKeyCode2, KeyCode toKeyCode3, KeyCode toKeyCode4) {
        remap(fromKeyCode1, fromKeyCode2, toKeyCode1, toKeyCode2, toKeyCode3, toKeyCode4, KeyCode::VK_NONE);
      }
      void remap(KeyCode fromKeyCode1, KeyCode fromKeyCode2, KeyCode toKeyCode1, KeyCode toKeyCode2, KeyCode toKeyCode3) {
        remap(fromKeyCode1, fromKeyCode2, toKeyCode1, toKeyCode2, toKeyCode3, KeyCode::VK_NONE);
      }
      void remap(KeyCode fromKeyCode1, KeyCode fromKeyCode2, KeyCode toKeyCode1, KeyCode toKeyCode2) {
        remap(fromKeyCode1, fromKeyCode2, toKeyCode1, toKeyCode2, KeyCode::VK_NONE);
      }
      void remap(KeyCode fromKeyCode1, KeyCode fromKeyCode2, KeyCode toKeyCode1) {
        remap(fromKeyCode1, fromKeyCode2, toKeyCode1, KeyCode::VK_NONE);
      }

    private:
      bool active1_;
      bool active2_;
    };

  private:
    enum {
      MAXNUM = 64,
    };

    static Item* enqueue_(OSObject* target,
                          EventType eventType,
                          Flags flags,
                          KeyCode key,
                          CharCode charCode,
                          CharSet charSet,
                          OrigCharCode origCharCode,
                          OrigCharSet origCharSet,
                          KeyboardType keyboardType,
                          bool repeat,
                          AbsoluteTime ts,
                          OSObject* sender,
                          void* refcon);

    static void fire(OSObject* owner, IOTimerEventSource* sender);
    static void fire_nolock(void);
    static Item* getnext(Item* p) {
      if (p >= item_ + (MAXNUM - 1)) {
        return item_;
      } else {
        return p + 1;
      }
    }

    static Item item_[MAXNUM];
    static IntervalChecker ic_;
    static Item* current_;
    static Item* last_;
    static TimerWrapper timer_;
    static bool isTimerActive_;
  };
}

#endif
<commit_msg>cleanup KeyEventInputQueue.hpp<commit_after>#ifndef KEYEVENTINPUTQUEUE_HPP
#define KEYEVENTINPUTQUEUE_HPP

#include "base.hpp"
#include "IntervalChecker.hpp"
#include "KeyCode.hpp"
#include "TimerWrapper.hpp"

namespace org_pqrs_KeyRemap4MacBook {
  class KeyEventInputQueue {
  public:
    static void initialize(IOWorkLoop& workloop);
    static void terminate(void);

    static void add(OSObject* target,
                    EventType eventType,
                    Flags flags,
                    KeyCode key,
                    CharCode charCode,
                    CharSet charSet,
                    OrigCharCode origCharCode,
                    OrigCharSet origCharSet,
                    KeyboardType keyboardType,
                    bool repeat,
                    AbsoluteTime ts,
                    OSObject* sender,
                    void* refcon);

    struct Item {
      OSObject* target;
      EventType eventType;
      Flags flags;
      KeyCode key;
      CharCode charCode;
      CharSet charSet;
      OrigCharCode origCharCode;
      OrigCharSet origCharSet;
      KeyboardType keyboardType;
      bool repeat;
      AbsoluteTime ts;
      OSObject* sender;
      void* refcon;

      bool active;
      bool dropped;
      bool isremapped;
      UInt32 delayMS;
    };

    class Remap {
    public:
      Remap(void) : active1_(false), active2_(false) {}
      void push(Item* base, KeyCode key);

      void remap(KeyCode fromKeyCode1, KeyCode fromKeyCode2, KeyCode toKeyCode1, KeyCode toKeyCode2, KeyCode toKeyCode3, KeyCode toKeyCode4, KeyCode toKeyCode5);
      void remap(KeyCode fromKeyCode1, KeyCode fromKeyCode2, KeyCode toKeyCode1, KeyCode toKeyCode2, KeyCode toKeyCode3, KeyCode toKeyCode4) {
        remap(fromKeyCode1, fromKeyCode2, toKeyCode1, toKeyCode2, toKeyCode3, toKeyCode4, KeyCode::VK_NONE);
      }
      void remap(KeyCode fromKeyCode1, KeyCode fromKeyCode2, KeyCode toKeyCode1, KeyCode toKeyCode2, KeyCode toKeyCode3) {
        remap(fromKeyCode1, fromKeyCode2, toKeyCode1, toKeyCode2, toKeyCode3, KeyCode::VK_NONE);
      }
      void remap(KeyCode fromKeyCode1, KeyCode fromKeyCode2, KeyCode toKeyCode1, KeyCode toKeyCode2) {
        remap(fromKeyCode1, fromKeyCode2, toKeyCode1, toKeyCode2, KeyCode::VK_NONE);
      }
      void remap(KeyCode fromKeyCode1, KeyCode fromKeyCode2, KeyCode toKeyCode1) {
        remap(fromKeyCode1, fromKeyCode2, toKeyCode1, KeyCode::VK_NONE);
      }

    private:
      bool active1_;
      bool active2_;
    };

  private:
    enum {
      MAXNUM = 64,
    };

    static Item* enqueue_(OSObject* target,
                          EventType eventType,
                          Flags flags,
                          KeyCode key,
                          CharCode charCode,
                          CharSet charSet,
                          OrigCharCode origCharCode,
                          OrigCharSet origCharSet,
                          KeyboardType keyboardType,
                          bool repeat,
                          AbsoluteTime ts,
                          OSObject* sender,
                          void* refcon);

    static void fire(OSObject* owner, IOTimerEventSource* sender);
    static void fire_nolock(void);
    static Item* getnext(Item* p) {
      if (p >= item_ + (MAXNUM - 1)) {
        return item_;
      } else {
        return p + 1;
      }
    }

    static Item item_[MAXNUM];
    static IntervalChecker ic_;
    static Item* current_;
    static Item* last_;
    static TimerWrapper timer_;
    static bool isTimerActive_;
  };
}

#endif
<|endoftext|>


<commit_before>/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * 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
 * OpenSceneGraph Public License for more details.
 */

#include <osg/GLExtensions>
#include <osg/GL>
#include <osg/PointSprite>
#include <osg/Point>
#include <osg/State>
#include <osg/buffered_value>
#include <osg/Notify>

using namespace osg;

PointSprite::PointSprite()
    : _coordOriginMode(UPPER_LEFT)
{
}

PointSprite::~PointSprite()
{
}

int PointSprite::compare(const StateAttribute& sa) const
{
    COMPARE_StateAttribute_Types(PointSprite,sa)

    COMPARE_StateAttribute_Parameter(_coordOriginMode)

    return 0; // passed all the above comparison macros, must be equal.
}

bool PointSprite::checkValidityOfAssociatedModes(osg::State& state) const
{

    bool modeValid = isPointSpriteSupported(state.getContextID());
    state.setModeValidity(GL_POINT_SPRITE_ARB, modeValid);

    return modeValid;
}

void PointSprite::apply(osg::State& state) const
{
#if defined( OSG_GL3_AVAILABLE )
    const Point::Extensions* extensions = Point::getExtensions(state.getContextID(),true);
    extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,_coordOriginMode);
#elif defined( OSG_GL_FIXED_FUNCTION_AVAILABLE )
    if(!isPointSpriteSupported(state.getContextID())) return;

    glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, 1);

    const Point::Extensions* extensions = Point::getExtensions(state.getContextID(),true);

    if (extensions->isPointSpriteCoordOriginSupported())
        extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,_coordOriginMode);
#else
    OSG_NOTICE<<"Warning: PointSprite::apply(State&) - not supported."<<std::endl;
#endif
}

struct IntializedSupportedPair
{
    IntializedSupportedPair():
        initialized(false),
        supported(false) {}

    bool initialized;
    bool supported;
};

typedef osg::buffered_object< IntializedSupportedPair > BufferedExtensions;
static BufferedExtensions s_extensions;

bool PointSprite::isPointSpriteSupported(unsigned int contextID)
{
    if (!s_extensions[contextID].initialized)
    {
        s_extensions[contextID].initialized = true;
        s_extensions[contextID].supported = OSG_GL3_FEATURES || isGLExtensionSupported(contextID, "GL_ARB_point_sprite") || isGLExtensionSupported(contextID, "GL_NV_point_sprite");
    }

    return s_extensions[contextID].supported;
}
<commit_msg>From Colin Cochran, OES support for point sprites<commit_after>/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * 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
 * OpenSceneGraph Public License for more details.
 */

#include <osg/GLExtensions>
#include <osg/GL>
#include <osg/PointSprite>
#include <osg/Point>
#include <osg/State>
#include <osg/buffered_value>
#include <osg/Notify>

using namespace osg;

PointSprite::PointSprite()
    : _coordOriginMode(UPPER_LEFT)
{
}

PointSprite::~PointSprite()
{
}

int PointSprite::compare(const StateAttribute& sa) const
{
    COMPARE_StateAttribute_Types(PointSprite,sa)

    COMPARE_StateAttribute_Parameter(_coordOriginMode)

    return 0; // passed all the above comparison macros, must be equal.
}

bool PointSprite::checkValidityOfAssociatedModes(osg::State& state) const
{

    bool modeValid = isPointSpriteSupported(state.getContextID());

#if defined( OSG_GLES1_AVAILABLE ) || defined( OSG_GLES2_AVAILABLE )
    state.setModeValidity(GL_POINT_SPRITE_OES, modeValid);
#else
    state.setModeValidity(GL_POINT_SPRITE_ARB, modeValid);
#endif

    return modeValid;
}

void PointSprite::apply(osg::State& state) const
{
#if defined( OSG_GL3_AVAILABLE )

    const Point::Extensions* extensions = Point::getExtensions(state.getContextID(),true);
    extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,_coordOriginMode);

#elif defined( OSG_GLES1_AVAILABLE ) || defined( OSG_GLES2_AVAILABLE )

    if(!isPointSpriteSupported(state.getContextID())) return;

    glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, 1);

#elif defined( OSG_GL_FIXED_FUNCTION_AVAILABLE )

    if(!isPointSpriteSupported(state.getContextID())) return;

    glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, 1);

    const Point::Extensions* extensions = Point::getExtensions(state.getContextID(),true);

    if (extensions->isPointSpriteCoordOriginSupported())
        extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,_coordOriginMode);

#else
    OSG_NOTICE<<"Warning: PointSprite::apply(State&) - not supported."<<std::endl;

#endif
}

struct IntializedSupportedPair
{
    IntializedSupportedPair():
        initialized(false),
        supported(false) {}

    bool initialized;
    bool supported;
};

typedef osg::buffered_object< IntializedSupportedPair > BufferedExtensions;
static BufferedExtensions s_extensions;

bool PointSprite::isPointSpriteSupported(unsigned int contextID)
{
    if (!s_extensions[contextID].initialized)
    {
        s_extensions[contextID].initialized = true;
        s_extensions[contextID].supported = OSG_GL3_FEATURES || isGLExtensionSupported(contextID, "GL_ARB_point_sprite") || isGLExtensionSupported(contextID, "GL_OES_point_sprite") || isGLExtensionSupported(contextID, "GL_NV_point_sprite");
    }

    return s_extensions[contextID].supported;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: webdavresultset.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 16:17:20 $
 *
 *  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
 *
 ************************************************************************/

/**************************************************************************
                                TODO
 **************************************************************************

 - This implementation is not a dynamic result set!!! It only implements
   the necessary interfaces, but never recognizes/notifies changes!!!

 *************************************************************************/

#ifndef _WEBDAV_UCP_RESULTSET_HXX
#include "webdavresultset.hxx"
#endif
#ifndef _WEBDAV_SESSION_HXX
#include "DAVSession.hxx"
#endif

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

//=========================================================================
//=========================================================================
//
// DynamicResultSet Implementation.
//
//=========================================================================
//=========================================================================

DynamicResultSet::DynamicResultSet(
                const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
                const rtl::Reference< Content >& rxContent,
                const com::sun::star::ucb::OpenCommandArgument2& rCommand,
                const uno::Reference<
                    com::sun::star::ucb::XCommandEnvironment >& rxEnv )
: ResultSetImplHelper( rxSMgr, rCommand ),
  m_xContent( rxContent ),
  m_xEnv( rxEnv )
{
}

//=========================================================================
//
// Non-interface methods.
//
//=========================================================================

void DynamicResultSet::initStatic()
{
    m_xResultSet1
        = new ::ucb::ResultSet( m_xSMgr,
                                m_aCommand.Properties,
                                new DataSupplier( m_xSMgr,
                                                  m_xContent,
                                                  m_aCommand.Mode ),
                                m_xEnv );
}

//=========================================================================
void DynamicResultSet::initDynamic()
{
    m_xResultSet1
        = new ::ucb::ResultSet( m_xSMgr,
                                m_aCommand.Properties,
                                new DataSupplier( m_xSMgr,
                                                  m_xContent,
                                                  m_aCommand.Mode ),
                                m_xEnv );
    m_xResultSet2 = m_xResultSet1;
}

<commit_msg>INTEGRATION: CWS pchfix02 (1.4.70); FILE MERGED 2006/09/01 17:55:55 kaib 1.4.70.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: webdavresultset.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 14:08:41 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_ucb.hxx"

/**************************************************************************
                                TODO
 **************************************************************************

 - This implementation is not a dynamic result set!!! It only implements
   the necessary interfaces, but never recognizes/notifies changes!!!

 *************************************************************************/

#ifndef _WEBDAV_UCP_RESULTSET_HXX
#include "webdavresultset.hxx"
#endif
#ifndef _WEBDAV_SESSION_HXX
#include "DAVSession.hxx"
#endif

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

//=========================================================================
//=========================================================================
//
// DynamicResultSet Implementation.
//
//=========================================================================
//=========================================================================

DynamicResultSet::DynamicResultSet(
                const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
                const rtl::Reference< Content >& rxContent,
                const com::sun::star::ucb::OpenCommandArgument2& rCommand,
                const uno::Reference<
                    com::sun::star::ucb::XCommandEnvironment >& rxEnv )
: ResultSetImplHelper( rxSMgr, rCommand ),
  m_xContent( rxContent ),
  m_xEnv( rxEnv )
{
}

//=========================================================================
//
// Non-interface methods.
//
//=========================================================================

void DynamicResultSet::initStatic()
{
    m_xResultSet1
        = new ::ucb::ResultSet( m_xSMgr,
                                m_aCommand.Properties,
                                new DataSupplier( m_xSMgr,
                                                  m_xContent,
                                                  m_aCommand.Mode ),
                                m_xEnv );
}

//=========================================================================
void DynamicResultSet::initDynamic()
{
    m_xResultSet1
        = new ::ucb::ResultSet( m_xSMgr,
                                m_aCommand.Properties,
                                new DataSupplier( m_xSMgr,
                                                  m_xContent,
                                                  m_aCommand.Mode ),
                                m_xEnv );
    m_xResultSet2 = m_xResultSet1;
}

<|endoftext|>


<commit_before>//
//  Logging.cpp
//  ChilliSource
//  Created by Scott Downie on 18/10/2010.
//
//  The MIT License (MIT)
//
//  Copyright (c) 2010 Tag Games Limited
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//

#include <ChilliSource/Core/Base/Logging.h>

#include <ChilliSource/Core/Base/Application.h>
#include <ChilliSource/Core/File/FileSystem.h>

#include <iostream>

#ifdef CS_TARGETPLATFORM_ANDROID
#include <android/log.h>
#include <cstdlib>
extern "C"
{
#define CS_ANDROID_LOG_VERBOSE(...) __android_log_print(ANDROID_LOG_DEBUG, "ChilliSource", "%s", __VA_ARGS__)
#define CS_ANDROID_LOG_WARNING(...) __android_log_print(ANDROID_LOG_WARN, "ChilliSource", "%s", __VA_ARGS__)
#define CS_ANDROID_LOG_ERROR(...) __android_log_print(ANDROID_LOG_ERROR, "ChilliSource", "%s", __VA_ARGS__)
}
#endif

#ifdef CS_TARGETPLATFORM_WINDOWS
#include <CSBackend/Platform/Windows/Core/String/WindowsStringUtils.h>
#include <Windows.h>
#endif

#ifdef CS_TARGETPLATFORM_IOS
#include <Foundation/NSThread.h>
#endif

#ifdef CS_ENABLE_DEBUG
#include <cassert>
#endif

#if CS_TARGETPLATFORM_IOS
#import <Foundation/Foundation.h>
#include <CSBackend/Platform/iOS/Core/String/NSStringUtils.h>
#endif

namespace ChilliSource
{
    namespace
    {
#ifdef CS_ENABLE_LOGTOFILE
        const u32 k_maxLogBufferSize = 2048;
        const std::string k_logFileName = "ChilliSourceLog.txt";
#endif
    }

    Logging* Logging::s_logging = nullptr;
    //-----------------------------------------------
    //-----------------------------------------------
    void Logging::Create()
    {
#ifdef CS_ENABLE_DEBUG
        assert(s_logging == nullptr);
#endif
        s_logging = new Logging();
    }
    //-----------------------------------------------
    //-----------------------------------------------
    Logging* Logging::Get()
    {
#ifdef CS_ENABLE_DEBUG
        assert(s_logging != nullptr);
#endif
        return s_logging;
    }
    //----------------------------------------------
    //----------------------------------------------
    Logging::Logging()
#ifdef CS_ENABLE_LOGTOFILE
        : m_isFirstLog(true)
#endif
    {
    }
    //----------------------------------------------
    //----------------------------------------------
    void Logging::LogVerbose(const std::string &in_message)
    {
#if defined CS_LOGLEVEL_VERBOSE
        LogMessage(LogLevel::k_verbose, in_message);
#endif
    }
    //----------------------------------------------
    //----------------------------------------------
    void Logging::LogWarning(const std::string &in_message)
    {
#if defined CS_LOGLEVEL_VERBOSE || defined CS_LOGLEVEL_WARNING
        LogMessage(LogLevel::k_warning, "WARNING: " + in_message);
#endif
    }
    //----------------------------------------------
    //----------------------------------------------
    void Logging::LogError(const std::string &in_message)
    {
#if defined CS_LOGLEVEL_VERBOSE || defined CS_LOGLEVEL_WARNING || defined CS_LOGLEVEL_ERROR
        LogMessage(LogLevel::k_error, "ERROR: " + in_message);
#endif
    }
    //----------------------------------------------
    //----------------------------------------------
    void Logging::LogFatal(const std::string &in_message)
    {
#if defined CS_LOGLEVEL_VERBOSE || defined CS_LOGLEVEL_WARNING || defined CS_LOGLEVEL_ERROR || defined CS_LOGLEVEL_FATAL
        LogMessage(LogLevel::k_error, "FATAL: " + in_message);
        LogMessage(LogLevel::k_error, "ChilliSource is exiting...");
#endif

#ifdef CS_TARGETPLATFORM_ANDROID
        exit(1);
#else
#ifdef CS_ENABLE_DEBUG
        assert(false);
#else
        abort();
#endif
#endif
    }
    //-----------------------------------------------------
    //-----------------------------------------------------
    void Logging::Destroy()
    {
        CS_SAFEDELETE(s_logging);
    }
    //-----------------------------------------------------
    //-----------------------------------------------------
    void Logging::LogMessage(LogLevel in_logLevel, const std::string& in_message)
    {

        //TODO:RPI

#ifdef CS_TARGETPLATFORM_ANDROID
        switch (in_logLevel)
        {
            case LogLevel::k_verbose:
                CS_ANDROID_LOG_VERBOSE(in_message.c_str());
                break;
            case LogLevel::k_warning:
                CS_ANDROID_LOG_WARNING(in_message.c_str());
                break;
            case LogLevel::k_error:
                CS_ANDROID_LOG_ERROR(in_message.c_str());
                break;

        }
#elif defined (CS_TARGETPLATFORM_IOS)
        NSString* message = [NSStringUtils newNSStringWithUTF8String:in_message];
        NSLog(@"[ChilliSource] %@", message);
        [message release];
#elif defined (CS_TARGETPLATFORM_WINDOWS)
        OutputDebugString(CSBackend::Windows::WindowsStringUtils::UTF8ToUTF16("[ChilliSource] " + in_message + "\n").c_str());
#endif

#ifdef CS_ENABLE_LOGTOFILE
        LogToFile(in_message);
#endif
    }

#ifdef CS_ENABLE_LOGTOFILE
    //-----------------------------------------------
    //-----------------------------------------------
    void Logging::CreateLogFile()
    {
        FileStreamUPtr stream = Application::Get()->GetFileSystem()->CreateFileStream(StorageLocation::k_cache, k_logFileName, FileMode::k_write);
        stream->Write("ChilliSource Log");
    }
    //-----------------------------------------------
    //-----------------------------------------------
    void Logging::LogToFile(const std::string& in_message)
    {
        std::unique_lock<std::mutex> lock(m_mutex);
        m_logBuffer += "\n" + in_message;

        FileSystem* fileSystem = Application::Get()->GetFileSystem();
        if(fileSystem != nullptr && m_logBuffer.length() > k_maxLogBufferSize)
        {
            if (m_isFirstLog == true)
            {
                FileStreamUPtr stream = Application::Get()->GetFileSystem()->CreateFileStream(StorageLocation::k_cache, k_logFileName, FileMode::k_write);
                stream->Write("ChilliSource Log");
                stream->Write(m_logBuffer);
                m_logBuffer.clear();
                m_isFirstLog = false;
            }
            else
            {
                FileStreamUPtr stream = Application::Get()->GetFileSystem()->CreateFileStream(StorageLocation::k_cache, k_logFileName, FileMode::k_writeAppend);
                stream->Write(m_logBuffer);
                m_logBuffer.clear();
            }
        }
    }
#endif
}
<commit_msg>Logging out to standard io on RPi<commit_after>//
//  Logging.cpp
//  ChilliSource
//  Created by Scott Downie on 18/10/2010.
//
//  The MIT License (MIT)
//
//  Copyright (c) 2010 Tag Games Limited
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//

#include <ChilliSource/Core/Base/Logging.h>

#include <ChilliSource/Core/Base/Application.h>
#include <ChilliSource/Core/File/FileSystem.h>

#include <iostream>

#ifdef CS_TARGETPLATFORM_ANDROID
#include <android/log.h>
#include <cstdlib>
extern "C"
{
#define CS_ANDROID_LOG_VERBOSE(...) __android_log_print(ANDROID_LOG_DEBUG, "ChilliSource", "%s", __VA_ARGS__)
#define CS_ANDROID_LOG_WARNING(...) __android_log_print(ANDROID_LOG_WARN, "ChilliSource", "%s", __VA_ARGS__)
#define CS_ANDROID_LOG_ERROR(...) __android_log_print(ANDROID_LOG_ERROR, "ChilliSource", "%s", __VA_ARGS__)
}
#endif

#ifdef CS_TARGETPLATFORM_WINDOWS
#include <CSBackend/Platform/Windows/Core/String/WindowsStringUtils.h>
#include <Windows.h>
#endif

#ifdef CS_TARGETPLATFORM_IOS
#include <Foundation/NSThread.h>
#endif

#ifdef CS_ENABLE_DEBUG
#include <cassert>
#endif

#if CS_TARGETPLATFORM_IOS
#import <Foundation/Foundation.h>
#include <CSBackend/Platform/iOS/Core/String/NSStringUtils.h>
#endif

namespace ChilliSource
{
    namespace
    {
#ifdef CS_ENABLE_LOGTOFILE
        const u32 k_maxLogBufferSize = 2048;
        const std::string k_logFileName = "ChilliSourceLog.txt";
#endif
    }

    Logging* Logging::s_logging = nullptr;
    //-----------------------------------------------
    //-----------------------------------------------
    void Logging::Create()
    {
#ifdef CS_ENABLE_DEBUG
        assert(s_logging == nullptr);
#endif
        s_logging = new Logging();
    }
    //-----------------------------------------------
    //-----------------------------------------------
    Logging* Logging::Get()
    {
#ifdef CS_ENABLE_DEBUG
        assert(s_logging != nullptr);
#endif
        return s_logging;
    }
    //----------------------------------------------
    //----------------------------------------------
    Logging::Logging()
#ifdef CS_ENABLE_LOGTOFILE
        : m_isFirstLog(true)
#endif
    {
    }
    //----------------------------------------------
    //----------------------------------------------
    void Logging::LogVerbose(const std::string &in_message)
    {
#if defined CS_LOGLEVEL_VERBOSE
        LogMessage(LogLevel::k_verbose, in_message);
#endif
    }
    //----------------------------------------------
    //----------------------------------------------
    void Logging::LogWarning(const std::string &in_message)
    {
#if defined CS_LOGLEVEL_VERBOSE || defined CS_LOGLEVEL_WARNING
        LogMessage(LogLevel::k_warning, "WARNING: " + in_message);
#endif
    }
    //----------------------------------------------
    //----------------------------------------------
    void Logging::LogError(const std::string &in_message)
    {
#if defined CS_LOGLEVEL_VERBOSE || defined CS_LOGLEVEL_WARNING || defined CS_LOGLEVEL_ERROR
        LogMessage(LogLevel::k_error, "ERROR: " + in_message);
#endif
    }
    //----------------------------------------------
    //----------------------------------------------
    void Logging::LogFatal(const std::string &in_message)
    {
#if defined CS_LOGLEVEL_VERBOSE || defined CS_LOGLEVEL_WARNING || defined CS_LOGLEVEL_ERROR || defined CS_LOGLEVEL_FATAL
        LogMessage(LogLevel::k_error, "FATAL: " + in_message);
        LogMessage(LogLevel::k_error, "ChilliSource is exiting...");
#endif

#ifdef CS_TARGETPLATFORM_ANDROID
        exit(1);
#else
#ifdef CS_ENABLE_DEBUG
        assert(false);
#else
        abort();
#endif
#endif
    }
    //-----------------------------------------------------
    //-----------------------------------------------------
    void Logging::Destroy()
    {
        CS_SAFEDELETE(s_logging);
    }
    //-----------------------------------------------------
    //-----------------------------------------------------
    void Logging::LogMessage(LogLevel in_logLevel, const std::string& in_message)
    {
#ifdef CS_TARGETPLATFORM_ANDROID
        switch (in_logLevel)
        {
            case LogLevel::k_verbose:
                CS_ANDROID_LOG_VERBOSE(in_message.c_str());
                break;
            case LogLevel::k_warning:
                CS_ANDROID_LOG_WARNING(in_message.c_str());
                break;
            case LogLevel::k_error:
                CS_ANDROID_LOG_ERROR(in_message.c_str());
                break;

        }
#elif defined (CS_TARGETPLATFORM_IOS)
        NSString* message = [NSStringUtils newNSStringWithUTF8String:in_message];
        NSLog(@"[ChilliSource] %@", message);
        [message release];
#elif defined (CS_TARGETPLATFORM_WINDOWS)
        OutputDebugString(CSBackend::Windows::WindowsStringUtils::UTF8ToUTF16("[ChilliSource] " + in_message + "\n").c_str());
#elif defined (CS_TARGETPLATFORM_RPI)
        std::cout << "[ChilliSource] " << in_message << std::endl;
#endif

#ifdef CS_ENABLE_LOGTOFILE
        LogToFile(in_message);
#endif
    }

#ifdef CS_ENABLE_LOGTOFILE
    //-----------------------------------------------
    //-----------------------------------------------
    void Logging::CreateLogFile()
    {
        FileStreamUPtr stream = Application::Get()->GetFileSystem()->CreateFileStream(StorageLocation::k_cache, k_logFileName, FileMode::k_write);
        stream->Write("ChilliSource Log");
    }
    //-----------------------------------------------
    //-----------------------------------------------
    void Logging::LogToFile(const std::string& in_message)
    {
        std::unique_lock<std::mutex> lock(m_mutex);
        m_logBuffer += "\n" + in_message;

        FileSystem* fileSystem = Application::Get()->GetFileSystem();
        if(fileSystem != nullptr && m_logBuffer.length() > k_maxLogBufferSize)
        {
            if (m_isFirstLog == true)
            {
                FileStreamUPtr stream = Application::Get()->GetFileSystem()->CreateFileStream(StorageLocation::k_cache, k_logFileName, FileMode::k_write);
                stream->Write("ChilliSource Log");
                stream->Write(m_logBuffer);
                m_logBuffer.clear();
                m_isFirstLog = false;
            }
            else
            {
                FileStreamUPtr stream = Application::Get()->GetFileSystem()->CreateFileStream(StorageLocation::k_cache, k_logFileName, FileMode::k_writeAppend);
                stream->Write(m_logBuffer);
                m_logBuffer.clear();
            }
        }
    }
#endif
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: DriverManager.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: hr $ $Date: 2004-11-09 12:12:30 $
 *
 *  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 _CONNECTIVITY_JAVA_SQL_DRIVERMANAGER_HXX_
#include "java/sql/DriverManager.hxx"
#endif
#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_
#include "java/tools.hxx"
#endif

using namespace connectivity;
//**************************************************************
//************ Class: java.sql.DriverManager
//**************************************************************

jclass java_sql_DriverManager::theClass = 0;

java_sql_DriverManager::~java_sql_DriverManager()
{}

jclass java_sql_DriverManager::getMyClass()
{
    // die Klasse muss nur einmal geholt werden, daher statisch
    if( !theClass ){
        SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment gelscht worden!");
        if( !t.pEnv ) return (jclass)0;
        jclass tempClass = t.pEnv->FindClass("java/sql/DriverManager"); OSL_ENSURE(tempClass,"Java : FindClass nicht erfolgreich!");
        jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass );
        t.pEnv->DeleteLocalRef( tempClass );
        saveClassRef( globClass );
    }
    return theClass;
}

void java_sql_DriverManager::saveClassRef( jclass pClass )
{
    if( pClass==0  )
        return;
    // der uebergebe Klassen-Handle ist schon global, daher einfach speichern
    theClass = pClass;
}

jobject java_sql_DriverManager::getDriver(const ::rtl::OUString &url)
{
    jobject out(0);
    SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment gelscht worden!");
    if( t.pEnv )
    {
        jvalue args[1];
        // Parameter konvertieren
        args[0].l = convertwchar_tToJavaString(t.pEnv,url);
        // temporaere Variable initialisieren
        static char * cSignature = "(Ljava/lang/String;)Ljava/sql/Driver;";
        static char * cMethodName = "getDriver";
        // Java-Call absetzen
        jmethodID mID = t.pEnv->GetStaticMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!");
        if( mID )
        {
            out = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
            // und aufraeumen

        } //mID
        t.pEnv->DeleteLocalRef((jstring)args[0].l);
        return t.pEnv->NewGlobalRef( out );
    } //t.pEnv

    return out;
}

void java_sql_DriverManager::setLoginTimeout(sal_Int32 _par0)
{
    SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment gelscht worden!");
    jobject out(0);
    if( t.pEnv )
    {
        // temporaere Variable initialisieren
        static char * cSignature = "(I)V";
        static char * cMethodName = "setLoginTimeout";
        // Java-Call absetzen
        jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!");
        if( mID )
            t.pEnv->CallStaticVoidMethod(getMyClass(), mID, _par0);
            ThrowSQLException(t.pEnv,0);
    } //t.pEnv
    // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
}

<commit_msg>INTEGRATION: CWS dba22 (1.6.16); FILE MERGED 2005/01/04 11:45:20 oj 1.6.16.1: #i39671# erase guard when no longer needed<commit_after>/*************************************************************************
 *
 *  $RCSfile: DriverManager.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: kz $ $Date: 2005-01-21 16:41:43 $
 *
 *  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 _CONNECTIVITY_JAVA_SQL_DRIVERMANAGER_HXX_
#include "java/sql/DriverManager.hxx"
#endif
#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_
#include "java/tools.hxx"
#endif

using namespace connectivity;
//**************************************************************
//************ Class: java.sql.DriverManager
//**************************************************************

jclass java_sql_DriverManager::theClass = 0;

java_sql_DriverManager::~java_sql_DriverManager()
{}

jclass java_sql_DriverManager::getMyClass()
{
    // die Klasse muss nur einmal geholt werden, daher statisch
    if( !theClass ){
        SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment gelscht worden!");
        if( !t.pEnv ) return (jclass)0;
        jclass tempClass = t.pEnv->FindClass("java/sql/DriverManager"); OSL_ENSURE(tempClass,"Java : FindClass nicht erfolgreich!");
        jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass );
        t.pEnv->DeleteLocalRef( tempClass );
        saveClassRef( globClass );
    }
    return theClass;
}

void java_sql_DriverManager::saveClassRef( jclass pClass )
{
    if( pClass==0  )
        return;
    // der uebergebe Klassen-Handle ist schon global, daher einfach speichern
    theClass = pClass;
}

jobject java_sql_DriverManager::getDriver(const ::rtl::OUString &url)
{
    jobject out(0);
    SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment gelscht worden!");
    if( t.pEnv )
    {
        jvalue args[1];
        // Parameter konvertieren
        args[0].l = convertwchar_tToJavaString(t.pEnv,url);
        // temporaere Variable initialisieren
        static char * cSignature = "(Ljava/lang/String;)Ljava/sql/Driver;";
        static char * cMethodName = "getDriver";
        // Java-Call absetzen
        static jmethodID mID = t.pEnv->GetStaticMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!");
        if( mID )
        {
            out = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
            // und aufraeumen

        } //mID
        t.pEnv->DeleteLocalRef((jstring)args[0].l);
        return t.pEnv->NewGlobalRef( out );
    } //t.pEnv

    return out;
}

void java_sql_DriverManager::setLoginTimeout(sal_Int32 _par0)
{
    SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment gelscht worden!");
    jobject out(0);
    if( t.pEnv )
    {
        // temporaere Variable initialisieren
        static char * cSignature = "(I)V";
        static char * cMethodName = "setLoginTimeout";
        // Java-Call absetzen
        static jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!");
        if( mID )
            t.pEnv->CallStaticVoidMethod(getMyClass(), mID, _par0);
            ThrowSQLException(t.pEnv,0);
    } //t.pEnv
    // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
}

<|endoftext|>