<commit_before>/**
 * @file lldiriterator_test.cpp
 * @date 2011-06
 * @brief LLDirIterator test cases.
 *
 * $LicenseInfo:firstyear=2011&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2011, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.,
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "linden_common.h"
#include "lltut.h"
#include "../lldiriterator.h"

namespace tut
{

    struct LLDirIteratorFixture
    {
        LLDirIteratorFixture()
        {
        }
    };
    typedef test_group<LLDirIteratorFixture> LLDirIteratorTest_factory;
    typedef LLDirIteratorTest_factory::object LLDirIteratorTest_t;
    LLDirIteratorTest_factory tf("LLDirIterator");

    /*
    CHOP-662 was originally introduced to deal with crashes deleting files from
    a directory (VWR-25500). However, this introduced a crash looking for
    old chat logs as the glob_to_regex function in lldiriterator wasn't escaping lots of regexp characters
    */
    void test_chop_662(void)
    {
        //  Check a selection of bad group names from the crash reports
        LLDirIterator iter(".","+bad-group-name]+??-??.*");
        LLDirIterator iter(".","))--@---bad-group-name2((??-??.*\.txt");
        LLDirIterator iter(".","__^v--x)Cuide d sua vida(x--v^__??-??.*");
    }

    template<> template<>
	void LLDirIteratorTest_t::test<1>()
    {
       test_chop_662();
    }

}
<commit_msg>CHOP-662 Coupl of fixes to extended unit-test<commit_after>/**
 * @file lldiriterator_test.cpp
 * @date 2011-06
 * @brief LLDirIterator test cases.
 *
 * $LicenseInfo:firstyear=2011&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2011, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.,
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "linden_common.h"
#include "lltut.h"
#include "../lldiriterator.h"

namespace tut
{

    struct LLDirIteratorFixture
    {
        LLDirIteratorFixture()
        {
        }
    };
    typedef test_group<LLDirIteratorFixture> LLDirIteratorTest_factory;
    typedef LLDirIteratorTest_factory::object LLDirIteratorTest_t;
    LLDirIteratorTest_factory tf("LLDirIterator");

    /*
    CHOP-662 was originally introduced to deal with crashes deleting files from
    a directory (VWR-25500). However, this introduced a crash looking for
    old chat logs as the glob_to_regex function in lldiriterator wasn't escaping lots of regexp characters
    */
    void test_chop_662(void)
    {
        //  Check a selection of bad group names from the crash reports
        LLDirIterator iter(".","+bad-group-name]+??-??.*");
        LLDirIterator iter1(".","))--@---bad-group-name2((??-??.*\\.txt");
        LLDirIterator iter2(".","__^v--x)Cuide d sua vida(x--v^__??-??.*");
    }

    template<> template<>
	void LLDirIteratorTest_t::test<1>()
    {
       test_chop_662();
    }

}
<|endoftext|>


<commit_before>/*

Copyright (c) 2007, Arvid Norberg
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 the author 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.

*/

#ifndef TORRENT_CHAINED_BUFFER_HPP_INCLUDED
#define TORRENT_CHAINED_BUFFER_HPP_INCLUDED

#include <boost/function/function1.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION < 103500
#include <asio/buffer.hpp>
#else
#include <boost/asio/buffer.hpp>
#endif
#include <list>
#include <string.h> // for memcpy

namespace libtorrent
{
#if BOOST_VERSION >= 103500
	namespace asio = boost::asio;
#endif
	struct chained_buffer
	{
		chained_buffer(): m_bytes(0), m_capacity(0)
		{
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
			m_destructed = false;
#endif
		}

		struct buffer_t
		{
			boost::function<void(char*)> free; // destructs the buffer
			char* buf; // the first byte of the buffer
			int size; // the total size of the buffer

			char* start; // the first byte to send/receive in the buffer
			int used_size; // this is the number of bytes to send/receive
		};

		bool empty() const { return m_bytes == 0; }
		int size() const { return m_bytes; }
		int capacity() const { return m_capacity; }

		void pop_front(int bytes_to_pop);

		void append_buffer(char* buffer, int s, int used_size
			, boost::function<void(char*)> const& destructor);

		// returns the number of bytes available at the
		// end of the last chained buffer.
		int space_in_last_buffer();

		// tries to copy the given buffer to the end of the
		// last chained buffer. If there's not enough room
		// it returns false
		char* append(char const* buf, int s);

		// tries to allocate memory from the end
		// of the last buffer. If there isn't
		// enough room, returns 0
		char* allocate_appendix(int s);

		std::list<asio::const_buffer> const& build_iovec(int to_send);

		~chained_buffer();

	private:

		// this is the list of all the buffers we want to
		// send
		std::list<buffer_t> m_vec;

		// this is the number of bytes in the send buf.
		// this will always be equal to the sum of the
		// size of all buffers in vec
		int m_bytes;

		// the total size of all buffers in the chain
		// including unused space
		int m_capacity;

		// this is the vector of buffers used when
		// invoking the async write call
		std::list<asio::const_buffer> m_tmp_vec;

#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
		bool m_destructed;
#endif
	};
}

#endif

<commit_msg>fix test_buffer build when linking dynamically<commit_after>/*

Copyright (c) 2007, Arvid Norberg
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 the author 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.

*/

#ifndef TORRENT_CHAINED_BUFFER_HPP_INCLUDED
#define TORRENT_CHAINED_BUFFER_HPP_INCLUDED

#include "libtorrent/config.hpp"

#include <boost/function/function1.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION < 103500
#include <asio/buffer.hpp>
#else
#include <boost/asio/buffer.hpp>
#endif
#include <list>
#include <string.h> // for memcpy

namespace libtorrent
{
#if BOOST_VERSION >= 103500
	namespace asio = boost::asio;
#endif
	struct TORRENT_EXPORT chained_buffer
	{
		chained_buffer(): m_bytes(0), m_capacity(0)
		{
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
			m_destructed = false;
#endif
		}

		struct buffer_t
		{
			boost::function<void(char*)> free; // destructs the buffer
			char* buf; // the first byte of the buffer
			int size; // the total size of the buffer

			char* start; // the first byte to send/receive in the buffer
			int used_size; // this is the number of bytes to send/receive
		};

		bool empty() const { return m_bytes == 0; }
		int size() const { return m_bytes; }
		int capacity() const { return m_capacity; }

		void pop_front(int bytes_to_pop);

		void append_buffer(char* buffer, int s, int used_size
			, boost::function<void(char*)> const& destructor);

		// returns the number of bytes available at the
		// end of the last chained buffer.
		int space_in_last_buffer();

		// tries to copy the given buffer to the end of the
		// last chained buffer. If there's not enough room
		// it returns false
		char* append(char const* buf, int s);

		// tries to allocate memory from the end
		// of the last buffer. If there isn't
		// enough room, returns 0
		char* allocate_appendix(int s);

		std::list<asio::const_buffer> const& build_iovec(int to_send);

		~chained_buffer();

	private:

		// this is the list of all the buffers we want to
		// send
		std::list<buffer_t> m_vec;

		// this is the number of bytes in the send buf.
		// this will always be equal to the sum of the
		// size of all buffers in vec
		int m_bytes;

		// the total size of all buffers in the chain
		// including unused space
		int m_capacity;

		// this is the vector of buffers used when
		// invoking the async write call
		std::list<asio::const_buffer> m_tmp_vec;

#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
		bool m_destructed;
#endif
	};
}

#endif

<|endoftext|>


<commit_before>#ifndef ECL_COMMAND_HPP
#define ECL_COMMAND_HPP

#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include "data.h"

#ifndef RECEIVER_CAPACITY
#define RECEIVER_CAPACITY 32
#endif

namespace ecl
{

namespace detail
{

template<typename cmd>
class i_receiver
{
protected:
    virtual ~i_receiver() {}

public:
    virtual void receive(cmd&)                                              = 0;
};

}

class i_command
{
public:
    virtual bool init(const uint8_t               argc,
                      const uint8_t* const* const argv)                     = 0;

    virtual bool dispatch()                                                 = 0;
};

template<typename cmd>
class cmd_core
{
protected:
    void reg(detail::i_receiver<cmd>* const i)
    {
        for(auto &itf: s_array) {
            if(nullptr == itf) {
                itf = i;
                return;
            }
        }
    }

    void execute(cmd& c)                                                   const
    {
        for(auto itf: s_array) {
            if(nullptr != itf) {
                itf->receive(c);
            }
        }
    }

private:
    static detail::i_receiver<cmd>* s_array[RECEIVER_CAPACITY];
};

template<typename NAME, typename cmd>
class command : public virtual cmd_core<cmd>,
                public i_command
{
public:
    explicit command(const data_t* const buf) :
        m_buf(buf),
        m_size(0)
    {}

    virtual bool dispatch()                                             override
    {
        this->execute(*static_cast<cmd*>(this));

        return true;
    }

    virtual bool init(const uint8_t               argc,
                      const uint8_t* const* const argv)                 override
    {
        (void)(argc);
        (void)(argv);
        return true;
    }

    size_t append(const data_t& d)
    {
        if(nullptr == m_buf) {
            return 0;
        }

        if( (nullptr == m_buf->ptr) || (nullptr == d.ptr) || (0 == d.size) ) {
            return 0;
        }

        size_t remain = m_buf->size - m_size;
        size_t size_safe = (d.size < remain) ? d.size : remain;
        for(size_t i = 0; i < size_safe; ++i) {
            m_buf->ptr[m_size + i] = d.ptr[i];
            ++m_size;
        }

        return size_safe;
    }

    size_t append(const char* const str)
    {
        data_t d = {
            (uint8_t* const)str,
            strlen(str)
        };

        return append(d);
    }

    constexpr static const char* const name()
    {
        return NAME::name();
    }

protected:
    uint8_t             m_argc;
    const uint8_t**     m_argv;

    const data_t* const m_buf;
    size_t              m_size;
};

template<typename cmd>
class receiver : public virtual cmd_core<cmd>,
                 public detail::i_receiver<cmd>
{
protected:
    receiver()
    {
        this->cmd_core<cmd>::reg(this);
    }

    virtual ~receiver() {}
};

} // namespace ecl

#endif // ECL_COMMAND_HPP
<commit_msg>include fix<commit_after>#ifndef ECL_COMMAND_HPP
#define ECL_COMMAND_HPP

#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include "internal/data.h"

#ifndef RECEIVER_CAPACITY
#define RECEIVER_CAPACITY 32
#endif

namespace ecl
{

namespace detail
{

template<typename cmd>
class i_receiver
{
protected:
    virtual ~i_receiver() {}

public:
    virtual void receive(cmd&)                                              = 0;
};

}

class i_command
{
public:
    virtual bool init(const uint8_t               argc,
                      const uint8_t* const* const argv)                     = 0;

    virtual bool dispatch()                                                 = 0;
};

template<typename cmd>
class cmd_core
{
protected:
    void reg(detail::i_receiver<cmd>* const i)
    {
        for(auto &itf: s_array) {
            if(nullptr == itf) {
                itf = i;
                return;
            }
        }
    }

    void execute(cmd& c)                                                   const
    {
        for(auto itf: s_array) {
            if(nullptr != itf) {
                itf->receive(c);
            }
        }
    }

private:
    static detail::i_receiver<cmd>* s_array[RECEIVER_CAPACITY];
};

template<typename NAME, typename cmd>
class command : public virtual cmd_core<cmd>,
                public i_command
{
public:
    explicit command(const data_t* const buf) :
        m_buf(buf),
        m_size(0)
    {}

    virtual bool dispatch()                                             override
    {
        this->execute(*static_cast<cmd*>(this));

        return true;
    }

    virtual bool init(const uint8_t               argc,
                      const uint8_t* const* const argv)                 override
    {
        (void)(argc);
        (void)(argv);
        return true;
    }

    size_t append(const data_t& d)
    {
        if(nullptr == m_buf) {
            return 0;
        }

        if( (nullptr == m_buf->ptr) || (nullptr == d.ptr) || (0 == d.size) ) {
            return 0;
        }

        size_t remain = m_buf->size - m_size;
        size_t size_safe = (d.size < remain) ? d.size : remain;
        for(size_t i = 0; i < size_safe; ++i) {
            m_buf->ptr[m_size + i] = d.ptr[i];
            ++m_size;
        }

        return size_safe;
    }

    size_t append(const char* const str)
    {
        data_t d = {
            (uint8_t* const)str,
            strlen(str)
        };

        return append(d);
    }

    constexpr static const char* const name()
    {
        return NAME::name();
    }

protected:
    uint8_t             m_argc;
    const uint8_t**     m_argv;

    const data_t* const m_buf;
    size_t              m_size;
};

template<typename cmd>
class receiver : public virtual cmd_core<cmd>,
                 public detail::i_receiver<cmd>
{
protected:
    receiver()
    {
        this->cmd_core<cmd>::reg(this);
    }

    virtual ~receiver() {}
};

} // namespace ecl

#endif // ECL_COMMAND_HPP
<|endoftext|>


<commit_before>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "mitkRTStructureSetReader.h"
#include <mitkIOUtil.h>

#include <mitkBaseRenderer.h>
#include "mitkDICOMTagHelper.h"

namespace mitk
{
    RTStructureSetReader::RTStructureSetReader() {}

    RTStructureSetReader::~RTStructureSetReader() {}

    RTStructureSetReader::RoiEntry::RoiEntry()
    {
        Number = 0;
        DisplayColor[0] = 1.0;
        DisplayColor[1] = 0.0;
        DisplayColor[2] = 0.0;
        ContourModelSet = mitk::ContourModelSet::New();
    }

    RTStructureSetReader::RoiEntry::RoiEntry(const RoiEntry& src)
    {
        Number = src.Number;
        Name = src.Name;
        Description = src.Description;
        DisplayColor[0] = src.DisplayColor[0];
        DisplayColor[1] = src.DisplayColor[1];
        DisplayColor[2] = src.DisplayColor[2];
        ContourModelSet = mitk::ContourModelSet::New();
        SetPolyData(src.ContourModelSet);
    }

    RTStructureSetReader::RoiEntry::~RoiEntry() {}

    RTStructureSetReader::RoiEntry& RTStructureSetReader::
        RoiEntry::operator =(const RoiEntry& src)
    {
        Number = src.Number;
        Name = src.Name;
        Description = src.Description;
        DisplayColor[0] = src.DisplayColor[0];
        DisplayColor[1] = src.DisplayColor[1];
        DisplayColor[2] = src.DisplayColor[2];
        SetPolyData(src.ContourModelSet);
        return (*this);
    }

    void RTStructureSetReader::RoiEntry::
        SetPolyData(mitk::ContourModelSet::Pointer roiPolyData)
    {
        if (roiPolyData == this->ContourModelSet)
        {
            return;
        }

        this->ContourModelSet = roiPolyData;
    }

    size_t RTStructureSetReader::GetNumberOfROIs()
    {
        return this->ROISequenceVector.size();
    }

    RTStructureSetReader::RoiEntry* RTStructureSetReader::
        FindRoiByNumber(unsigned int roiNum)
    {
        for (unsigned int i = 0; i < this->ROISequenceVector.size(); ++i)
        {
            if (this->ROISequenceVector[i].Number == roiNum)
            {
                return &this->ROISequenceVector[i];
            }
        }

        return NULL;
    }

    RTStructureSetReader::ContourModelSetNodes RTStructureSetReader::
        ReadStructureSet(const char* filepath)
    {
        DcmFileFormat file;
        OFCondition output = file.loadFile(filepath, EXS_Unknown);

        if (output.bad())
        {
            MITK_ERROR << "Cant read the file" << std::endl;
        }

        DcmDataset* dataset = file.getDataset();

        DRTStructureSetIOD structureSetObject;
        OFCondition outp = structureSetObject.read(*dataset);

        if (!outp.good())
        {
            MITK_ERROR << "Error reading the file" << std::endl;
            RTStructureSetReader::ContourModelSetNodes x;
            return x;
        }

        DRTStructureSetROISequence& roiSequence =
            structureSetObject.getStructureSetROISequence();

        if (!roiSequence.gotoFirstItem().good())
        {
            MITK_ERROR << "Error reading the structure sequence" << std::endl;
            RTStructureSetReader::ContourModelSetNodes x;
            return x;
        }

        do
        {
            DRTStructureSetROISequence::Item& currentSequence =
                roiSequence.getCurrentItem();

            if (!currentSequence.isValid())
            {
                continue;
            }

            OFString roiName;
            OFString roiDescription;
            Sint32 roiNumber;
            RoiEntry roi;

            currentSequence.getROIName(roiName);
            currentSequence.getROIDescription(roiDescription);
            currentSequence.getROINumber(roiNumber);

            roi.Name = roiName.c_str();
            roi.Description = roiDescription.c_str();
            roi.Number = roiNumber;

            this->ROISequenceVector.push_back(roi);
        } while (roiSequence.gotoNextItem().good());

        Sint32 refRoiNumber;
        DRTROIContourSequence& roiContourSeqObject =
            structureSetObject.getROIContourSequence();

        if (!roiContourSeqObject.gotoFirstItem().good())
        {
            MITK_ERROR << "Error reading the contour sequence" << std::endl;
            RTStructureSetReader::ContourModelSetNodes x;
            return x;
        }

        do
        {
            mitk::ContourModelSet::Pointer contourSet = mitk::ContourModelSet::New();
            DRTROIContourSequence::Item& currentRoiObject =
                roiContourSeqObject.getCurrentItem();

            if (!currentRoiObject.isValid())
            {
                continue;
            }

            currentRoiObject.getReferencedROINumber(refRoiNumber);
            DRTContourSequence& contourSeqObject =
                currentRoiObject.getContourSequence();

            if (contourSeqObject.gotoFirstItem().good())
            {
                do
                {
                    DRTContourSequence::Item& contourItem =
                        contourSeqObject.getCurrentItem();

                    if (!contourItem.isValid())
                    {
                        continue;
                    }

                    OFString contourNumber;
                    OFString numberOfPoints;
                    OFVector<Float64> contourData_LPS;
                    mitk::ContourModel::Pointer contourSequence =
                        mitk::ContourModel::New();

                    contourItem.getContourNumber(contourNumber);
                    contourItem.getNumberOfContourPoints(numberOfPoints);
                    contourItem.getContourData(contourData_LPS);

                    for (unsigned int i = 0; i < contourData_LPS.size() / 3; i++)
                    {
                        mitk::Point3D point;
                        point[0] = contourData_LPS.at(3 * i);
                        point[1] = contourData_LPS.at(3 * i + 1);
                        point[2] = contourData_LPS.at(3 * i + 2);
                        contourSequence->AddVertex(point);
                    }

                    contourSequence->Close();
                    contourSet->AddContourModel(contourSequence);
                } while (contourSeqObject.gotoNextItem().good());
            }
            else
            {
                MITK_ERROR << "Error reading contourSeqObject" << std::endl;
            }

            RoiEntry* refROI = this->FindRoiByNumber(refRoiNumber);

            if (refROI == NULL)
            {
                MITK_ERROR << "Can not find references ROI" << std::endl;
                continue;
            }

            Sint32 roiColor;

            for (int j = 0; j < 3; j++)
            {
                currentRoiObject.getROIDisplayColor(roiColor, j);
                refROI->DisplayColor[j] = roiColor / 255.0;
            }

            refROI->ContourModelSet = contourSet;
            contourSet->SetProperty("name", mitk::StringProperty::New(refROI->Name));
            contourSet->SetProperty("contour.color", mitk::ColorProperty::New(
                refROI->DisplayColor[0],
                refROI->DisplayColor[1],
                refROI->DisplayColor[2]));

            //add uid and patient uid to property
            OFString uid;
            structureSetObject.getSeriesInstanceUID(uid);
            std::string uidPropertyName = mitk::GeneratPropertyNameForDICOMTag(mitk::DICOMTag(0x0020, 0x000e));
            contourSet->SetProperty(uidPropertyName.c_str(), mitk::StringProperty::New(uid.c_str()));

            OFString patientUid;
            structureSetObject.getPatientID(patientUid);
            std::string patientUidPropertyName = mitk::GeneratPropertyNameForDICOMTag(mitk::DICOMTag(0x0010,
                0x0020));
            contourSet->SetProperty(patientUidPropertyName.c_str(),
                mitk::StringProperty::New(patientUid.c_str()));

        } while (roiContourSeqObject.gotoNextItem().good());

        std::deque<mitk::DataNode::Pointer> nodes;

        for (unsigned int i = 0; i < ROISequenceVector.size(); i++)
        {
            mitk::DataNode::Pointer node = mitk::DataNode::New();
            node->SetData(ROISequenceVector.at(i).ContourModelSet);
            node->SetProperty("name", ROISequenceVector.at(i).ContourModelSet->GetProperty("name"));
            node->SetProperty("color", ROISequenceVector.at(i).ContourModelSet->GetProperty("contour.color"));
            node->SetProperty("contour.color",
                ROISequenceVector.at(i).ContourModelSet->GetProperty("contour.color"));
            node->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false));
            node->SetVisibility(true, mitk::BaseRenderer::GetInstance(
                mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget1")));
            node->SetVisibility(false, mitk::BaseRenderer::GetInstance(
                mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget2")));
            node->SetVisibility(false, mitk::BaseRenderer::GetInstance(
                mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget3")));
            node->SetVisibility(true, mitk::BaseRenderer::GetInstance(
                mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget4")));

            nodes.push_back(node);
        }

        return nodes;
    }
}
<commit_msg>fixed missed compile errors in DicomRT.<commit_after>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "mitkRTStructureSetReader.h"
#include <mitkIOUtil.h>

#include <mitkBaseRenderer.h>
#include "mitkDICOMTagPath.h"

namespace mitk
{
    RTStructureSetReader::RTStructureSetReader() {}

    RTStructureSetReader::~RTStructureSetReader() {}

    RTStructureSetReader::RoiEntry::RoiEntry()
    {
        Number = 0;
        DisplayColor[0] = 1.0;
        DisplayColor[1] = 0.0;
        DisplayColor[2] = 0.0;
        ContourModelSet = mitk::ContourModelSet::New();
    }

    RTStructureSetReader::RoiEntry::RoiEntry(const RoiEntry& src)
    {
        Number = src.Number;
        Name = src.Name;
        Description = src.Description;
        DisplayColor[0] = src.DisplayColor[0];
        DisplayColor[1] = src.DisplayColor[1];
        DisplayColor[2] = src.DisplayColor[2];
        ContourModelSet = mitk::ContourModelSet::New();
        SetPolyData(src.ContourModelSet);
    }

    RTStructureSetReader::RoiEntry::~RoiEntry() {}

    RTStructureSetReader::RoiEntry& RTStructureSetReader::
        RoiEntry::operator =(const RoiEntry& src)
    {
        Number = src.Number;
        Name = src.Name;
        Description = src.Description;
        DisplayColor[0] = src.DisplayColor[0];
        DisplayColor[1] = src.DisplayColor[1];
        DisplayColor[2] = src.DisplayColor[2];
        SetPolyData(src.ContourModelSet);
        return (*this);
    }

    void RTStructureSetReader::RoiEntry::
        SetPolyData(mitk::ContourModelSet::Pointer roiPolyData)
    {
        if (roiPolyData == this->ContourModelSet)
        {
            return;
        }

        this->ContourModelSet = roiPolyData;
    }

    size_t RTStructureSetReader::GetNumberOfROIs()
    {
        return this->ROISequenceVector.size();
    }

    RTStructureSetReader::RoiEntry* RTStructureSetReader::
        FindRoiByNumber(unsigned int roiNum)
    {
        for (unsigned int i = 0; i < this->ROISequenceVector.size(); ++i)
        {
            if (this->ROISequenceVector[i].Number == roiNum)
            {
                return &this->ROISequenceVector[i];
            }
        }

        return NULL;
    }

    RTStructureSetReader::ContourModelSetNodes RTStructureSetReader::
        ReadStructureSet(const char* filepath)
    {
        DcmFileFormat file;
        OFCondition output = file.loadFile(filepath, EXS_Unknown);

        if (output.bad())
        {
            MITK_ERROR << "Cant read the file" << std::endl;
        }

        DcmDataset* dataset = file.getDataset();

        DRTStructureSetIOD structureSetObject;
        OFCondition outp = structureSetObject.read(*dataset);

        if (!outp.good())
        {
            MITK_ERROR << "Error reading the file" << std::endl;
            RTStructureSetReader::ContourModelSetNodes x;
            return x;
        }

        DRTStructureSetROISequence& roiSequence =
            structureSetObject.getStructureSetROISequence();

        if (!roiSequence.gotoFirstItem().good())
        {
            MITK_ERROR << "Error reading the structure sequence" << std::endl;
            RTStructureSetReader::ContourModelSetNodes x;
            return x;
        }

        do
        {
            DRTStructureSetROISequence::Item& currentSequence =
                roiSequence.getCurrentItem();

            if (!currentSequence.isValid())
            {
                continue;
            }

            OFString roiName;
            OFString roiDescription;
            Sint32 roiNumber;
            RoiEntry roi;

            currentSequence.getROIName(roiName);
            currentSequence.getROIDescription(roiDescription);
            currentSequence.getROINumber(roiNumber);

            roi.Name = roiName.c_str();
            roi.Description = roiDescription.c_str();
            roi.Number = roiNumber;

            this->ROISequenceVector.push_back(roi);
        } while (roiSequence.gotoNextItem().good());

        Sint32 refRoiNumber;
        DRTROIContourSequence& roiContourSeqObject =
            structureSetObject.getROIContourSequence();

        if (!roiContourSeqObject.gotoFirstItem().good())
        {
            MITK_ERROR << "Error reading the contour sequence" << std::endl;
            RTStructureSetReader::ContourModelSetNodes x;
            return x;
        }

        do
        {
            mitk::ContourModelSet::Pointer contourSet = mitk::ContourModelSet::New();
            DRTROIContourSequence::Item& currentRoiObject =
                roiContourSeqObject.getCurrentItem();

            if (!currentRoiObject.isValid())
            {
                continue;
            }

            currentRoiObject.getReferencedROINumber(refRoiNumber);
            DRTContourSequence& contourSeqObject =
                currentRoiObject.getContourSequence();

            if (contourSeqObject.gotoFirstItem().good())
            {
                do
                {
                    DRTContourSequence::Item& contourItem =
                        contourSeqObject.getCurrentItem();

                    if (!contourItem.isValid())
                    {
                        continue;
                    }

                    OFString contourNumber;
                    OFString numberOfPoints;
                    OFVector<Float64> contourData_LPS;
                    mitk::ContourModel::Pointer contourSequence =
                        mitk::ContourModel::New();

                    contourItem.getContourNumber(contourNumber);
                    contourItem.getNumberOfContourPoints(numberOfPoints);
                    contourItem.getContourData(contourData_LPS);

                    for (unsigned int i = 0; i < contourData_LPS.size() / 3; i++)
                    {
                        mitk::Point3D point;
                        point[0] = contourData_LPS.at(3 * i);
                        point[1] = contourData_LPS.at(3 * i + 1);
                        point[2] = contourData_LPS.at(3 * i + 2);
                        contourSequence->AddVertex(point);
                    }

                    contourSequence->Close();
                    contourSet->AddContourModel(contourSequence);
                } while (contourSeqObject.gotoNextItem().good());
            }
            else
            {
                MITK_ERROR << "Error reading contourSeqObject" << std::endl;
            }

            RoiEntry* refROI = this->FindRoiByNumber(refRoiNumber);

            if (refROI == NULL)
            {
                MITK_ERROR << "Can not find references ROI" << std::endl;
                continue;
            }

            Sint32 roiColor;

            for (int j = 0; j < 3; j++)
            {
                currentRoiObject.getROIDisplayColor(roiColor, j);
                refROI->DisplayColor[j] = roiColor / 255.0;
            }

            refROI->ContourModelSet = contourSet;
            contourSet->SetProperty("name", mitk::StringProperty::New(refROI->Name));
            contourSet->SetProperty("contour.color", mitk::ColorProperty::New(
                refROI->DisplayColor[0],
                refROI->DisplayColor[1],
                refROI->DisplayColor[2]));

            //add uid and patient uid to property
            OFString uid;
            structureSetObject.getSeriesInstanceUID(uid);
            std::string uidPropertyName = mitk::DICOMTagPathToPropertyName(mitk::DICOMTagPath(0x0020, 0x000e));
            contourSet->SetProperty(uidPropertyName.c_str(), mitk::StringProperty::New(uid.c_str()));

            OFString patientUid;
            structureSetObject.getPatientID(patientUid);
            std::string patientUidPropertyName = mitk::DICOMTagPathToPropertyName(mitk::DICOMTagPath(0x0010,
                0x0020));
            contourSet->SetProperty(patientUidPropertyName.c_str(),
                mitk::StringProperty::New(patientUid.c_str()));

        } while (roiContourSeqObject.gotoNextItem().good());

        std::deque<mitk::DataNode::Pointer> nodes;

        for (unsigned int i = 0; i < ROISequenceVector.size(); i++)
        {
            mitk::DataNode::Pointer node = mitk::DataNode::New();
            node->SetData(ROISequenceVector.at(i).ContourModelSet);
            node->SetProperty("name", ROISequenceVector.at(i).ContourModelSet->GetProperty("name"));
            node->SetProperty("color", ROISequenceVector.at(i).ContourModelSet->GetProperty("contour.color"));
            node->SetProperty("contour.color",
                ROISequenceVector.at(i).ContourModelSet->GetProperty("contour.color"));
            node->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false));
            node->SetVisibility(true, mitk::BaseRenderer::GetInstance(
                mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget1")));
            node->SetVisibility(false, mitk::BaseRenderer::GetInstance(
                mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget2")));
            node->SetVisibility(false, mitk::BaseRenderer::GetInstance(
                mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget3")));
            node->SetVisibility(true, mitk::BaseRenderer::GetInstance(
                mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget4")));

            nodes.push_back(node);
        }

        return nodes;
    }
}
<|endoftext|>


<commit_before>/*

Copyright (c) 2007, Arvid Norberg
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 the author 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.

*/

#ifndef TORRENT_DISK_IO_THREAD
#define TORRENT_DISK_IO_THREAD

#ifdef TORRENT_DISK_STATS
#include <fstream>
#endif

#include "libtorrent/storage.hpp"
#include "libtorrent/allocator.hpp"
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_array.hpp>
#include <list>
#include "libtorrent/config.hpp"
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
#include <boost/pool/pool.hpp>
#endif
#include "libtorrent/session_settings.hpp"

namespace libtorrent
{
	struct cached_piece_info
	{
		int piece;
		std::vector<bool> blocks;
		ptime last_use;
		enum kind_t { read_cache = 0, write_cache = 1 };
		kind_t kind;
	};

	struct disk_io_job
	{
		disk_io_job()
			: action(read)
			, buffer(0)
			, buffer_size(0)
			, piece(0)
			, offset(0)
			, priority(0)
		{}

		enum action_t
		{
			read
			, write
			, hash
			, move_storage
			, release_files
			, delete_files
			, check_fastresume
			, check_files
			, save_resume_data
			, rename_file
			, abort_thread
			, clear_read_cache
			, abort_torrent
			, update_settings
			, read_and_hash
		};

		action_t action;

		char* buffer;
		int buffer_size;
		boost::intrusive_ptr<piece_manager> storage;
		// arguments used for read and write
		int piece, offset;
		// used for move_storage and rename_file. On errors, this is set
		// to the error message
		std::string str;

		// on error, this is set to the path of the
		// file the disk operation failed on
		std::string error_file;

		// priority decides whether or not this
		// job will skip entries in the queue or
		// not. It always skips in front of entries
		// with lower priority
		int priority;

		boost::shared_ptr<entry> resume_data;

		// the error code from the file operation
		error_code error;

		// this is called when operation completes
		boost::function<void(int, disk_io_job const&)> callback;
	};

	struct cache_status
	{
		cache_status()
			: blocks_written(0)
			, writes(0)
			, blocks_read(0)
			, blocks_read_hit(0)
			, reads(0)
			, cache_size(0)
			, read_cache_size(0)
		{}

		// the number of 16kB blocks written
		size_type blocks_written;
		// the number of write operations used
		size_type writes;
		// (blocks_written - writes) / blocks_written represents the
		// "cache hit" ratio in the write cache
		// the number of blocks read

		// the number of blocks passed back to the bittorrent engine
		size_type blocks_read;
		// the number of blocks that was just copied from the read cache
		size_type blocks_read_hit;
		// the number of read operations used
		size_type reads;

		// the number of blocks in the cache (both read and write)
		int cache_size;

		// the number of blocks in the cache used for read cache
		int read_cache_size;
	};

	struct disk_buffer_pool : boost::noncopyable
	{
		disk_buffer_pool(int block_size);

#ifdef TORRENT_DEBUG
		bool is_disk_buffer(char* buffer) const;
#endif

		char* allocate_buffer(char const* category);
		void free_buffer(char* buf);

		char* allocate_buffers(int blocks, char const* category);
		void free_buffers(char* buf, int blocks);

		int block_size() const { return m_block_size; }

#ifdef TORRENT_STATS
		int disk_allocations() const
		{ return m_allocations; }
#endif

		void release_memory();

	protected:

		// number of bytes per block. The BitTorrent
		// protocol defines the block size to 16 KiB.
		const int m_block_size;

		session_settings m_settings;

	private:

		// this only protects the pool allocator
		typedef boost::mutex mutex_t;
		mutable mutex_t m_pool_mutex;
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
		// memory pool for read and write operations
		// and disk cache
		boost::pool<page_aligned_allocator> m_pool;
#endif

#ifdef TORRENT_STATS
		int m_allocations;
		std::map<std::string, int> m_categories;
		std::map<char*, std::string> m_buf_to_category;
		std::ofstream m_log;
#endif
	};

	// this is a singleton consisting of the thread and a queue
	// of disk io jobs
	struct disk_io_thread : disk_buffer_pool
	{
		disk_io_thread(io_service& ios, int block_size = 16 * 1024);
		~disk_io_thread();

		void join();

		// aborts read operations
		void stop(boost::intrusive_ptr<piece_manager> s);
		void add_job(disk_io_job const& j
			, boost::function<void(int, disk_io_job const&)> const& f
			= boost::function<void(int, disk_io_job const&)>());

		// keep track of the number of bytes in the job queue
		// at any given time. i.e. the sum of all buffer_size.
		// this is used to slow down the download global download
		// speed when the queue buffer size is too big.
		size_type queue_buffer_size() const
		{ return m_queue_buffer_size; }

		void get_cache_info(sha1_hash const& ih
			, std::vector<cached_piece_info>& ret) const;

		cache_status status() const;

		void operator()();

#ifdef TORRENT_DEBUG
		void check_invariant() const;
#endif

	private:

		struct cached_piece_entry
		{
			int piece;
			// storage this piece belongs to
			boost::intrusive_ptr<piece_manager> storage;
			// the last time a block was writting to this piece
			ptime last_use;
			// the number of blocks in the cache for this piece
			int num_blocks;
			// the pointers to the block data
			boost::shared_array<char*> blocks;
		};

		typedef boost::recursive_mutex mutex_t;
		typedef std::list<cached_piece_entry> cache_t;

		bool test_error(disk_io_job& j);
		void post_callback(boost::function<void(int, disk_io_job const&)> const& handler
			, disk_io_job const& j, int ret);

		// cache operations
		cache_t::iterator find_cached_piece(
			cache_t& cache, disk_io_job const& j
			, mutex_t::scoped_lock& l);
		int copy_from_piece(cache_t::iterator p, bool& hit
			, disk_io_job const& j, mutex_t::scoped_lock& l);

		// write cache operations
		void flush_oldest_piece(mutex_t::scoped_lock& l);
		void flush_expired_pieces();
		void flush_and_remove(cache_t::iterator i, mutex_t::scoped_lock& l);
		void flush(cache_t::iterator i, mutex_t::scoped_lock& l);
		void cache_block(disk_io_job& j, mutex_t::scoped_lock& l);

		// read cache operations
		bool clear_oldest_read_piece(cache_t::iterator ignore
			, mutex_t::scoped_lock& l);
		int read_into_piece(cached_piece_entry& p, int start_block
			, int options, mutex_t::scoped_lock& l);
		int cache_read_block(disk_io_job const& j, mutex_t::scoped_lock& l);
		int cache_read_piece(disk_io_job const& j, mutex_t::scoped_lock& l);
		void free_piece(cached_piece_entry& p, mutex_t::scoped_lock& l);
		bool make_room(int num_blocks
			, cache_t::iterator ignore
			, mutex_t::scoped_lock& l);
		int try_read_from_cache(disk_io_job const& j);
		int read_piece_from_cache_and_hash(disk_io_job const& j, sha1_hash& h);

		// this mutex only protects m_jobs, m_queue_buffer_size
		// and m_abort
		mutable mutex_t m_queue_mutex;
		boost::condition m_signal;
		bool m_abort;
		std::list<disk_io_job> m_jobs;
		size_type m_queue_buffer_size;

		// this protects the piece cache and related members
		mutable mutex_t m_piece_mutex;
		// write cache
		cache_t m_pieces;

		// read cache
		cache_t m_read_pieces;

		// total number of blocks in use by both the read
		// and the write cache. This is not supposed to
		// exceed m_cache_size
		cache_status m_cache_stats;

#ifdef TORRENT_DISK_STATS
		std::ofstream m_log;
#endif

		io_service& m_ios;

		// thread for performing blocking disk io operations
		boost::thread m_disk_io_thread;
	};

}

#endif

<commit_msg>fixed disk stat build<commit_after>/*

Copyright (c) 2007, Arvid Norberg
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 the author 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.

*/

#ifndef TORRENT_DISK_IO_THREAD
#define TORRENT_DISK_IO_THREAD

#ifdef TORRENT_DISK_STATS
#include <fstream>
#endif

#include "libtorrent/storage.hpp"
#include "libtorrent/allocator.hpp"
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_array.hpp>
#include <list>
#include "libtorrent/config.hpp"
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
#include <boost/pool/pool.hpp>
#endif
#include "libtorrent/session_settings.hpp"

namespace libtorrent
{
	struct cached_piece_info
	{
		int piece;
		std::vector<bool> blocks;
		ptime last_use;
		enum kind_t { read_cache = 0, write_cache = 1 };
		kind_t kind;
	};

	struct disk_io_job
	{
		disk_io_job()
			: action(read)
			, buffer(0)
			, buffer_size(0)
			, piece(0)
			, offset(0)
			, priority(0)
		{}

		enum action_t
		{
			read
			, write
			, hash
			, move_storage
			, release_files
			, delete_files
			, check_fastresume
			, check_files
			, save_resume_data
			, rename_file
			, abort_thread
			, clear_read_cache
			, abort_torrent
			, update_settings
			, read_and_hash
		};

		action_t action;

		char* buffer;
		int buffer_size;
		boost::intrusive_ptr<piece_manager> storage;
		// arguments used for read and write
		int piece, offset;
		// used for move_storage and rename_file. On errors, this is set
		// to the error message
		std::string str;

		// on error, this is set to the path of the
		// file the disk operation failed on
		std::string error_file;

		// priority decides whether or not this
		// job will skip entries in the queue or
		// not. It always skips in front of entries
		// with lower priority
		int priority;

		boost::shared_ptr<entry> resume_data;

		// the error code from the file operation
		error_code error;

		// this is called when operation completes
		boost::function<void(int, disk_io_job const&)> callback;
	};

	struct cache_status
	{
		cache_status()
			: blocks_written(0)
			, writes(0)
			, blocks_read(0)
			, blocks_read_hit(0)
			, reads(0)
			, cache_size(0)
			, read_cache_size(0)
		{}

		// the number of 16kB blocks written
		size_type blocks_written;
		// the number of write operations used
		size_type writes;
		// (blocks_written - writes) / blocks_written represents the
		// "cache hit" ratio in the write cache
		// the number of blocks read

		// the number of blocks passed back to the bittorrent engine
		size_type blocks_read;
		// the number of blocks that was just copied from the read cache
		size_type blocks_read_hit;
		// the number of read operations used
		size_type reads;

		// the number of blocks in the cache (both read and write)
		int cache_size;

		// the number of blocks in the cache used for read cache
		int read_cache_size;
	};

	struct disk_buffer_pool : boost::noncopyable
	{
		disk_buffer_pool(int block_size);

#ifdef TORRENT_DEBUG
		bool is_disk_buffer(char* buffer) const;
#endif

		char* allocate_buffer(char const* category);
		void free_buffer(char* buf);

		char* allocate_buffers(int blocks, char const* category);
		void free_buffers(char* buf, int blocks);

		int block_size() const { return m_block_size; }

#ifdef TORRENT_STATS
		int disk_allocations() const
		{ return m_allocations; }
#endif

		void release_memory();

	protected:

		// number of bytes per block. The BitTorrent
		// protocol defines the block size to 16 KiB.
		const int m_block_size;

		session_settings m_settings;

	private:

		// this only protects the pool allocator
		typedef boost::mutex mutex_t;
		mutable mutex_t m_pool_mutex;
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
		// memory pool for read and write operations
		// and disk cache
		boost::pool<page_aligned_allocator> m_pool;
#endif

#ifdef TORRENT_STATS
		int m_allocations;
		std::map<std::string, int> m_categories;
		std::map<char*, std::string> m_buf_to_category;
#endif
#ifdef TORRENT_DISK_STATS
		std::ofstream m_log;
#endif
	};

	// this is a singleton consisting of the thread and a queue
	// of disk io jobs
	struct disk_io_thread : disk_buffer_pool
	{
		disk_io_thread(io_service& ios, int block_size = 16 * 1024);
		~disk_io_thread();

		void join();

		// aborts read operations
		void stop(boost::intrusive_ptr<piece_manager> s);
		void add_job(disk_io_job const& j
			, boost::function<void(int, disk_io_job const&)> const& f
			= boost::function<void(int, disk_io_job const&)>());

		// keep track of the number of bytes in the job queue
		// at any given time. i.e. the sum of all buffer_size.
		// this is used to slow down the download global download
		// speed when the queue buffer size is too big.
		size_type queue_buffer_size() const
		{ return m_queue_buffer_size; }

		void get_cache_info(sha1_hash const& ih
			, std::vector<cached_piece_info>& ret) const;

		cache_status status() const;

		void operator()();

#ifdef TORRENT_DEBUG
		void check_invariant() const;
#endif

	private:

		struct cached_piece_entry
		{
			int piece;
			// storage this piece belongs to
			boost::intrusive_ptr<piece_manager> storage;
			// the last time a block was writting to this piece
			ptime last_use;
			// the number of blocks in the cache for this piece
			int num_blocks;
			// the pointers to the block data
			boost::shared_array<char*> blocks;
		};

		typedef boost::recursive_mutex mutex_t;
		typedef std::list<cached_piece_entry> cache_t;

		bool test_error(disk_io_job& j);
		void post_callback(boost::function<void(int, disk_io_job const&)> const& handler
			, disk_io_job const& j, int ret);

		// cache operations
		cache_t::iterator find_cached_piece(
			cache_t& cache, disk_io_job const& j
			, mutex_t::scoped_lock& l);
		int copy_from_piece(cache_t::iterator p, bool& hit
			, disk_io_job const& j, mutex_t::scoped_lock& l);

		// write cache operations
		void flush_oldest_piece(mutex_t::scoped_lock& l);
		void flush_expired_pieces();
		void flush_and_remove(cache_t::iterator i, mutex_t::scoped_lock& l);
		void flush(cache_t::iterator i, mutex_t::scoped_lock& l);
		void cache_block(disk_io_job& j, mutex_t::scoped_lock& l);

		// read cache operations
		bool clear_oldest_read_piece(cache_t::iterator ignore
			, mutex_t::scoped_lock& l);
		int read_into_piece(cached_piece_entry& p, int start_block
			, int options, mutex_t::scoped_lock& l);
		int cache_read_block(disk_io_job const& j, mutex_t::scoped_lock& l);
		int cache_read_piece(disk_io_job const& j, mutex_t::scoped_lock& l);
		void free_piece(cached_piece_entry& p, mutex_t::scoped_lock& l);
		bool make_room(int num_blocks
			, cache_t::iterator ignore
			, mutex_t::scoped_lock& l);
		int try_read_from_cache(disk_io_job const& j);
		int read_piece_from_cache_and_hash(disk_io_job const& j, sha1_hash& h);

		// this mutex only protects m_jobs, m_queue_buffer_size
		// and m_abort
		mutable mutex_t m_queue_mutex;
		boost::condition m_signal;
		bool m_abort;
		std::list<disk_io_job> m_jobs;
		size_type m_queue_buffer_size;

		// this protects the piece cache and related members
		mutable mutex_t m_piece_mutex;
		// write cache
		cache_t m_pieces;

		// read cache
		cache_t m_read_pieces;

		// total number of blocks in use by both the read
		// and the write cache. This is not supposed to
		// exceed m_cache_size
		cache_status m_cache_stats;

#ifdef TORRENT_DISK_STATS
		std::ofstream m_log;
#endif

		io_service& m_ios;

		// thread for performing blocking disk io operations
		boost::thread m_disk_io_thread;
	};

}

#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: moduldlg.hxx,v $
 *
 *  $Revision: 1.17 $
 *
 *  last change: $Author: kz $ $Date: 2004-07-23 12:06:40 $
 *
 *  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 _MODULDLG_HXX
#define _MODULDLG_HXX

#ifndef _SVHEADER_HXX
#include <svheader.hxx>
#endif

#include <bastype2.hxx>

#ifndef _SV_DIALOG_HXX //autogen
#include <vcl/dialog.hxx>
#endif

#ifndef _SV_BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif

#ifndef _SV_FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif

#ifndef _SVTABBX_HXX //autogen
#include <svtools/svtabbx.hxx>
#endif

#ifndef _SV_TABDLG_HXX //autogen
#include <vcl/tabdlg.hxx>
#endif

#ifndef _SV_TABPAGE_HXX //autogen
#include <vcl/tabpage.hxx>
#endif

#include <vcl/tabctrl.hxx>
#include <vcl/lstbox.hxx>

class StarBASIC;

#define NEWOBJECTMODE_LIB       1
#define NEWOBJECTMODE_MOD       2
#define NEWOBJECTMODE_DLG       3
#define NEWOBJECTMODE_METH      4

class NewObjectDialog : public ModalDialog
{
private:
    FixedText       aText;
    Edit            aEdit;
    OKButton        aOKButton;
    CancelButton    aCancelButton;

    DECL_LINK(OkButtonHandler, Button *);

public:
    NewObjectDialog(Window * pParent, USHORT nMode, bool bCheckName = false);
                ~NewObjectDialog();

    String      GetObjectName() const { return aEdit.GetText(); }
    void        SetObjectName( const String& rName ) { aEdit.SetText( rName ); aEdit.SetSelection( Selection( 0, rName.Len() ) );}
};

class ExtBasicTreeListBox : public BasicTreeListBox
{
protected:
    virtual BOOL    EditingEntry( SvLBoxEntry* pEntry, Selection& rSel  );
    virtual BOOL    EditedEntry( SvLBoxEntry* pEntry, const String& rNewText );

    virtual DragDropMode    NotifyStartDrag( TransferDataContainer& rData, SvLBoxEntry* pEntry );
    virtual BOOL            NotifyAcceptDrop( SvLBoxEntry* pEntry );

    virtual BOOL    NotifyMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
                        SvLBoxEntry*& rpNewParent, ULONG& rNewChildPos );
    virtual BOOL    NotifyCopying( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
                        SvLBoxEntry*& rpNewParent, ULONG& rNewChildPos );
    BOOL            NotifyCopyingMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
                        SvLBoxEntry*& rpNewParent, ULONG& rNewChildPos, BOOL bMove );

public:
    ExtBasicTreeListBox( Window* pParent, const ResId& rRes );
    ~ExtBasicTreeListBox();
};

#define LIBMODE_CHOOSER     1
#define LIBMODE_MANAGER     2

class BasicCheckBox : public SvTabListBox
{
private:
    USHORT              nMode;
    SvLBoxButtonData*   pCheckButton;
    SfxObjectShell*     m_pShell;
    void                Init();

public:
                    BasicCheckBox( Window* pParent, const ResId& rResId );
                    ~BasicCheckBox();

    SvLBoxEntry*    InsertEntry( const String& rStr, ULONG nPos = LISTBOX_APPEND );
    void            RemoveEntry( ULONG nPos );
    SvLBoxEntry*    FindEntry( const String& rName );

    void            SelectEntryPos( ULONG nPos, BOOL bSelect = TRUE );
    ULONG           GetSelectEntryPos() const;

    ULONG           GetCheckedEntryCount() const;
    void            CheckEntryPos( ULONG nPos, BOOL bCheck = TRUE );
    BOOL            IsChecked( ULONG nPos ) const;

    virtual void    InitEntry( SvLBoxEntry*, const XubString&, const Image&, const Image& );
    virtual BOOL    EditingEntry( SvLBoxEntry* pEntry, Selection& rSel );
    virtual BOOL    EditedEntry( SvLBoxEntry* pEntry, const String& rNewText );

    void            SetShell( SfxObjectShell* pShell ) { m_pShell = pShell; }

    void            SetMode( USHORT n );
    USHORT          GetMode() const         { return nMode; }
};

class LibDialog: public ModalDialog
{
private:
    OKButton        aOKButton;
    CancelButton    aCancelButton;
    FixedText       aStorageName;
    BasicCheckBox   aLibBox;
    FixedLine       aFixedLine;
    CheckBox        aReferenceBox;
    CheckBox        aReplaceBox;

public:
                    LibDialog( Window* pParent );
                    ~LibDialog();

    void            SetStorageName( const String& rName );

    BasicCheckBox&  GetLibBox()                 { return aLibBox; }
    BOOL            IsReference() const         { return aReferenceBox.IsChecked(); }
    BOOL            IsReplace() const           { return aReplaceBox.IsChecked(); }

    void            EnableReference( BOOL b )   { aReferenceBox.Enable( b ); }
    void            EnableReplace( BOOL b )     { aReplaceBox.Enable( b ); }
};

class OrganizeDialog : public TabDialog
{
private:
    TabControl              aTabCtrl;
    BasicEntryDescriptor    m_aCurEntry;

public:
                    OrganizeDialog( Window* pParent, INT16 tabId, BasicEntryDescriptor& rDesc );
                    ~OrganizeDialog();

    virtual short   Execute();

    DECL_LINK( ActivatePageHdl, TabControl * );
};

class ObjectPage: public TabPage
{
protected:
    FixedText           aLibText;
    ExtBasicTreeListBox aBasicBox;
    PushButton          aEditButton;
    CancelButton        aCloseButton;
    PushButton          aNewModButton;
    PushButton          aNewDlgButton;
    PushButton          aDelButton;

    DECL_LINK( BasicBoxHighlightHdl, BasicTreeListBox * );
    DECL_LINK( ButtonHdl, Button * );
    void                CheckButtons();
    bool                GetSelection( SfxObjectShell*& rpShell, String& rLibName );
    void                DeleteCurrent();
    void                NewModule();
    void                NewDialog();
    void                EndTabDialog( USHORT nRet );

    TabDialog*          pTabDlg;

    virtual void        ActivatePage();
    virtual void        DeactivatePage();

public:
                        ObjectPage( Window* pParent, const ResId& rResId, USHORT nMode );

    void                SetCurrentEntry( BasicEntryDescriptor& rDesc );
    void                SetTabDlg( TabDialog* p ) { pTabDlg = p;}
};

class SvxPasswordDialog;

class LibPage: public TabPage
{
protected:
    FixedText           aBasicsText;
    ListBox             aBasicsBox;
    FixedText           aLibText;
    BasicCheckBox       aLibBox;
    PushButton          aEditButton;
    CancelButton        aCloseButton;
    PushButton          aPasswordButton;
    PushButton          aNewLibButton;
    PushButton          aInsertLibButton;
    PushButton          aDelButton;

    SfxObjectShell*     m_pCurShell;
    LibraryLocation     m_eCurLocation;

    DECL_LINK( TreeListHighlightHdl, SvTreeListBox * );
    DECL_LINK( BasicSelectHdl, ListBox * );
    DECL_LINK( ButtonHdl, Button * );
    DECL_LINK( CheckPasswordHdl, SvxPasswordDialog * );
    void                CheckButtons();
    void                DeleteCurrent();
    void                NewLib();
    void                InsertLib();
    void                EndTabDialog( USHORT nRet );
    void                FillListBox();
    void                InsertListBoxEntry( SfxObjectShell* pShell, LibraryLocation eLocation );
    void                SetCurLib();
    SvLBoxEntry*        ImpInsertLibEntry( const String& rLibName, ULONG nPos );
    virtual void        ActivatePage();
    virtual void        DeactivatePage();

    TabDialog*          pTabDlg;

public:
                        LibPage( Window* pParent );
    virtual             ~LibPage();

    void                SetTabDlg( TabDialog* p ) { pTabDlg = p;}
};

// Helper functions
SbModule* createModImpl( Window* pWin, SfxObjectShell* pShell,
    BasicTreeListBox& rBasicBox, const String& rLibName, String aModName, bool bMain = false );
void createLibImpl( Window* pWin, SfxObjectShell* pShell,
                    BasicCheckBox* pLibBox, BasicTreeListBox* pBasicBox );

#endif // _MODULDLG_HXX
<commit_msg>INTEGRATION: CWS ooo19126 (1.17.140); FILE MERGED 2005/09/05 13:55:45 rt 1.17.140.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: moduldlg.hxx,v $
 *
 *  $Revision: 1.18 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-07 20:07:59 $
 *
 *  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
 *
 ************************************************************************/

#ifndef _MODULDLG_HXX
#define _MODULDLG_HXX

#ifndef _SVHEADER_HXX
#include <svheader.hxx>
#endif

#include <bastype2.hxx>

#ifndef _SV_DIALOG_HXX //autogen
#include <vcl/dialog.hxx>
#endif

#ifndef _SV_BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif

#ifndef _SV_FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif

#ifndef _SVTABBX_HXX //autogen
#include <svtools/svtabbx.hxx>
#endif

#ifndef _SV_TABDLG_HXX //autogen
#include <vcl/tabdlg.hxx>
#endif

#ifndef _SV_TABPAGE_HXX //autogen
#include <vcl/tabpage.hxx>
#endif

#include <vcl/tabctrl.hxx>
#include <vcl/lstbox.hxx>

class StarBASIC;

#define NEWOBJECTMODE_LIB       1
#define NEWOBJECTMODE_MOD       2
#define NEWOBJECTMODE_DLG       3
#define NEWOBJECTMODE_METH      4

class NewObjectDialog : public ModalDialog
{
private:
    FixedText       aText;
    Edit            aEdit;
    OKButton        aOKButton;
    CancelButton    aCancelButton;

    DECL_LINK(OkButtonHandler, Button *);

public:
    NewObjectDialog(Window * pParent, USHORT nMode, bool bCheckName = false);
                ~NewObjectDialog();

    String      GetObjectName() const { return aEdit.GetText(); }
    void        SetObjectName( const String& rName ) { aEdit.SetText( rName ); aEdit.SetSelection( Selection( 0, rName.Len() ) );}
};

class ExtBasicTreeListBox : public BasicTreeListBox
{
protected:
    virtual BOOL    EditingEntry( SvLBoxEntry* pEntry, Selection& rSel  );
    virtual BOOL    EditedEntry( SvLBoxEntry* pEntry, const String& rNewText );

    virtual DragDropMode    NotifyStartDrag( TransferDataContainer& rData, SvLBoxEntry* pEntry );
    virtual BOOL            NotifyAcceptDrop( SvLBoxEntry* pEntry );

    virtual BOOL    NotifyMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
                        SvLBoxEntry*& rpNewParent, ULONG& rNewChildPos );
    virtual BOOL    NotifyCopying( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
                        SvLBoxEntry*& rpNewParent, ULONG& rNewChildPos );
    BOOL            NotifyCopyingMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
                        SvLBoxEntry*& rpNewParent, ULONG& rNewChildPos, BOOL bMove );

public:
    ExtBasicTreeListBox( Window* pParent, const ResId& rRes );
    ~ExtBasicTreeListBox();
};

#define LIBMODE_CHOOSER     1
#define LIBMODE_MANAGER     2

class BasicCheckBox : public SvTabListBox
{
private:
    USHORT              nMode;
    SvLBoxButtonData*   pCheckButton;
    SfxObjectShell*     m_pShell;
    void                Init();

public:
                    BasicCheckBox( Window* pParent, const ResId& rResId );
                    ~BasicCheckBox();

    SvLBoxEntry*    InsertEntry( const String& rStr, ULONG nPos = LISTBOX_APPEND );
    void            RemoveEntry( ULONG nPos );
    SvLBoxEntry*    FindEntry( const String& rName );

    void            SelectEntryPos( ULONG nPos, BOOL bSelect = TRUE );
    ULONG           GetSelectEntryPos() const;

    ULONG           GetCheckedEntryCount() const;
    void            CheckEntryPos( ULONG nPos, BOOL bCheck = TRUE );
    BOOL            IsChecked( ULONG nPos ) const;

    virtual void    InitEntry( SvLBoxEntry*, const XubString&, const Image&, const Image& );
    virtual BOOL    EditingEntry( SvLBoxEntry* pEntry, Selection& rSel );
    virtual BOOL    EditedEntry( SvLBoxEntry* pEntry, const String& rNewText );

    void            SetShell( SfxObjectShell* pShell ) { m_pShell = pShell; }

    void            SetMode( USHORT n );
    USHORT          GetMode() const         { return nMode; }
};

class LibDialog: public ModalDialog
{
private:
    OKButton        aOKButton;
    CancelButton    aCancelButton;
    FixedText       aStorageName;
    BasicCheckBox   aLibBox;
    FixedLine       aFixedLine;
    CheckBox        aReferenceBox;
    CheckBox        aReplaceBox;

public:
                    LibDialog( Window* pParent );
                    ~LibDialog();

    void            SetStorageName( const String& rName );

    BasicCheckBox&  GetLibBox()                 { return aLibBox; }
    BOOL            IsReference() const         { return aReferenceBox.IsChecked(); }
    BOOL            IsReplace() const           { return aReplaceBox.IsChecked(); }

    void            EnableReference( BOOL b )   { aReferenceBox.Enable( b ); }
    void            EnableReplace( BOOL b )     { aReplaceBox.Enable( b ); }
};

class OrganizeDialog : public TabDialog
{
private:
    TabControl              aTabCtrl;
    BasicEntryDescriptor    m_aCurEntry;

public:
                    OrganizeDialog( Window* pParent, INT16 tabId, BasicEntryDescriptor& rDesc );
                    ~OrganizeDialog();

    virtual short   Execute();

    DECL_LINK( ActivatePageHdl, TabControl * );
};

class ObjectPage: public TabPage
{
protected:
    FixedText           aLibText;
    ExtBasicTreeListBox aBasicBox;
    PushButton          aEditButton;
    CancelButton        aCloseButton;
    PushButton          aNewModButton;
    PushButton          aNewDlgButton;
    PushButton          aDelButton;

    DECL_LINK( BasicBoxHighlightHdl, BasicTreeListBox * );
    DECL_LINK( ButtonHdl, Button * );
    void                CheckButtons();
    bool                GetSelection( SfxObjectShell*& rpShell, String& rLibName );
    void                DeleteCurrent();
    void                NewModule();
    void                NewDialog();
    void                EndTabDialog( USHORT nRet );

    TabDialog*          pTabDlg;

    virtual void        ActivatePage();
    virtual void        DeactivatePage();

public:
                        ObjectPage( Window* pParent, const ResId& rResId, USHORT nMode );

    void                SetCurrentEntry( BasicEntryDescriptor& rDesc );
    void                SetTabDlg( TabDialog* p ) { pTabDlg = p;}
};

class SvxPasswordDialog;

class LibPage: public TabPage
{
protected:
    FixedText           aBasicsText;
    ListBox             aBasicsBox;
    FixedText           aLibText;
    BasicCheckBox       aLibBox;
    PushButton          aEditButton;
    CancelButton        aCloseButton;
    PushButton          aPasswordButton;
    PushButton          aNewLibButton;
    PushButton          aInsertLibButton;
    PushButton          aDelButton;

    SfxObjectShell*     m_pCurShell;
    LibraryLocation     m_eCurLocation;

    DECL_LINK( TreeListHighlightHdl, SvTreeListBox * );
    DECL_LINK( BasicSelectHdl, ListBox * );
    DECL_LINK( ButtonHdl, Button * );
    DECL_LINK( CheckPasswordHdl, SvxPasswordDialog * );
    void                CheckButtons();
    void                DeleteCurrent();
    void                NewLib();
    void                InsertLib();
    void                EndTabDialog( USHORT nRet );
    void                FillListBox();
    void                InsertListBoxEntry( SfxObjectShell* pShell, LibraryLocation eLocation );
    void                SetCurLib();
    SvLBoxEntry*        ImpInsertLibEntry( const String& rLibName, ULONG nPos );
    virtual void        ActivatePage();
    virtual void        DeactivatePage();

    TabDialog*          pTabDlg;

public:
                        LibPage( Window* pParent );
    virtual             ~LibPage();

    void                SetTabDlg( TabDialog* p ) { pTabDlg = p;}
};

// Helper functions
SbModule* createModImpl( Window* pWin, SfxObjectShell* pShell,
    BasicTreeListBox& rBasicBox, const String& rLibName, String aModName, bool bMain = false );
void createLibImpl( Window* pWin, SfxObjectShell* pShell,
                    BasicCheckBox* pLibBox, BasicTreeListBox* pBasicBox );

#endif // _MODULDLG_HXX
<|endoftext|>


<commit_before>/*

Copyright (c) 2006, Arvid Norberg
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 the author 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.

*/

#ifndef TORRENT_SESSION_STATUS_HPP_INCLUDED
#define TORRENT_SESSION_STATUS_HPP_INCLUDED

namespace libtorrent
{

#ifndef TORRENT_DISABLE_DHT

	struct dht_lookup
	{
		char const* type;
		int outstanding_requests;
		int timeouts;
		int responses;
		int branch_factor;
	};

#endif

	struct TORRENT_EXPORT session_status
	{
		bool has_incoming_connections;

		float upload_rate;
		float download_rate;
		size_type total_download;
		size_type total_upload;

		float payload_upload_rate;
		float payload_download_rate;
		size_type total_payload_download;
		size_type total_payload_upload;

		float ip_overhead_upload_rate;
		float ip_overhead_download_rate;
		size_type total_ip_overhead_download;
		size_type total_ip_overhead_upload;

		float dht_upload_rate;
		float dht_download_rate;
		size_type total_dht_download;
		size_type total_dht_upload;

		float tracker_upload_rate;
		float tracker_download_rate;
		size_type total_tracker_download;
		size_type total_tracker_upload;

		size_type total_redundant_bytes;
		size_type total_failed_bytes;

		int num_peers;
		int num_unchoked;
		int allowed_upload_slots;

		int up_bandwidth_queue;
		int down_bandwidth_queue;

		int optimistic_unchoke_counter;
		int unchoke_counter;

#ifndef TORRENT_DISABLE_DHT
		int dht_nodes;
		int dht_node_cache;
		int dht_torrents;
		size_type dht_global_nodes;
		std::vector<dht_lookup> active_requests;
#endif
	};

}

#endif // TORRENT_SESSION_STATUS_HPP_INCLUDED

<commit_msg>fixed missing includes in header<commit_after>/*

Copyright (c) 2006, Arvid Norberg
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 the author 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.

*/

#ifndef TORRENT_SESSION_STATUS_HPP_INCLUDED
#define TORRENT_SESSION_STATUS_HPP_INCLUDED

#include "libtorrent/config.hpp"
#include "libtorrent/size_type.hpp"

namespace libtorrent
{

#ifndef TORRENT_DISABLE_DHT

	struct dht_lookup
	{
		char const* type;
		int outstanding_requests;
		int timeouts;
		int responses;
		int branch_factor;
	};

#endif

	struct TORRENT_EXPORT session_status
	{
		bool has_incoming_connections;

		float upload_rate;
		float download_rate;
		size_type total_download;
		size_type total_upload;

		float payload_upload_rate;
		float payload_download_rate;
		size_type total_payload_download;
		size_type total_payload_upload;

		float ip_overhead_upload_rate;
		float ip_overhead_download_rate;
		size_type total_ip_overhead_download;
		size_type total_ip_overhead_upload;

		float dht_upload_rate;
		float dht_download_rate;
		size_type total_dht_download;
		size_type total_dht_upload;

		float tracker_upload_rate;
		float tracker_download_rate;
		size_type total_tracker_download;
		size_type total_tracker_upload;

		size_type total_redundant_bytes;
		size_type total_failed_bytes;

		int num_peers;
		int num_unchoked;
		int allowed_upload_slots;

		int up_bandwidth_queue;
		int down_bandwidth_queue;

		int optimistic_unchoke_counter;
		int unchoke_counter;

#ifndef TORRENT_DISABLE_DHT
		int dht_nodes;
		int dht_node_cache;
		int dht_torrents;
		size_type dht_global_nodes;
		std::vector<dht_lookup> active_requests;
#endif
	};

}

#endif // TORRENT_SESSION_STATUS_HPP_INCLUDED

<|endoftext|>