<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 Artem Pavlenko
 *
 * 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; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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 St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#ifndef MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP
#define MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP

// mapnik
#include <mapnik/json/generic_json.hpp>
#include <mapnik/json/error_handler.hpp>
#include <mapnik/box2d.hpp>

// boost
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#pragma GCC diagnostic pop

// stl
#include <tuple>

namespace mapnik { namespace json {

using position = std::tuple<double,double>;
using boxes = std::vector<std::pair<box2d<double>, std::pair<std::size_t, std::size_t>>>;

namespace qi = boost::spirit::qi;

struct calculate_bounding_box_impl
{
    using result_type = void;
    template <typename T0, typename T1>
    result_type operator() (T0 & bbox, T1 const& pos) const
    {
        if (pos)
        {
            double x = std::get<0>(*pos);
            double y = std::get<1>(*pos);
            if (!bbox.valid())
            {
                bbox.init(x, y, x, y); //TODO: add init(x,y) convinience method
            }
            else
            {
                bbox.expand_to_include(x, y);
            }
        }
    }
};

struct push_box_impl
{
    using result_type = void;
    template <typename T0, typename T1, typename T2, typename T3>
    void operator() (T0 & boxes, T1 const& begin, T2 const& box, T3 const& range) const
    {
        if (box.valid()) boxes.emplace_back(box, std::make_pair(std::distance(begin, range.begin()), std::distance(range.begin(), range.end())));
    }
};

template <typename Iterator, typename ErrorHandler = error_handler<Iterator> >
struct extract_bounding_box_grammar :
        qi::grammar<Iterator, void(boxes&), space_type>
{
    extract_bounding_box_grammar();
    // rules
    qi::rule<Iterator, void(boxes&), space_type> start;
    qi::rule<Iterator, qi::locals<Iterator>, void(boxes&), space_type> features;
    qi::rule<Iterator, qi::locals<int, box2d<double>>, void(boxes&, Iterator const&), space_type> feature;
    qi::rule<Iterator, qi::locals<box2d<double>>, box2d<double>(), space_type> coords;
    qi::rule<Iterator, boost::optional<position>(), space_type> pos;
    qi::rule<Iterator, void(box2d<double>&), space_type> ring;
    qi::rule<Iterator, void(box2d<double>&), space_type> rings;
    qi::rule<Iterator, void(box2d<double>&), space_type> rings_array;
    // generic JSON support
    json::generic_json<Iterator> json;
    // phoenix functions
    boost::phoenix::function<push_box_impl> push_box;
    boost::phoenix::function<calculate_bounding_box_impl> calculate_bounding_box;
    // error handler
    boost::phoenix::function<ErrorHandler> const error_handler;
};

}}

#endif // MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP
<commit_msg>update bounsing box grammar to work with mapnik-geometry<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 Artem Pavlenko
 *
 * 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; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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 St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#ifndef MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP
#define MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP

// mapnik
#include <mapnik/json/generic_json.hpp>
#include <mapnik/json/error_handler.hpp>
#include <mapnik/box2d.hpp>
#include <mapnik/geometry_impl.hpp>
// boost
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#pragma GCC diagnostic pop

// stl
#include <tuple>

namespace mapnik { namespace json {

using position = mapnik::new_geometry::point;
using boxes = std::vector<std::pair<box2d<double>, std::pair<std::size_t, std::size_t>>>;

namespace qi = boost::spirit::qi;

struct calculate_bounding_box_impl
{
    using result_type = void;
    template <typename T0, typename T1>
    result_type operator() (T0 & bbox, T1 const& pos) const
    {
        if (pos)
        {
            double x = pos->x;
            double y = pos->y;
            if (!bbox.valid())
            {
                bbox.init(x, y, x, y); //TODO: add init(x,y) convinience method
            }
            else
            {
                bbox.expand_to_include(x, y);
            }
        }
    }
};

struct push_box_impl
{
    using result_type = void;
    template <typename T0, typename T1, typename T2, typename T3>
    void operator() (T0 & boxes, T1 const& begin, T2 const& box, T3 const& range) const
    {
        if (box.valid()) boxes.emplace_back(box, std::make_pair(std::distance(begin, range.begin()), std::distance(range.begin(), range.end())));
    }
};

template <typename Iterator, typename ErrorHandler = error_handler<Iterator> >
struct extract_bounding_box_grammar :
        qi::grammar<Iterator, void(boxes&), space_type>
{
    extract_bounding_box_grammar();
    // rules
    qi::rule<Iterator, void(boxes&), space_type> start;
    qi::rule<Iterator, qi::locals<Iterator>, void(boxes&), space_type> features;
    qi::rule<Iterator, qi::locals<int, box2d<double>>, void(boxes&, Iterator const&), space_type> feature;
    qi::rule<Iterator, qi::locals<box2d<double>>, box2d<double>(), space_type> coords;
    qi::rule<Iterator, boost::optional<position>(), space_type> pos;
    qi::rule<Iterator, void(box2d<double>&), space_type> ring;
    qi::rule<Iterator, void(box2d<double>&), space_type> rings;
    qi::rule<Iterator, void(box2d<double>&), space_type> rings_array;
    // generic JSON support
    json::generic_json<Iterator> json;
    // phoenix functions
    boost::phoenix::function<push_box_impl> push_box;
    boost::phoenix::function<calculate_bounding_box_impl> calculate_bounding_box;
    // error handler
    boost::phoenix::function<ErrorHandler> const error_handler;
};

}}

#endif // MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP
<|endoftext|>


<commit_before>// Copyright (c) 2016 Per Malmberg
// Licensed under MIT, see LICENSE file.

#include "IntegerType.h"

namespace cmdparser4cpp {

//////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////
IntegerType::IntegerType( CmdParser4Cpp& parser, Argument& argument, int minParameterCount, int maxParameterCount )
	: BaseType( parser, argument, minParameterCount, maxParameterCount ),
	  myMatcher(R"!!(^([+-]{0,1}\d*)$)!!")
{
}

//////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////
IntegerType::~IntegerType()
{
}

//////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////
bool
IntegerType::DoTypeParse( const std::string& parameter )
{
	size_t count = myResults.size();

	if( std::regex_match( parameter, myMatcher )) {
		myResults.push_back( parameter );
	}

	// Any new results added?
	return count < myResults.size();
}

//////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////
void
IntegerType::RetrieveResult()
{
	myParser.SetResult( myArgument.GetPrimaryName(), this );
}

//////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////
int
IntegerType::GetResult( int index, int defaultValue ) const
{
	bool res = defaultValue;

	if( index >= 0 && index < static_cast<int>( myResults.size() ) ) {
		return atoi( myResults.at( static_cast<size_t>( index ) ).c_str() );
	}

	return res;
}

} // END cmdparser4cpp<commit_msg>Fixed type error.<commit_after>// Copyright (c) 2016 Per Malmberg
// Licensed under MIT, see LICENSE file.

#include "IntegerType.h"

namespace cmdparser4cpp {

//////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////
IntegerType::IntegerType( CmdParser4Cpp& parser, Argument& argument, int minParameterCount, int maxParameterCount )
	: BaseType( parser, argument, minParameterCount, maxParameterCount ),
	  myMatcher(R"!!(^([+-]{0,1}\d*)$)!!")
{
}

//////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////
IntegerType::~IntegerType()
{
}

//////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////
bool
IntegerType::DoTypeParse( const std::string& parameter )
{
	size_t count = myResults.size();

	if( std::regex_match( parameter, myMatcher )) {
		myResults.push_back( parameter );
	}

	// Any new results added?
	return count < myResults.size();
}

//////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////
void
IntegerType::RetrieveResult()
{
	myParser.SetResult( myArgument.GetPrimaryName(), this );
}

//////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////
int
IntegerType::GetResult( int index, int defaultValue ) const
{
	int res = defaultValue;

	if( index >= 0 && index < static_cast<int>( myResults.size() ) ) {
		res = atoi( myResults.at( static_cast<size_t>( index ) ).c_str() );
	}

	return res;
}

} // END cmdparser4cpp<|endoftext|>


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

  Program:   Visualization Toolkit
  Module:    vtkClientSocket.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkClientSocket.h"

#include "vtkObjectFactory.h"

vtkStandardNewMacro(vtkClientSocket);
//-----------------------------------------------------------------------------
vtkClientSocket::vtkClientSocket()
{
  this->ConnectingSide = false;
}

//-----------------------------------------------------------------------------
vtkClientSocket::~vtkClientSocket()
{
}

//-----------------------------------------------------------------------------
int vtkClientSocket::ConnectToServer(const char* hostName, int port)
{
  if (this->SocketDescriptor != -1)
    {
    vtkWarningMacro("Client connection already exists. Closing it.");
    this->CloseSocket(this->SocketDescriptor);
    this->SocketDescriptor = -1;
    }

  this->SocketDescriptor = this->CreateSocket();
  if (!this->SocketDescriptor)
    {
    vtkErrorMacro("Failed to create socket.");
    return -1;
    }

  if (this->Connect(this->SocketDescriptor, hostName, port) == -1)
    {
    this->CloseSocket(this->SocketDescriptor);
    this->SocketDescriptor = -1;

    vtkErrorMacro("Failed to connect to server " << hostName << ":" << port);
    return -1;
    }

  this->ConnectingSide = true;
  return 0;
}

//-----------------------------------------------------------------------------
void vtkClientSocket::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "ConnectingSide: " << this->ConnectingSide << endl;
}
<commit_msg>BUG: Fix invalid return value check in vtkClientSocket.<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkClientSocket.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkClientSocket.h"

#include "vtkObjectFactory.h"

vtkStandardNewMacro(vtkClientSocket);
//-----------------------------------------------------------------------------
vtkClientSocket::vtkClientSocket()
{
  this->ConnectingSide = false;
}

//-----------------------------------------------------------------------------
vtkClientSocket::~vtkClientSocket()
{
}

//-----------------------------------------------------------------------------
int vtkClientSocket::ConnectToServer(const char* hostName, int port)
{
  if (this->SocketDescriptor != -1)
    {
    vtkWarningMacro("Client connection already exists. Closing it.");
    this->CloseSocket(this->SocketDescriptor);
    this->SocketDescriptor = -1;
    }

  this->SocketDescriptor = this->CreateSocket();
  if (this->SocketDescriptor == -1)
    {
    vtkErrorMacro("Failed to create socket.");
    return -1;
    }

  if (this->Connect(this->SocketDescriptor, hostName, port) == -1)
    {
    this->CloseSocket(this->SocketDescriptor);
    this->SocketDescriptor = -1;

    vtkErrorMacro("Failed to connect to server " << hostName << ":" << port);
    return -1;
    }

  this->ConnectingSide = true;
  return 0;
}

//-----------------------------------------------------------------------------
void vtkClientSocket::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "ConnectingSide: " << this->ConnectingSide << endl;
}
<|endoftext|>


<commit_before><commit_msg>INTEGRATION: CWS dba24 (1.5.260); FILE MERGED 2005/02/09 08:07:52 oj 1.5.260.1: #i26950# remove the need for XNamed<commit_after><|endoftext|>


<commit_before>#pragma once
//=====================================================================//
/*!	@file
	@brief	ルネサス RX ペリフェラル／デバイス選択
    @author 平松邦仁 (hira@rvf-rc45.net)
	@copyright	Copyright (C) 2016, 2022 Kunihito Hiramatsu @n
				Released under the MIT license @n
				https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=====================================================================//
#include "common/byte_order.h"
#include "common/vect.h"
#include "common/delay.hpp"
#include "common/device.hpp"

#if defined(SIG_RX63T)
#include "RX63T/lvda.hpp"
#include "RX63T/bus.hpp"
#include "RX600/dmac.hpp"
#include "RX63T/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX63T/poe3.hpp"
#include "RX63T/gpt.hpp"
#include "RX600/usb.hpp"
#include "RX600/can.hpp"
#include "RX600/crc.hpp"
#include "RX63T/s12adb.hpp"
#include "RX63T/ad.hpp"
#include "RX63T/da.hpp"
#include "RX600/doc.hpp"
#include "RX63T/dpc.hpp"
#include "RX63T/flash.hpp"

#include "RX63T/system_io.hpp"

#elif defined(SIG_RX621) || defined(SIG_RX62N)
#include "RX62x/lvd.hpp"
#include "RX62x/bus.hpp"
#include "RX600/dmac.hpp"
#include "RX600/exdmac.hpp"
#include "RX62x/port.hpp"
#include "RX62x/mtu2.hpp"
#include "RX62x/poe2.hpp"
#include "RX600/ppg.hpp"
#include "RX600/tmr.hpp"
#include "RX62x/rtc.hpp"
#include "RX62x/wdt.hpp"
#include "RX600/etherc.hpp"
#include "RX600/edmac.hpp"
#include "RX62x/usb.hpp"
#include "RX600/crc.hpp"
#include "RX600/can.hpp"
#include "RX62x/s12ad.hpp"
#include "RX62x/ad.hpp"
#include "RX62x/da.hpp"
#include "RX62x/flash.hpp"

#include "RX62x/system_io.hpp"
#include "RX62x/flash_io.hpp"
#include "RX600/dmac_mgr.hpp"
#include "RX24T/dac_out.hpp"

#elif defined(SIG_RX24T)
#include "RX24T/lvda.hpp"
#include "RX600/bus.hpp"
#include "RX600/cac.hpp"
#include "RX600/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX600/poe3.hpp"
#include "RX600/tmr.hpp"
#include "RX600/gpt.hpp"
#include "RX24T/s12ad.hpp"
#include "RX24T/da.hpp"
#include "RX600/cmpc.hpp"
#include "RX24T/flash.hpp"
#include "RX600/crc.hpp"
#include "RX600/doc.hpp"

#include "RX24T/system_io.hpp"
#include "RX24T/flash_io.hpp"
#include "RX24T/adc_in.hpp"
#include "RX24T/dac_out.hpp"

#elif defined(SIG_RX64M) || defined(SIG_RX71M)
#include "RX600/lvda.hpp"
#include "RX600/bus.hpp"
#include "RX600/cac.hpp"
#include "RX600/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX600/poe3.hpp"
#include "RX600/tmr.hpp"
#include "RX600/dmac.hpp"
#include "RX600/elc.hpp"
#include "RX600/exdmac.hpp"
#include "RX600/mpc.hpp"
#include "RX600/tpu.hpp"
#include "RX600/gpt.hpp"
#include "RX600/ppg.hpp"
#include "RX600/cmtw.hpp"
#include "RX600/can.hpp"
#include "RX600/qspi.hpp"
#include "RX600/s12adc.hpp"
#include "RX600/r12da.hpp"
#include "RX600/sdram.hpp"
#include "RX600/etherc.hpp"
#include "RX600/eptpc.hpp"
#include "RX600/edmac.hpp"
#include "RX600/usb.hpp"
#include "RX600/usba.hpp"
#include "RX600/scif.hpp"
#include "RX600/rtc.hpp"
#include "RX600/rtc_io.hpp"
#include "RX600/wdta.hpp"
#include "RX600/flash.hpp"
#include "RX600/ssi.hpp"
#include "RX600/src.hpp"
#include "RX600/sdhi.hpp"
#include "RX600/mmcif.hpp"
#include "RX600/pdc.hpp"
#include "RX600/standby_ram.hpp"
#include "RX600/crc.hpp"
#include "RX600/doc.hpp"

#include "RX600/system_io.hpp"
#include "RX600/dmac_mgr.hpp"
#include "RX600/ether_io.hpp"
#include "RX600/adc_in.hpp"
#include "RX600/dac_out.hpp"
#include "RX600/flash_io.hpp"
#include "RX600/sdhi_io.hpp"
#include "RX600/ssi_io.hpp"

#elif defined(SIG_RX65N)
#include "RX600/lvda.hpp"
#include "RX600/bus.hpp"
#include "RX600/cac.hpp"
#include "RX600/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX600/poe3.hpp"
#include "RX600/tmr.hpp"
#include "RX600/dmac.hpp"
#include "RX600/elc.hpp"
#include "RX600/exdmac.hpp"
#include "RX600/mpc.hpp"
#include "RX600/tpu.hpp"
#include "RX600/ppg.hpp"
#include "RX600/cmtw.hpp"
#include "RX600/qspi.hpp"
#include "RX600/can.hpp"
#include "RX600/s12adf.hpp"
#include "RX600/r12da.hpp"
#include "RX600/sdram.hpp"
#include "RX600/etherc.hpp"
#include "RX600/edmac.hpp"
#include "RX600/usb.hpp"
#include "RX600/rtc.hpp"
#include "RX600/wdta.hpp"
#include "RX600/flash.hpp"
#include "RX600/sdhi.hpp"
#include "RX600/sdsi.hpp"
#include "RX600/mmcif.hpp"
#include "RX600/pdc.hpp"
#include "RX600/standby_ram.hpp"
#include "RX600/glcdc.hpp"
#include "RX600/drw2d.hpp"
#include "RX600/crca.hpp"
#include "RX600/doc.hpp"

#include "RX600/system_io.hpp"
#include "RX600/rtc_io.hpp"
#include "RX600/dmac_mgr.hpp"
#include "RX600/ether_io.hpp"
#include "RX600/sdhi_io.hpp"
#include "RX600/glcdc_mgr.hpp"
#include "RX600/drw2d_mgr.hpp"
#include "RX600/adc_in.hpp"
#include "RX600/dac_out.hpp"
#include "RX600/flash_io.hpp"

#elif defined(SIG_RX72M) || defined(SIG_RX72N)
#include "RX600/lvda.hpp"
#include "RX600/bus.hpp"
#include "RX600/cac.hpp"
#include "RX600/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX600/poe3.hpp"
#include "RX600/tmr.hpp"
#include "RX600/dmac.hpp"
#include "RX600/elc.hpp"
#include "RX600/exdmac.hpp"
#include "RX600/mpc.hpp"
#include "RX600/tpu.hpp"
#include "RX600/ppg.hpp"
#include "RX600/gptw.hpp"
#include "RX600/ppg.hpp"
#include "RX600/cmtw.hpp"
#include "RX600/can.hpp"
#include "RX600/qspi.hpp"
#include "RX600/s12adf.hpp"
#include "RX600/r12da.hpp"
#include "RX600/sdram.hpp"
#include "RX600/etherc.hpp"
#include "RX600/eptpc.hpp"
#include "RX600/edmac.hpp"
#include "RX600/pmgi.hpp"
#include "RX600/usb.hpp"
#include "RX600/scif.hpp"
#include "RX600/rtc.hpp"
#include "RX600/wdta.hpp"
#include "RX600/flash.hpp"
#include "RX600/ssie.hpp"
#include "RX600/sdhi.hpp"
#include "RX600/mmcif.hpp"
#include "RX600/pdc.hpp"
#if defined(SIG_RX72M)
#include "RX600/dsmif.hpp"
#endif
#include "RX600/standby_ram.hpp"
#include "RX600/glcdc.hpp"
#include "RX600/drw2d.hpp"
#include "RX600/crca.hpp"
#include "RX600/doc.hpp"

#include "RX600/system_io.hpp"
#include "RX600/dmac_mgr.hpp"
#include "RX600/rtc_io.hpp"
#include "RX600/sdhi_io.hpp"
#include "RX600/ssie_io.hpp"
#include "RX600/glcdc_mgr.hpp"
#include "RX600/drw2d_mgr.hpp"
#include "RX600/adc_in.hpp"
#include "RX600/dac_out.hpp"
#include "RX600/flash_io.hpp"
#include "RX600/ether_io.hpp"

#elif defined(SIG_RX66T) || defined(SIG_RX72T)
#include "RX600/lvda.hpp"
#include "RX600/bus.hpp"
#include "RX600/cac.hpp"
#include "RX600/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX600/poe3.hpp"
#include "RX600/tmr.hpp"
#include "RX600/dmac.hpp"
#include "RX600/elc.hpp"
#include "RX600/mpc.hpp"
#include "RX600/gptw.hpp"
#include "RX600/hrpwm.hpp"
#include "RX600/poeg.hpp"
#include "RX600/can.hpp"
#include "RX72T/s12adh.hpp"
#include "RX600/r12da.hpp"
#include "RX600/usb.hpp"
#include "RX600/wdta.hpp"
#include "RX600/flash.hpp"
#include "RX600/cmpc.hpp"
#include "RX600/crca.hpp"
#include "RX600/doc.hpp"

#include "RX600/system_io.hpp"
#include "RX600/dmac_mgr.hpp"
#include "RX600/dac_out.hpp"
#include "RX600/flash_io.hpp"

#else
#  error "renesas.hpp: Requires SIG_RXxxx to be defined"
#endif

// RX マイコン共通ペリフェラル
#include "RX600/dtc.hpp"
#include "RX600/cmt.hpp"
#include "RX600/iwdt.hpp"
#include "RX600/sci.hpp"
#include "RX600/riic.hpp"
#include "RX600/rspi.hpp"
#include "RX600/mpu.hpp"
<commit_msg>Update: edit path for poe3.hpp<commit_after>#pragma once
//=====================================================================//
/*!	@file
	@brief	ルネサス RX ペリフェラル／デバイス選択
    @author 平松邦仁 (hira@rvf-rc45.net)
	@copyright	Copyright (C) 2016, 2022 Kunihito Hiramatsu @n
				Released under the MIT license @n
				https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=====================================================================//
#include "common/byte_order.h"
#include "common/vect.h"
#include "common/delay.hpp"
#include "common/device.hpp"

#if defined(SIG_RX63T)
#include "RX63T/lvda.hpp"
#include "RX63T/bus.hpp"
#include "RX600/dmac.hpp"
#include "RX63T/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX63T/poe3.hpp"
#include "RX63T/gpt.hpp"
#include "RX600/usb.hpp"
#include "RX600/can.hpp"
#include "RX600/crc.hpp"
#include "RX63T/s12adb.hpp"
#include "RX63T/ad.hpp"
#include "RX63T/da.hpp"
#include "RX600/doc.hpp"
#include "RX63T/dpc.hpp"
#include "RX63T/flash.hpp"

#include "RX63T/system_io.hpp"

#elif defined(SIG_RX621) || defined(SIG_RX62N)
#include "RX62x/lvd.hpp"
#include "RX62x/bus.hpp"
#include "RX600/dmac.hpp"
#include "RX600/exdmac.hpp"
#include "RX62x/port.hpp"
#include "RX62x/mtu2.hpp"
#include "RX62x/poe2.hpp"
#include "RX600/ppg.hpp"
#include "RX600/tmr.hpp"
#include "RX62x/rtc.hpp"
#include "RX62x/wdt.hpp"
#include "RX600/etherc.hpp"
#include "RX600/edmac.hpp"
#include "RX62x/usb.hpp"
#include "RX600/crc.hpp"
#include "RX600/can.hpp"
#include "RX62x/s12ad.hpp"
#include "RX62x/ad.hpp"
#include "RX62x/da.hpp"
#include "RX62x/flash.hpp"

#include "RX62x/system_io.hpp"
#include "RX62x/flash_io.hpp"
#include "RX600/dmac_mgr.hpp"
#include "RX24T/dac_out.hpp"

#elif defined(SIG_RX24T)
#include "RX24T/lvda.hpp"
#include "RX600/bus.hpp"
#include "RX600/cac.hpp"
#include "RX600/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX24T/poe3.hpp"
#include "RX600/tmr.hpp"
#include "RX600/gpt.hpp"
#include "RX24T/s12ad.hpp"
#include "RX24T/da.hpp"
#include "RX600/cmpc.hpp"
#include "RX24T/flash.hpp"
#include "RX600/crc.hpp"
#include "RX600/doc.hpp"

#include "RX24T/system_io.hpp"
#include "RX24T/flash_io.hpp"
#include "RX24T/adc_in.hpp"
#include "RX24T/dac_out.hpp"

#elif defined(SIG_RX64M) || defined(SIG_RX71M)
#include "RX600/lvda.hpp"
#include "RX600/bus.hpp"
#include "RX600/cac.hpp"
#include "RX600/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX64M/poe3.hpp"
#include "RX600/tmr.hpp"
#include "RX600/dmac.hpp"
#include "RX600/elc.hpp"
#include "RX600/exdmac.hpp"
#include "RX600/mpc.hpp"
#include "RX600/tpu.hpp"
#include "RX600/gpt.hpp"
#include "RX600/ppg.hpp"
#include "RX600/cmtw.hpp"
#include "RX600/can.hpp"
#include "RX600/qspi.hpp"
#include "RX600/s12adc.hpp"
#include "RX600/r12da.hpp"
#include "RX600/sdram.hpp"
#include "RX600/etherc.hpp"
#include "RX600/eptpc.hpp"
#include "RX600/edmac.hpp"
#include "RX600/usb.hpp"
#include "RX600/usba.hpp"
#include "RX600/scif.hpp"
#include "RX600/rtc.hpp"
#include "RX600/rtc_io.hpp"
#include "RX600/wdta.hpp"
#include "RX600/flash.hpp"
#include "RX600/ssi.hpp"
#include "RX600/src.hpp"
#include "RX600/sdhi.hpp"
#include "RX600/mmcif.hpp"
#include "RX600/pdc.hpp"
#include "RX600/standby_ram.hpp"
#include "RX600/crc.hpp"
#include "RX600/doc.hpp"

#include "RX600/system_io.hpp"
#include "RX600/dmac_mgr.hpp"
#include "RX600/ether_io.hpp"
#include "RX600/adc_in.hpp"
#include "RX600/dac_out.hpp"
#include "RX600/flash_io.hpp"
#include "RX600/sdhi_io.hpp"
#include "RX600/ssi_io.hpp"

#elif defined(SIG_RX65N)
#include "RX600/lvda.hpp"
#include "RX600/bus.hpp"
#include "RX600/cac.hpp"
#include "RX600/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX65x/poe3.hpp"
#include "RX600/tmr.hpp"
#include "RX600/dmac.hpp"
#include "RX600/elc.hpp"
#include "RX600/exdmac.hpp"
#include "RX600/mpc.hpp"
#include "RX600/tpu.hpp"
#include "RX600/ppg.hpp"
#include "RX600/cmtw.hpp"
#include "RX600/qspi.hpp"
#include "RX600/can.hpp"
#include "RX600/s12adf.hpp"
#include "RX600/r12da.hpp"
#include "RX600/sdram.hpp"
#include "RX600/etherc.hpp"
#include "RX600/edmac.hpp"
#include "RX600/usb.hpp"
#include "RX600/rtc.hpp"
#include "RX600/wdta.hpp"
#include "RX600/flash.hpp"
#include "RX600/sdhi.hpp"
#include "RX600/sdsi.hpp"
#include "RX600/mmcif.hpp"
#include "RX600/pdc.hpp"
#include "RX600/standby_ram.hpp"
#include "RX600/glcdc.hpp"
#include "RX600/drw2d.hpp"
#include "RX600/crca.hpp"
#include "RX600/doc.hpp"

#include "RX600/system_io.hpp"
#include "RX600/rtc_io.hpp"
#include "RX600/dmac_mgr.hpp"
#include "RX600/ether_io.hpp"
#include "RX600/sdhi_io.hpp"
#include "RX600/glcdc_mgr.hpp"
#include "RX600/drw2d_mgr.hpp"
#include "RX600/adc_in.hpp"
#include "RX600/dac_out.hpp"
#include "RX600/flash_io.hpp"

#elif defined(SIG_RX72M) || defined(SIG_RX72N)
#include "RX600/lvda.hpp"
#include "RX600/bus.hpp"
#include "RX600/cac.hpp"
#include "RX600/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX72N/poe3.hpp"
#include "RX600/tmr.hpp"
#include "RX600/dmac.hpp"
#include "RX600/elc.hpp"
#include "RX600/exdmac.hpp"
#include "RX600/mpc.hpp"
#include "RX600/tpu.hpp"
#include "RX600/ppg.hpp"
#include "RX600/gptw.hpp"
#include "RX600/ppg.hpp"
#include "RX600/cmtw.hpp"
#include "RX600/can.hpp"
#include "RX600/qspi.hpp"
#include "RX600/s12adf.hpp"
#include "RX600/r12da.hpp"
#include "RX600/sdram.hpp"
#include "RX600/etherc.hpp"
#include "RX600/eptpc.hpp"
#include "RX600/edmac.hpp"
#include "RX600/pmgi.hpp"
#include "RX600/usb.hpp"
#include "RX600/scif.hpp"
#include "RX600/rtc.hpp"
#include "RX600/wdta.hpp"
#include "RX600/flash.hpp"
#include "RX600/ssie.hpp"
#include "RX600/sdhi.hpp"
#include "RX600/mmcif.hpp"
#include "RX600/pdc.hpp"
#if defined(SIG_RX72M)
#include "RX600/dsmif.hpp"
#endif
#include "RX600/standby_ram.hpp"
#include "RX600/glcdc.hpp"
#include "RX600/drw2d.hpp"
#include "RX600/crca.hpp"
#include "RX600/doc.hpp"

#include "RX600/system_io.hpp"
#include "RX600/dmac_mgr.hpp"
#include "RX600/rtc_io.hpp"
#include "RX600/sdhi_io.hpp"
#include "RX600/ssie_io.hpp"
#include "RX600/glcdc_mgr.hpp"
#include "RX600/drw2d_mgr.hpp"
#include "RX600/adc_in.hpp"
#include "RX600/dac_out.hpp"
#include "RX600/flash_io.hpp"
#include "RX600/ether_io.hpp"

#elif defined(SIG_RX66T) || defined(SIG_RX72T)
#include "RX600/lvda.hpp"
#include "RX600/bus.hpp"
#include "RX600/cac.hpp"
#include "RX600/port.hpp"
#include "RX600/mtu3.hpp"
#include "RX66T/poe3.hpp"
#include "RX600/tmr.hpp"
#include "RX600/dmac.hpp"
#include "RX600/elc.hpp"
#include "RX600/mpc.hpp"
#include "RX600/gptw.hpp"
#include "RX600/hrpwm.hpp"
#include "RX600/poeg.hpp"
#include "RX600/can.hpp"
#include "RX72T/s12adh.hpp"
#include "RX600/r12da.hpp"
#include "RX600/usb.hpp"
#include "RX600/wdta.hpp"
#include "RX600/flash.hpp"
#include "RX600/cmpc.hpp"
#include "RX600/crca.hpp"
#include "RX600/doc.hpp"

#include "RX600/system_io.hpp"
#include "RX600/dmac_mgr.hpp"
#include "RX600/dac_out.hpp"
#include "RX600/flash_io.hpp"

#else
#  error "renesas.hpp: Requires SIG_RXxxx to be defined"
#endif

// RX マイコン共通ペリフェラル
#include "RX600/dtc.hpp"
#include "RX600/cmt.hpp"
#include "RX600/iwdt.hpp"
#include "RX600/sci.hpp"
#include "RX600/riic.hpp"
#include "RX600/rspi.hpp"
#include "RX600/mpu.hpp"
<|endoftext|>


<commit_before>/******************************************************************************\
 *           ___        __                                                    *
 *          /\_ \    __/\ \                                                   *
 *          \//\ \  /\_\ \ \____    ___   _____   _____      __               *
 *            \ \ \ \/\ \ \ '__`\  /'___\/\ '__`\/\ '__`\  /'__`\             *
 *             \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_           *
 *             /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\          *
 *             \/____/ \/_/\/___/  \/____/ \ \ \/  \ \ \/  \/__/\/_/          *
 *                                          \ \_\   \ \_\                     *
 *                                           \/_/    \/_/                     *
 *                                                                            *
 * Copyright (C) 2011, 2012                                                   *
 * Dominik Charousset <dominik.charousset@haw-hamburg.de>                     *
 *                                                                            *
 * This file is part of libcppa.                                              *
 * libcppa 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, either version 3 of the License                  *
 * or (at your option) any later version.                                     *
 *                                                                            *
 * libcppa 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 libcppa. If not, see <http://www.gnu.org/licenses/>.            *
\******************************************************************************/

#include "cppa/cppa.hpp"
#include "cppa/exception.hpp"
#include "cppa/detail/task_scheduler.hpp"
#include "cppa/detail/abstract_scheduled_actor.hpp"
#include "cppa/detail/yield_interface.hpp"

namespace cppa { namespace detail {

namespace { void dummy_enqueue(void*, abstract_scheduled_actor*) { } }

abstract_scheduled_actor::abstract_scheduled_actor()
    : next(nullptr)
    , m_state(abstract_scheduled_actor::done)
    , m_enqueue_to_scheduler(dummy_enqueue, static_cast<void*>(nullptr), this)
    , m_has_pending_timeout_request(false)
    , m_active_timeout_id(0)
{
}

abstract_scheduled_actor::resume_callback::~resume_callback()
{
}

void abstract_scheduled_actor::quit(std::uint32_t reason)
{
    cleanup(reason);
    throw actor_exited(reason);
}

void abstract_scheduled_actor::enqueue_node(queue_node* node)
{
    if (m_mailbox._push_back(node))
    {
        for (;;)
        {
            int state = m_state.load();
            switch (state)
            {
                case blocked:
                {
                    if (m_state.compare_exchange_weak(state, ready))
                    {
                        m_enqueue_to_scheduler();
                        return;
                    }
                    break;
                }
                case about_to_block:
                {
                    if (m_state.compare_exchange_weak(state, ready))
                    {
                        return;
                    }
                    break;
                }
                default: return;
            }
        }
    }
}

void abstract_scheduled_actor::enqueue(actor* sender, any_tuple&& msg)
{
    enqueue_node(new queue_node(sender, std::move(msg)));
}

void abstract_scheduled_actor::enqueue(actor* sender, const any_tuple& msg)
{
    enqueue_node(new queue_node(sender, msg));
}

int abstract_scheduled_actor::compare_exchange_state(int expected,
                                                     int new_value)
{
    int e = expected;
    do
    {
        if (m_state.compare_exchange_weak(e, new_value))
        {
            return new_value;
        }
    }
    while (e == expected);
    return e;
}

void abstract_scheduled_actor::request_timeout(const util::duration& d)
{
    future_send(this, d, atom(":Timeout"), ++m_active_timeout_id);
    m_has_pending_timeout_request = true;
}

auto abstract_scheduled_actor::filter_msg(const any_tuple& msg) -> filter_result
{
    if (m_pattern(msg))
    {
        auto v0 = *reinterpret_cast<const atom_value*>(msg.at(0));
        auto v1 = *reinterpret_cast<const std::uint32_t*>(msg.at(1));
        if (v0 == atom(":Exit"))
        {
            if (m_trap_exit == false)
            {
                if (v1 != exit_reason::normal)
                {
                    quit(v1);
                }
                return normal_exit_signal;
            }
        }
        else if (v0 == atom(":Timeout"))
        {
            return (v1 == m_active_timeout_id) ? timeout_message
                                               : expired_timeout_message;
        }
    }
    return ordinary_message;
}

auto abstract_scheduled_actor::dq(std::unique_ptr<queue_node>& node,
                                  invoke_rules_base& rules,
                                  queue_node_buffer& buffer) -> dq_result
{
    switch (filter_msg(node->msg))
    {
        case normal_exit_signal:
        case expired_timeout_message:
        {
            // skip message
            return dq_indeterminate;
        }
        case timeout_message:
        {
            // m_active_timeout_id is already invalid
            m_has_pending_timeout_request = false;
            // restore mailbox before calling client
            if (!buffer.empty())
            {
                m_mailbox.push_front(std::move(buffer));
                buffer.clear();
            }
            return dq_timeout_occured;
        }
        default: break;
    }
    auto imd = rules.get_intermediate(node->msg);
    if (imd)
    {
        m_last_dequeued = std::move(node->msg);
        m_last_sender = std::move(node->sender);
        // restore mailbox before invoking imd
        if (!buffer.empty())
        {
            m_mailbox.push_front(std::move(buffer));
            buffer.clear();
        }
        // expire pending request
        if (m_has_pending_timeout_request)
        {
            ++m_active_timeout_id;
            m_has_pending_timeout_request = false;
        }
        imd->invoke();
        return dq_done;
    }
    else
    {
        buffer.push_back(node.release());
        return dq_indeterminate;
    }
}

// dummy

void scheduled_actor_dummy::resume(util::fiber*, resume_callback*)
{
}

void scheduled_actor_dummy::quit(std::uint32_t)
{
}

void scheduled_actor_dummy::dequeue(invoke_rules&)
{
}

void scheduled_actor_dummy::dequeue(timed_invoke_rules&)
{
}

void scheduled_actor_dummy::link_to(intrusive_ptr<actor>&)
{
}

void scheduled_actor_dummy::unlink_from(intrusive_ptr<actor>&)
{
}

bool scheduled_actor_dummy::establish_backlink(intrusive_ptr<actor>&)
{
    return false;
}

bool scheduled_actor_dummy::remove_backlink(intrusive_ptr<actor>&)
{
    return false;
}

void scheduled_actor_dummy::detach(const attachable::token&)
{
}

bool scheduled_actor_dummy::attach(attachable*)
{
    return false;
}

} } // namespace cppa::detail
<commit_msg>coding style<commit_after>/******************************************************************************\
 *           ___        __                                                    *
 *          /\_ \    __/\ \                                                   *
 *          \//\ \  /\_\ \ \____    ___   _____   _____      __               *
 *            \ \ \ \/\ \ \ '__`\  /'___\/\ '__`\/\ '__`\  /'__`\             *
 *             \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_           *
 *             /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\          *
 *             \/____/ \/_/\/___/  \/____/ \ \ \/  \ \ \/  \/__/\/_/          *
 *                                          \ \_\   \ \_\                     *
 *                                           \/_/    \/_/                     *
 *                                                                            *
 * Copyright (C) 2011, 2012                                                   *
 * Dominik Charousset <dominik.charousset@haw-hamburg.de>                     *
 *                                                                            *
 * This file is part of libcppa.                                              *
 * libcppa 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, either version 3 of the License                  *
 * or (at your option) any later version.                                     *
 *                                                                            *
 * libcppa 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 libcppa. If not, see <http://www.gnu.org/licenses/>.            *
\******************************************************************************/

#include "cppa/cppa.hpp"
#include "cppa/exception.hpp"
#include "cppa/detail/task_scheduler.hpp"
#include "cppa/detail/abstract_scheduled_actor.hpp"
#include "cppa/detail/yield_interface.hpp"

namespace cppa { namespace detail {

namespace { void dummy_enqueue(void*, abstract_scheduled_actor*) { } }

abstract_scheduled_actor::abstract_scheduled_actor()
    : next(nullptr)
    , m_state(abstract_scheduled_actor::done)
    , m_enqueue_to_scheduler(dummy_enqueue, static_cast<void*>(nullptr), this)
    , m_has_pending_timeout_request(false)
    , m_active_timeout_id(0)
{
}

abstract_scheduled_actor::resume_callback::~resume_callback()
{
}

void abstract_scheduled_actor::quit(std::uint32_t reason)
{
    cleanup(reason);
    throw actor_exited(reason);
}

void abstract_scheduled_actor::enqueue_node(queue_node* node)
{
    if (m_mailbox._push_back(node))
    {
        for (;;)
        {
            int state = m_state.load();
            switch (state)
            {
                case blocked:
                {
                    if (m_state.compare_exchange_weak(state, ready))
                    {
                        m_enqueue_to_scheduler();
                        return;
                    }
                    break;
                }
                case about_to_block:
                {
                    if (m_state.compare_exchange_weak(state, ready))
                    {
                        return;
                    }
                    break;
                }
                default: return;
            }
        }
    }
}

void abstract_scheduled_actor::enqueue(actor* sender, any_tuple&& msg)
{
    enqueue_node(new queue_node(sender, std::move(msg)));
}

void abstract_scheduled_actor::enqueue(actor* sender, any_tuple const& msg)
{
    enqueue_node(new queue_node(sender, msg));
}

int abstract_scheduled_actor::compare_exchange_state(int expected,
                                                     int new_value)
{
    int e = expected;
    do
    {
        if (m_state.compare_exchange_weak(e, new_value))
        {
            return new_value;
        }
    }
    while (e == expected);
    return e;
}

void abstract_scheduled_actor::request_timeout(util::duration const& d)
{
    future_send(this, d, atom(":Timeout"), ++m_active_timeout_id);
    m_has_pending_timeout_request = true;
}

auto abstract_scheduled_actor::filter_msg(const any_tuple& msg) -> filter_result
{
    if (m_pattern(msg))
    {
        auto v0 = *reinterpret_cast<const atom_value*>(msg.at(0));
        auto v1 = *reinterpret_cast<const std::uint32_t*>(msg.at(1));
        if (v0 == atom(":Exit"))
        {
            if (m_trap_exit == false)
            {
                if (v1 != exit_reason::normal)
                {
                    quit(v1);
                }
                return normal_exit_signal;
            }
        }
        else if (v0 == atom(":Timeout"))
        {
            return (v1 == m_active_timeout_id) ? timeout_message
                                               : expired_timeout_message;
        }
    }
    return ordinary_message;
}

auto abstract_scheduled_actor::dq(std::unique_ptr<queue_node>& node,
                                  invoke_rules_base& rules,
                                  queue_node_buffer& buffer) -> dq_result
{
    switch (filter_msg(node->msg))
    {
        case normal_exit_signal:
        case expired_timeout_message:
        {
            // skip message
            return dq_indeterminate;
        }
        case timeout_message:
        {
            // m_active_timeout_id is already invalid
            m_has_pending_timeout_request = false;
            // restore mailbox before calling client
            if (!buffer.empty())
            {
                m_mailbox.push_front(std::move(buffer));
                buffer.clear();
            }
            return dq_timeout_occured;
        }
        default: break;
    }
    auto imd = rules.get_intermediate(node->msg);
    if (imd)
    {
        m_last_dequeued = std::move(node->msg);
        m_last_sender = std::move(node->sender);
        // restore mailbox before invoking imd
        if (!buffer.empty())
        {
            m_mailbox.push_front(std::move(buffer));
            buffer.clear();
        }
        // expire pending request
        if (m_has_pending_timeout_request)
        {
            ++m_active_timeout_id;
            m_has_pending_timeout_request = false;
        }
        imd->invoke();
        return dq_done;
    }
    else
    {
        buffer.push_back(node.release());
        return dq_indeterminate;
    }
}

// dummy

void scheduled_actor_dummy::resume(util::fiber*, resume_callback*)
{
}

void scheduled_actor_dummy::quit(std::uint32_t)
{
}

void scheduled_actor_dummy::dequeue(invoke_rules&)
{
}

void scheduled_actor_dummy::dequeue(timed_invoke_rules&)
{
}

void scheduled_actor_dummy::link_to(intrusive_ptr<actor>&)
{
}

void scheduled_actor_dummy::unlink_from(intrusive_ptr<actor>&)
{
}

bool scheduled_actor_dummy::establish_backlink(intrusive_ptr<actor>&)
{
    return false;
}

bool scheduled_actor_dummy::remove_backlink(intrusive_ptr<actor>&)
{
    return false;
}

void scheduled_actor_dummy::detach(attachable::token const&)
{
}

bool scheduled_actor_dummy::attach(attachable*)
{
    return false;
}

} } // namespace cppa::detail
<|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 "mitkCommon.h"
#include "mitkTestingMacros.h"
#include <mitkLog.h>
#include <mitkVector.h>
#include <itkMultiThreader.h>
#include <itksys/SystemTools.hxx>
#include <mitkStandardFileLocations.h>

/** Documentation
  *
  * @brief Objects of this class can start an internal thread by calling the Start() method.
  *        The thread is then logging messages until the method Stop() is called. The class
  *        can be used to test if logging is thread-save by using multiple objects and let
  *        them log simuntanously.
  */
class mitkTestLoggingThread : public itk::Object
{
public:

mitkClassMacro(mitkTestLoggingThread,itk::Object);
mitkNewMacro1Param(mitkTestLoggingThread,itk::MultiThreader::Pointer);

int NumberOfMessages;

protected:

mitkTestLoggingThread(itk::MultiThreader::Pointer MultiThreader)
  {
  ThreadID = -1;
  NumberOfMessages = 0;
  m_MultiThreader = MultiThreader;
  }

bool LoggingRunning;

int ThreadID;

itk::MultiThreader::Pointer m_MultiThreader;

void LogMessages()
  {

  while(LoggingRunning)
    {
    MITK_INFO << "Test info stream in thread" << ThreadID << "\n even with newlines";
    MITK_WARN << "Test warning stream in thread " << ThreadID <<". "
              << "Even with a very long text, even without meaning or implied meaning or content, just a long sentence to see whether something has problems with long sentences or output in files or into windows or commandlines or whatever.";
    MITK_DEBUG << "Test debugging stream in thread " << ThreadID;
    MITK_ERROR << "Test error stream in thread " << ThreadID;
    MITK_FATAL << "Test fatal stream in thread " << ThreadID;

    NumberOfMessages += 5;
    }
  }

static ITK_THREAD_RETURN_TYPE ThreadStartTracking(void* pInfoStruct)
  {
  /* extract this pointer from Thread Info structure */
  struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct;
  if (pInfo == NULL)
  {
    return ITK_THREAD_RETURN_VALUE;
  }
  if (pInfo->UserData == NULL)
  {
    return ITK_THREAD_RETURN_VALUE;
  }
  mitkTestLoggingThread *thisthread = (mitkTestLoggingThread*)pInfo->UserData;

  if (thisthread != NULL)
    thisthread->LogMessages();

  return ITK_THREAD_RETURN_VALUE;
  }

public:

int Start()
  {
  LoggingRunning = true;
  this->ThreadID = m_MultiThreader->SpawnThread(this->ThreadStartTracking, this);
  return ThreadID;
  }

void Stop()
  {
  LoggingRunning = false;
  }

};

/** Documentation
 *
 *  @brief This class holds static test methods to sturcture the test of the mitk logging mechanism.
 */
class mitkLogTestClass
{

public:

static void TestSimpleLog()
    {
    bool testSucceded = true;
    try
      {
      MITK_INFO << "Test info stream.";
      MITK_WARN << "Test warning stream.";
      MITK_DEBUG << "Test debugging stream."; //only activated if cmake variable is on!
                                              //so no worries if you see no output for this line
      MITK_ERROR << "Test error stream.";
      MITK_FATAL << "Test fatal stream.";
      }
    catch(mitk::Exception e)
      {
      testSucceded = false;
      }
    MITK_TEST_CONDITION_REQUIRED(testSucceded,"Test logging streams.");
    }

static void TestObjectInfoLogging()
    {
    bool testSucceded = true;
    try
      {
      int i = 123;
      float f = .32234;
      double d = 123123;
      std::string testString = "testString";
      std::stringstream testStringStream;
      testStringStream << "test" << "String" << "Stream";
      mitk::Point3D testMitkPoint;
      testMitkPoint.Fill(2);

      MITK_INFO << i;
      MITK_INFO << f;
      MITK_INFO << d;
      MITK_INFO << testString;
      MITK_INFO << testStringStream;
      MITK_INFO << testMitkPoint;
      }
    catch(mitk::Exception e)
      {
      testSucceded = false;
      }
    MITK_TEST_CONDITION_REQUIRED(testSucceded,"Test logging of object information.");
    }

static void TestThreadSaveLog()
    {
    bool testSucceded = true;

    try
      {
        std::string filename = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + "/testthreadlog.log";
        mitk::LoggingBackend::SetLogFile(filename.c_str());

        unsigned int numberOfThreads = 20;
        unsigned int threadRuntimeInMilliseconds = 2000;

        std::vector<unsigned int> threadIDs;
        std::vector<mitkTestLoggingThread::Pointer> threads;

        itk::MultiThreader::Pointer multiThreader = itk::MultiThreader::New();
        for (unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
        {
          //initialize threads...
          mitkTestLoggingThread::Pointer newThread = mitkTestLoggingThread::New(multiThreader);
          threads.push_back(newThread);
          std::cout << "Created " << threadIdx << ". thread." << std::endl;
        }

        for (unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
        {
          //start them
          std::cout << "Start " << threadIdx << ". thread." << std::endl;
          threadIDs.push_back( threads[threadIdx]->Start() );
          std::cout << threadIdx << ". thread has ID " << threadIDs[threadIdx] << std::endl;
        }

        //wait for some time (milliseconds)
        itksys::SystemTools::Delay( threadRuntimeInMilliseconds );

        for (unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
        {
          //stop them
          std::cout << "Stop " << threadIdx << ". thread." << std::endl;
          threads[threadIdx]->Stop();
        }

        for (unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
        {
          //Wait for all threads to end
          multiThreader->TerminateThread(threadIDs[threadIdx]);
          std::cout << "Terminated " << threadIdx << ". thread (" << threads[threadIdx]->NumberOfMessages << " messages)." << std::endl;
        }

      }
    catch(std::exception e)
      {
        MITK_ERROR << "exception during 'TestThreadSaveLog': "<<e.what();
        testSucceded = false;
      }
    catch(...)
      {
        MITK_ERROR << "unknown exception during 'TestThreadSaveLog'";
        testSucceded = false;
      }

    //if no error occured until now, everything is ok
    MITK_TEST_CONDITION_REQUIRED(testSucceded,"Test logging in different threads.");
    }

static void TestLoggingToFile()
    {
    std::string filename = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + "/testlog.log";
    mitk::LoggingBackend::SetLogFile(filename.c_str());
    MITK_INFO << "Test logging to default filename: " << mitk::LoggingBackend::GetLogFile();
    MITK_TEST_CONDITION_REQUIRED(itksys::SystemTools::FileExists(filename.c_str()),"Testing if log file exists.");
    //TODO delete log file?
    }

static void TestAddAndRemoveBackends()
    {
    mbilog::BackendCout myBackend = mbilog::BackendCout();
    mbilog::RegisterBackend(&myBackend);
    MITK_INFO << "Test logging";
    mbilog::UnregisterBackend(&myBackend);

    //if no error occured until now, everything is ok
    MITK_TEST_CONDITION_REQUIRED(true,"Test add/remove logging backend.");
    }

static void  TestDefaultBackend()
    {
    //not possible now, because we cannot unregister the mitk logging backend in the moment. If such a method is added to mbilog utility one may add this test.
    }

};

int mitkLogTest(int /* argc */, char* /*argv*/[])
{
  // always start with this!
  MITK_TEST_BEGIN("Log")

  MITK_TEST_OUTPUT(<<"TESTING ALL LOGGING OUTPUTS, ERROR MESSAGES ARE ALSO TESTED AND NOT MEANING AN ERROR OCCURED!")

  mitkLogTestClass::TestSimpleLog();
  mitkLogTestClass::TestObjectInfoLogging();

  mitkLogTestClass::TestLoggingToFile();
  mitkLogTestClass::TestAddAndRemoveBackends();
  mitkLogTestClass::TestThreadSaveLog();

  // always end with this!
  MITK_TEST_END()
}
<commit_msg>Test logging to console AND to file<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 "mitkCommon.h"
#include "mitkTestingMacros.h"
#include <mitkLog.h>
#include <mitkVector.h>
#include <itkMultiThreader.h>
#include <itksys/SystemTools.hxx>
#include <mitkStandardFileLocations.h>

/** Documentation
  *
  * @brief Objects of this class can start an internal thread by calling the Start() method.
  *        The thread is then logging messages until the method Stop() is called. The class
  *        can be used to test if logging is thread-save by using multiple objects and let
  *        them log simuntanously.
  */
class mitkTestLoggingThread : public itk::Object
{
public:

mitkClassMacro(mitkTestLoggingThread,itk::Object);
mitkNewMacro1Param(mitkTestLoggingThread,itk::MultiThreader::Pointer);

int NumberOfMessages;

protected:

mitkTestLoggingThread(itk::MultiThreader::Pointer MultiThreader)
  {
  ThreadID = -1;
  NumberOfMessages = 0;
  m_MultiThreader = MultiThreader;
  }

bool LoggingRunning;

int ThreadID;

itk::MultiThreader::Pointer m_MultiThreader;

void LogMessages()
  {

  while(LoggingRunning)
    {
    MITK_INFO << "Test info stream in thread" << ThreadID << "\n even with newlines";
    MITK_WARN << "Test warning stream in thread " << ThreadID <<". "
              << "Even with a very long text, even without meaning or implied meaning or content, just a long sentence to see whether something has problems with long sentences or output in files or into windows or commandlines or whatever.";
    MITK_DEBUG << "Test debugging stream in thread " << ThreadID;
    MITK_ERROR << "Test error stream in thread " << ThreadID;
    MITK_FATAL << "Test fatal stream in thread " << ThreadID;

    NumberOfMessages += 5;
    }
  }

static ITK_THREAD_RETURN_TYPE ThreadStartTracking(void* pInfoStruct)
  {
  /* extract this pointer from Thread Info structure */
  struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct;
  if (pInfo == NULL)
  {
    return ITK_THREAD_RETURN_VALUE;
  }
  if (pInfo->UserData == NULL)
  {
    return ITK_THREAD_RETURN_VALUE;
  }
  mitkTestLoggingThread *thisthread = (mitkTestLoggingThread*)pInfo->UserData;

  if (thisthread != NULL)
    thisthread->LogMessages();

  return ITK_THREAD_RETURN_VALUE;
  }

public:

int Start()
  {
  LoggingRunning = true;
  this->ThreadID = m_MultiThreader->SpawnThread(this->ThreadStartTracking, this);
  return ThreadID;
  }

void Stop()
  {
  LoggingRunning = false;
  }

};

/** Documentation
 *
 *  @brief This class holds static test methods to sturcture the test of the mitk logging mechanism.
 */
class mitkLogTestClass
{

public:

static void TestSimpleLog()
    {
    bool testSucceded = true;
    try
      {
      MITK_INFO << "Test info stream.";
      MITK_WARN << "Test warning stream.";
      MITK_DEBUG << "Test debugging stream."; //only activated if cmake variable is on!
                                              //so no worries if you see no output for this line
      MITK_ERROR << "Test error stream.";
      MITK_FATAL << "Test fatal stream.";
      }
    catch(mitk::Exception e)
      {
      testSucceded = false;
      }
    MITK_TEST_CONDITION_REQUIRED(testSucceded,"Test logging streams.");
    }

static void TestObjectInfoLogging()
    {
    bool testSucceded = true;
    try
      {
      int i = 123;
      float f = .32234;
      double d = 123123;
      std::string testString = "testString";
      std::stringstream testStringStream;
      testStringStream << "test" << "String" << "Stream";
      mitk::Point3D testMitkPoint;
      testMitkPoint.Fill(2);

      MITK_INFO << i;
      MITK_INFO << f;
      MITK_INFO << d;
      MITK_INFO << testString;
      MITK_INFO << testStringStream;
      MITK_INFO << testMitkPoint;
      }
    catch(mitk::Exception e)
      {
      testSucceded = false;
      }
    MITK_TEST_CONDITION_REQUIRED(testSucceded,"Test logging of object information.");
    }

static void TestThreadSaveLog(bool toFile)
    {
    bool testSucceded = true;

    try
      {
        if (toFile)
        {
          std::string filename = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + "/testthreadlog.log";
          mitk::LoggingBackend::SetLogFile(filename.c_str());
        }

        unsigned int numberOfThreads = 20;
        unsigned int threadRuntimeInMilliseconds = 2000;

        std::vector<unsigned int> threadIDs;
        std::vector<mitkTestLoggingThread::Pointer> threads;

        itk::MultiThreader::Pointer multiThreader = itk::MultiThreader::New();
        for (unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
        {
          //initialize threads...
          mitkTestLoggingThread::Pointer newThread = mitkTestLoggingThread::New(multiThreader);
          threads.push_back(newThread);
          std::cout << "Created " << threadIdx << ". thread." << std::endl;
        }

        for (unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
        {
          //start them
          std::cout << "Start " << threadIdx << ". thread." << std::endl;
          threadIDs.push_back( threads[threadIdx]->Start() );
          std::cout << threadIdx << ". thread has ID " << threadIDs[threadIdx] << std::endl;
        }

        //wait for some time (milliseconds)
        itksys::SystemTools::Delay( threadRuntimeInMilliseconds );

        for (unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
        {
          //stop them
          std::cout << "Stop " << threadIdx << ". thread." << std::endl;
          threads[threadIdx]->Stop();
        }

        for (unsigned int threadIdx = 0; threadIdx < numberOfThreads; ++threadIdx)
        {
          //Wait for all threads to end
          multiThreader->TerminateThread(threadIDs[threadIdx]);
          std::cout << "Terminated " << threadIdx << ". thread (" << threads[threadIdx]->NumberOfMessages << " messages)." << std::endl;
        }

      }
    catch(std::exception e)
      {
        MITK_ERROR << "exception during 'TestThreadSaveLog': "<<e.what();
        testSucceded = false;
      }
    catch(...)
      {
        MITK_ERROR << "unknown exception during 'TestThreadSaveLog'";
        testSucceded = false;
      }

    //if no error occured until now, everything is ok
    MITK_TEST_CONDITION_REQUIRED(testSucceded,"Test logging in different threads.");
    }

static void TestLoggingToFile()
    {
    std::string filename = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + "/testlog.log";
    mitk::LoggingBackend::SetLogFile(filename.c_str());
    MITK_INFO << "Test logging to default filename: " << mitk::LoggingBackend::GetLogFile();
    MITK_TEST_CONDITION_REQUIRED(itksys::SystemTools::FileExists(filename.c_str()),"Testing if log file exists.");
    //TODO delete log file?
    }

static void TestAddAndRemoveBackends()
    {
    mbilog::BackendCout myBackend = mbilog::BackendCout();
    mbilog::RegisterBackend(&myBackend);
    MITK_INFO << "Test logging";
    mbilog::UnregisterBackend(&myBackend);

    //if no error occured until now, everything is ok
    MITK_TEST_CONDITION_REQUIRED(true,"Test add/remove logging backend.");
    }

static void  TestDefaultBackend()
    {
    //not possible now, because we cannot unregister the mitk logging backend in the moment. If such a method is added to mbilog utility one may add this test.
    }

};

int mitkLogTest(int /* argc */, char* /*argv*/[])
{
  // always start with this!
  MITK_TEST_BEGIN("Log")

  MITK_TEST_OUTPUT(<<"TESTING ALL LOGGING OUTPUTS, ERROR MESSAGES ARE ALSO TESTED AND NOT MEANING AN ERROR OCCURED!")

  mitkLogTestClass::TestSimpleLog();
  mitkLogTestClass::TestObjectInfoLogging();

  mitkLogTestClass::TestLoggingToFile();
  mitkLogTestClass::TestAddAndRemoveBackends();
  mitkLogTestClass::TestThreadSaveLog( false ); // false = to console
  mitkLogTestClass::TestThreadSaveLog( true );  // true = to file
  // TODO actually test file somehow?

  // always end with this!
  MITK_TEST_END()
}
<|endoftext|>


<commit_before>/**
 * @file      ac_tlm_port.cpp
 * @author    Thiago Massariolli Sigrist
 *
 * @author    The ArchC Team
 *            http://www.archc.org/
 *
 *            Computer Systems Laboratory (LSC)
 *            IC-UNICAMP
 *            http://www.lsc.ic.unicamp.br/
 *
 * @version   2.0alpha1
 * @date      Tue, 13 Dec 2005 20:09:00 -0200
 *
 * @brief     ArchC TLM initiator port class implementation.
 *
 * @attention Copyright (C) 2002-2005 --- The ArchC Team
 *
 *   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; either
 *   version 2.1 of the License, or (at your option) any later version.
 *
 *   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.
 *
 *
 */

//////////////////////////////////////////////////////////////////////////////

// Standard includes

// SystemC includes

// ArchC includes
#include "ac_tlm_port.H"

//////////////////////////////////////////////////////////////////////////////

// using statements

//////////////////////////////////////////////////////////////////////////////

// Forward class declarations, needed to compile

//////////////////////////////////////////////////////////////////////////////

// Constructors

/**
 * Default constructor.
 *
 * @param size Size or address range of the element to be attached.
 *
 */
ac_tlm_port::ac_tlm_port(char const* nm, uint32_t sz) : name(nm), size(sz) {}

//////////////////////////////////////////////////////////////////////////////

// Methods

/**
 * Reads a single word.
 *
 * @param buf Buffer into which the word will be copied.
 * @param address Address from where the word will be read.
 * @param wordsize Word size in bits.
 *
 */
void ac_tlm_port::read(ac_ptr buf, uint32_t address, int wordsize) {
  ac_tlm_req req;
  ac_tlm_rsp rsp;

  req.type = READ;
  req.addr = address;
  req.data = 0ULL;

  rsp = (*this)->transport(req);

  if (rsp.status == SUCCESS) {
    switch (wordsize) {
    case 8:
      *(buf.ptr8) = (uint8_t) rsp.data;
      break;
    case 16:
      *(buf.ptr16) = (uint16_t) rsp.data;
      break;
    case 32:
      *(buf.ptr32) = (uint32_t) rsp.data;
      break;
    case 64:
      *(buf.ptr64) = rsp.data;
      break;
    default:
      break;
    }
  }
}

/**
 * Reads multiple words.
 *
 * @param buf Buffer into which the words will be copied.
 * @param address Address from where the words will be read.
 * @param wordsize Word size in bits.
 * @param n_words Number of words to be read.
 *
 */
void ac_tlm_port::read(ac_ptr buf, uint32_t address,
		       int wordsize, int n_words) {
  ac_tlm_req req;
  ac_tlm_rsp rsp;

  req.type = READ;

  switch (wordsize) {
  case 8:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + i;
      req.data = 0ULL;

      rsp = (*this)->transport(req);

      if (rsp.status == SUCCESS) {
	for (int j = 0; (i < n_words) && (j < 8); i++, j++) {
	  (buf.ptr8)[i] = ((uint8_t*)&rsp.data)[j];
	}
      }
    }
    break;
  case 16:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + (i * sizeof(uint16_t));
      req.data = 0ULL;

      rsp = (*this)->transport(req);

      if (rsp.status == SUCCESS) {
	for (int j = 0; (i < n_words) && (j < 4); i++, j++) {
	  (buf.ptr16)[i] = ((uint16_t*)&rsp.data)[j];
	}
      }
    }
    break;
  case 32:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + (i * sizeof(uint32_t));
      req.data = 0ULL;

      rsp = (*this)->transport(req);

      if (rsp.status == SUCCESS) {
	for (int j = 0; (i < n_words) && (j < 2); i++, j++) {
	  (buf.ptr32)[i] = ((uint32_t*)&rsp.data)[j];
	}
      }
    }
    break;
  case 64:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + (i * sizeof(uint64_t));
      req.data = 0ULL;

      rsp = (*this)->transport(req);

      if (rsp.status == SUCCESS) {
	(buf.ptr64)[i] = rsp.data;
      }
    }
    break;
  default:
    break;
  }
}

/**
 * Writes a single word.
 *
 * @param buf Buffer from which the word will be copied.
 * @param address Address to where the word will be written.
 * @param wordsize Word size in bits.
 *
 */
void ac_tlm_port::write(ac_ptr buf, uint32_t address, int wordsize) {
  ac_tlm_req req;
  ac_tlm_rsp rsp;

//   req.type = WRITE;
//   req.addr = address;

  // It would be necessary to read 64 bits and mix the bits with the smaller
  // words that will be written
  switch (wordsize) {
  case 8:
    req.type = READ;
    req.addr = address && 0xfffff000;
    rsp = (*this)->transport(req);

    req.type = WRITE;
    ((uint8_t*)&(req.data))[address % sizeof(uint64_t)] = *(buf.ptr8);
    rsp = (*this)->transport(req);
    break;
  case 16:
    req.type = READ;
    req.addr = address && 0xfffff000;
    rsp = (*this)->transport(req);

    req.type = WRITE;
    ((uint16_t*)&(req.data))[(address % sizeof(uint64_t)) >> 1] =
      *(buf.ptr16);
    rsp = (*this)->transport(req);
    break;
  case 32:
    req.type = READ;
    req.addr = address && 0xfffff000;
    rsp = (*this)->transport(req);

    req.type = WRITE;
    ((uint32_t*)&(req.data))[(address % sizeof(uint64_t)) >> 2] =
      *(buf.ptr32);
    rsp = (*this)->transport(req);
    break;
  case 64:
    req.type = WRITE;
    req.addr = address;
    req.data = *(buf.ptr64);
    rsp = (*this)->transport(req);
    break;
  default:
    break;
  }
}

/**
 * Writes multiple words.
 *
 * @param buf Buffer from which the words will be copied.
 * @param address Address to where the words will be written.
 * @param wordsize Word size in bits.
 * @param n_words Number of words to be written.
 *
 */
void ac_tlm_port::write(ac_ptr buf, uint32_t address,
			int wordsize, int n_words) {
  ac_tlm_req req;
  ac_tlm_rsp rsp;

  req.type = WRITE;

  switch (wordsize) {
  case 8:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + i;
      for (int j = 0; (i < n_words) && (j < 8); j++, i++) {
	((uint8_t*)&req.data)[j] = (buf.ptr8)[i];
      }
      (*this)->transport(req);
    }
    break;
  case 16:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + (i * sizeof(uint16_t));
      for (int j = 0; (i < n_words) && (j < 4); j++, i++) {
	((uint16_t*)&req.data)[j] = (buf.ptr16)[i];
      }
      (*this)->transport(req);
    }
    break;
  case 32:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + (i * sizeof(uint32_t));
      for (int j = 0; (i < n_words) && (j < 2); j++, i++) {
	((uint32_t*)&req.data)[j] = (buf.ptr32)[i];
      }
      (*this)->transport(req);
    }
    break;
  case 64:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + (i * sizeof(uint64_t));
      req.data = (buf.ptr64)[i];
      (*this)->transport(req);
    }
    break;
  default:
    break;
  }
}

uint32_t ac_tlm_port::get_size() const {
  return size;
}

//////////////////////////////////////////////////////////////////////////////

// Destructors

/**
 * Default (virtual) destructor.
 * @return Nothing.
 */
ac_tlm_port::~ac_tlm_port() {}

//////////////////////////////////////////////////////////////////////////////

<commit_msg>Ported bugfixes from Bruno Albertini to ac_tlm_port.<commit_after>/**
 * @file      ac_tlm_port.cpp
 * @author    Thiago Massariolli Sigrist
 *
 * @author    The ArchC Team
 *            http://www.archc.org/
 *
 *            Computer Systems Laboratory (LSC)
 *            IC-UNICAMP
 *            http://www.lsc.ic.unicamp.br/
 *
 * @version   2.0alpha1
 * @date      Tue, 13 Dec 2005 20:09:00 -0200
 *
 * @brief     ArchC TLM initiator port class implementation.
 *
 * @attention Copyright (C) 2002-2005 --- The ArchC Team
 *
 *   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; either
 *   version 2.1 of the License, or (at your option) any later version.
 *
 *   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.
 *
 *
 */

//////////////////////////////////////////////////////////////////////////////

// Standard includes

// SystemC includes

// ArchC includes
#include "ac_tlm_port.H"

//////////////////////////////////////////////////////////////////////////////

// using statements

//////////////////////////////////////////////////////////////////////////////

// Forward class declarations, needed to compile

//////////////////////////////////////////////////////////////////////////////

// Constructors

/**
 * Default constructor.
 *
 * @param size Size or address range of the element to be attached.
 *
 */
ac_tlm_port::ac_tlm_port(char const* nm, uint32_t sz) : name(nm), size(sz) {}

//////////////////////////////////////////////////////////////////////////////

// Methods

/**
 * Reads a single word.
 *
 * @param buf Buffer into which the word will be copied.
 * @param address Address from where the word will be read.
 * @param wordsize Word size in bits.
 *
 */
void ac_tlm_port::read(ac_ptr buf, uint32_t address, int wordsize) {
  ac_tlm_req req;
  ac_tlm_rsp rsp;

  req.type = READ;
  req.addr = address;
  req.data = 0ULL;

  rsp = (*this)->transport(req);

  if (rsp.status == SUCCESS) {
    switch (wordsize) {
    case 8:
      *(buf.ptr8) = ((uint8_t*)&rsp.data)[0];
      break;
    case 16:
      *(buf.ptr16) = ((uint16_t*)&rsp.data)[0];
      break;
    case 32:
      *(buf.ptr32) = ((uint32_t*)&rsp.data)[0];
      break;
    case 64:
      *(buf.ptr64) = rsp.data;
      break;
    default:
      break;
    }
  }
}

/**
 * Reads multiple words.
 *
 * @param buf Buffer into which the words will be copied.
 * @param address Address from where the words will be read.
 * @param wordsize Word size in bits.
 * @param n_words Number of words to be read.
 *
 */
void ac_tlm_port::read(ac_ptr buf, uint32_t address,
		       int wordsize, int n_words) {
  ac_tlm_req req;
  ac_tlm_rsp rsp;

  req.type = READ;

  switch (wordsize) {
  case 8:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + i;
      req.data = 0ULL;

      rsp = (*this)->transport(req);

      if (rsp.status == SUCCESS) {
	for (int j = 0; (i < n_words) && (j < 8); i++, j++) {
	  (buf.ptr8)[i] = ((uint8_t*)&rsp.data)[j];
	}
        i--;
      }
    }
    break;
  case 16:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + (i * sizeof(uint16_t));
      req.data = 0ULL;

      rsp = (*this)->transport(req);

      if (rsp.status == SUCCESS) {
	for (int j = 0; (i < n_words) && (j < 4); i++, j++) {
	  (buf.ptr16)[i] = ((uint16_t*)&rsp.data)[j];
	}
        i--;
      }
    }
    break;
  case 32:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + (i * sizeof(uint32_t));
      req.data = 0ULL;

      rsp = (*this)->transport(req);

      if (rsp.status == SUCCESS) {
	for (int j = 0; (i < n_words) && (j < 2); i++, j++) {
	  (buf.ptr32)[i] = ((uint32_t*)&rsp.data)[j];
	}
        i--;
      }
    }
    break;
  case 64:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + (i * sizeof(uint64_t));
      req.data = 0ULL;

      rsp = (*this)->transport(req);

      if (rsp.status == SUCCESS) {
	(buf.ptr64)[i] = rsp.data;
      }
    }
    break;
  default:
    break;
  }
}

/**
 * Writes a single word.
 *
 * @param buf Buffer from which the word will be copied.
 * @param address Address to where the word will be written.
 * @param wordsize Word size in bits.
 *
 */
void ac_tlm_port::write(ac_ptr buf, uint32_t address, int wordsize) {
  ac_tlm_req req;
  ac_tlm_rsp rsp;

//   req.type = WRITE;
//   req.addr = address;

  // It would be necessary to read 64 bits and mix the bits with the smaller
  // words that will be written
  switch (wordsize) {
  case 8:
    req.type = READ;
    req.addr = address;
    rsp = (*this)->transport(req);

    req.type = WRITE;
    ((uint8_t*)&(req.data))[0] = *(buf.ptr8);
    rsp = (*this)->transport(req);
    break;
  case 16:
    req.type = READ;
    req.addr = address;
    rsp = (*this)->transport(req);

    req.type = WRITE;
    ((uint16_t*)&(req.data))[0] =
      *(buf.ptr16);
    rsp = (*this)->transport(req);
    break;
  case 32:
    req.type = READ;
    req.addr = address;
    rsp = (*this)->transport(req);

    req.type = WRITE;
    ((uint32_t*)&(req.data))[0] =
      *(buf.ptr32);
    rsp = (*this)->transport(req);
    break;
  case 64:
    req.type = WRITE;
    req.addr = address;
    req.data = *(buf.ptr64);
    rsp = (*this)->transport(req);
    break;
  default:
    break;
  }
}

/**
 * Writes multiple words.
 *
 * @param buf Buffer from which the words will be copied.
 * @param address Address to where the words will be written.
 * @param wordsize Word size in bits.
 * @param n_words Number of words to be written.
 *
 */
void ac_tlm_port::write(ac_ptr buf, uint32_t address,
			int wordsize, int n_words) {
  ac_tlm_req req;
  ac_tlm_rsp rsp;

  switch (wordsize) {
  case 8:
    for (int i = 0; i < n_words; i++) {
      req.type = READ;
      req.addr = address + i;
      req.data = 0ULL;
      rsp = (*this)->transport(req);

      req.type = WRITE;
      req.data = rsp.data;

      for (int j = 0; (i < n_words) && (j < 8); j++, i++) {
	((uint8_t*)&req.data)[j] = (buf.ptr8)[i];
      }
      i--;
      (*this)->transport(req);
    }
    break;
  case 16:
    for (int i = 0; i < n_words; i++) {
      req.type = READ;
      req.addr = address + (i * sizeof(uint16_t));
      req.data = 0ULL;
      rsp = (*this)->transport(req);

      req.type = WRITE;
      req.data = rsp.data;

      for (int j = 0; (i < n_words) && (j < 4); j++, i++) {
	((uint16_t*)&req.data)[j] = (buf.ptr16)[i];
      }
      i--;
      (*this)->transport(req);
    }
    break;
  case 32:
    for (int i = 0; i < n_words; i++) {
      req.type = READ;
      req.addr = address + (i * sizeof(uint32_t));
      req.data = 0ULL;
      rsp = (*this)->transport(req);

      req.type = WRITE;
      req.data = rsp.data;

      for (int j = 0; (i < n_words) && (j < 2); j++, i++) {
	((uint32_t*)&req.data)[j] = (buf.ptr32)[i];
      }
      i--;
      (*this)->transport(req);
    }
    break;
  case 64:
    for (int i = 0; i < n_words; i++) {
      req.addr = address + (i * sizeof(uint64_t));
      req.data = (buf.ptr64)[i];
      (*this)->transport(req);
    }
    break;
  default:
    break;
  }
}

uint32_t ac_tlm_port::get_size() const {
  return size;
}

//////////////////////////////////////////////////////////////////////////////

// Destructors

/**
 * Default (virtual) destructor.
 * @return Nothing.
 */
ac_tlm_port::~ac_tlm_port() {}

//////////////////////////////////////////////////////////////////////////////

<|endoftext|>


<commit_before><commit_msg>Prefer initial-caps versions of key phrases, if they exist.<commit_after><|endoftext|>


<commit_before>#include "world.h"
#include "room.h"
#include "player.h"
#include "exit.h"
#include <iostream>
#include <algorithm>

using namespace std;

World::World()
{
	Room* sleeping_quarters = new Room("Sleeping quarters", "It's kinda dark, and everyone is sleeping. I should not wake anyone...");
	Room* main_deck = new Room("Main deck", "Blablabla maindeck");

	Exit* exit1 = new Exit(up, sleeping_quarters, main_deck);
	Exit* exit2 = new Exit(down, main_deck, sleeping_quarters);

	sleeping_quarters->exits.push_back(exit1);
	main_deck->exits.push_back(exit2);

	mainguy = new Player("Slinger", "A young, untrained but clever pirate", sleeping_quarters);

	worldEntities.push_back(sleeping_quarters);
	worldEntities.push_back(main_deck);
	worldEntities.push_back(mainguy);
}

World::~World()
{
}

void World::readInput(vector<string> userInput)
{
	switch ( userInput.size() )
	{
		case 1:
			if (userInput[0] == "Look")
			{
				mainguy->Look();
			}
			else if (userInput[0] == "Inventory")
			{
				cout << "Checking inventory" << endl << ">";
			}
			else
			{
				cout << "I didn't understand you, mate" << endl << ">";
			}
			break;

		case 2:
			if (userInput[0] == "Go")
			{
				if (userInput[1] == "north")
				{
					if (mainguy->Go(north)) mainguy->Look();
				}
				else if (userInput[1] == "south")
				{
					if (mainguy->Go(south)) mainguy->Look();
				}
				else if (userInput[1] == "east")
				{
					if (mainguy->Go(east)) mainguy->Look();
				}
				else if (userInput[1] == "west")
				{
					if (mainguy->Go(west)) mainguy->Look();
				}
				else if (userInput[1] == "up")
				{
					if (mainguy->Go(up)) mainguy->Look();
				}
				else if (userInput[1] == "down")
				{
					if (mainguy->Go(down)) mainguy->Look();
				}
				else cout << "That's not a valid direction!" << endl << ">";
			}
			else if (userInput[0] == "Pick")
			{
				cout << "Picking something" << endl << ">";
			}
			else if (userInput[0] == "Drop")
			{
				cout << "Dropping something" << endl << ">";
			}
			else
			{
				cout << "I didn't understand you, mate" << endl << ">";
			}

			break;

		case 4:
			if (userInput[0] == "Put")
			{
				cout << "Putting something in/on something" << endl << ">";
			}
			else
			{
				cout << "I didn't understand you, mate" << endl << ">";
			}

			break;

	}
}<commit_msg>Added Inventory and PickUp calls to manage items<commit_after>#include "world.h"
#include "room.h"
#include "player.h"
#include "exit.h"
#include "item.h"
#include <iostream>
#include <algorithm>

using namespace std;

World::World()
{
	Room* sleeping_quarters = new Room("Sleeping quarters", "It's kinda dark, and everyone is sleeping. I should not wake anyone...");
	Room* main_deck = new Room("Main deck", "Blablabla maindeck");

	Exit* exit1 = new Exit(up, sleeping_quarters, main_deck);
	Exit* exit2 = new Exit(down, main_deck, sleeping_quarters);

	sleeping_quarters->exits.push_back(exit1);
	main_deck->exits.push_back(exit2);

	mainguy = new Player("Slinger", "A young, untrained but clever pirate", sleeping_quarters);

	Item* sword = new Item("Cutlass", "A slightly old, ugly but effective weapon.", true);
	Item* orange = new Item("Orange", "The best defense against scurvy!", true);

	sleeping_quarters->containedEntities.push_back(sword);

	worldEntities.push_back(sleeping_quarters);
	worldEntities.push_back(main_deck);
	worldEntities.push_back(mainguy);
}

World::~World()
{
}

void World::readInput(vector<string> userInput)
{
	switch ( userInput.size() )
	{
		case 1:
			if (userInput[0] == "Look")
			{
				mainguy->Look();
			}
			else if (userInput[0] == "Inventory")
			{
				mainguy->Inventory();
			}
			else
			{
				cout << "I didn't understand you, mate" << endl << ">";
			}
			break;

		case 2:
			if (userInput[0] == "Go")
			{
				if (userInput[1] == "north")
				{
					if (mainguy->Go(north)) mainguy->Look();
				}
				else if (userInput[1] == "south")
				{
					if (mainguy->Go(south)) mainguy->Look();
				}
				else if (userInput[1] == "east")
				{
					if (mainguy->Go(east)) mainguy->Look();
				}
				else if (userInput[1] == "west")
				{
					if (mainguy->Go(west)) mainguy->Look();
				}
				else if (userInput[1] == "up")
				{
					if (mainguy->Go(up)) mainguy->Look();
				}
				else if (userInput[1] == "down")
				{
					if (mainguy->Go(down)) mainguy->Look();
				}
				else cout << "That's not a valid direction!" << endl << ">";
			}
			else if (userInput[0] == "Pick")
			{
				mainguy->PickUp(userInput[1].c_str());
			}
			else if (userInput[0] == "Drop")
			{
				cout << "Dropping something" << endl << ">";
			}
			else
			{
				cout << "I didn't understand you, mate" << endl << ">";
			}

			break;

		case 4:
			if (userInput[0] == "Put")
			{
				cout << "Putting something in/on something" << endl << ">";
			}
			else
			{
				cout << "I didn't understand you, mate" << endl << ">";
			}

			break;

	}
}<|endoftext|>