<commit_before>
#include "cc/tiles/Tile.h"

#include "SkBitmap.h"
#include "SkCanvas.h"
#include "cc/tiles/TileGrid.h"
#include "cc/tiles/TileWidthHeight.h"
#include "cc/blink/WebLayerImpl.h" // TODO for backgroundColor

#include "third_party/WebKit/Source/wtf/RefCountedLeakCounter.h"

namespace cc {

#ifndef NDEBUG
DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, tileCounter, ("ccTile"));
#endif

Tile::Tile(TileGrid* tileGrid, int xIndex, int yIndex)
{
    m_isNotInit = true;
	m_refCnt = 1;
    m_xIndex = xIndex;
    m_yIndex = yIndex;
    m_priority = TilePriorityNormal;
    m_postion = blink::IntRect(xIndex * kDefaultTileWidth, yIndex * kDefaultTileHeight, kDefaultTileWidth, kDefaultTileHeight);
    //m_bitmap = nullptr;
    m_useingRate = 0;
    m_tileGrid = tileGrid;
    m_tileGrid->registerTile(this);
    setAllBoundDirty();

#ifndef NDEBUG
    tileCounter.increment();
#endif
}

Tile::~Tile()
{
    for (size_t i = 0; i < m_refFrom.size(); ++i) {
        TileTraceLocation* location = m_refFrom[i];
        delete location;
    }
    //m_refFrom.clear();

    //clearBitmap();
    m_tileGrid->unregisterTile(this);

#ifndef NDEBUG
    tileCounter.decrement();
#endif
}

void Tile::ref(const blink::WebTraceLocation& location)
{
    // m_refFromҪ
	  //m_refFrom.append(new TileTraceLocation(location.functionName(), location.fileName(), true));
	  ASSERT(m_refCnt > 0);
	  (void)sk_atomic_fetch_add(&m_refCnt, +1, sk_memory_order_relaxed);  // No barrier required.
}

void Tile::unref(const blink::WebTraceLocation& location)
{
	  //m_refFrom.append(new TileTraceLocation(location.functionName(), location.fileName(), false));
    ASSERT(m_refCnt > 0);
    if (1 == sk_atomic_fetch_add(&m_refCnt, -1, sk_memory_order_acq_rel)) {
        delete this;
    }
}

int32_t Tile::getRefCnt() const
{
	  return m_refCnt;
}

void Tile::clearBitmap()
{
//     if (m_bitmap)
//         delete m_bitmap;
//     m_bitmap = nullptr;
//     //m_bitmap->eraseColor(0xff000000); // debug test
	  m_bitmap = false;
}

void Tile::allocBitmapIfNeeded()
{
	  m_bitmap = true;
//     WTF::MutexLocker locker(m_mutex);
//     m_isNotInit = false;
//     //ASSERT(!(!m_bitmap && 1 != getRefCnt())); // пڻûդͱclearBitmap
//
//     if (m_bitmap)
//         return;
//
//     m_bitmap = new SkBitmap();
//     m_bitmap->allocN32Pixels(m_postion.width(), m_postion.height(), false);
//     SkColor color = 0x00ffffff;
//     if (m_tileGrid && m_tileGrid->layer())
//         color = 0x00ffffff & (m_tileGrid->layer()->backgroundColor());
// 	// weolar
// 	//color = 0xfff010f0;
//     m_bitmap->eraseColor(color); // Ƿ͸ھɫ
}

bool Tile::isSameTileGrid(const TileGrid* tileGrid) const
{
    return m_tileGrid == tileGrid;
}

void Tile::appendDirtyRect(const blink::IntRect& r)
{
    WTF::MutexLocker locker(m_mutex);
    m_dirtyRect.unite(r);
}

void Tile::clearDirtyRect()
{
    WTF::MutexLocker locker(m_mutex);
    m_dirtyRect = blink::IntRect();
}

cc_blink::WebLayerImpl* Tile::layer() const
{
    if (!m_tileGrid)
        return nullptr;
    return m_tileGrid->layer();
}

TileGrid* Tile::tileGrid() const
{
    return m_tileGrid;
}

blink::IntRect Tile::postion() const
{
    return m_postion;
}

blink::IntRect Tile::dirtyRect()
{
    WTF::MutexLocker locker(m_mutex);
    return m_dirtyRect;
}

void Tile::setAllBoundDirty()
{
    WTF::MutexLocker locker(m_mutex);
    m_dirtyRect = blink::IntRect(0, 0, m_postion.width(), m_postion.height());
}

TilePriority Tile::priority() const
{
    return m_priority;
}

void Tile::setPriority(TilePriority priority)
{
    m_priority = priority;
}

void Tile::eraseColor(const blink::IntRect& r, const SkColor* color)
{
    //tile->bitmap()->eraseColor(0x00ffffff);

//     SkCanvas canvas(*bitmap());
//
//     blink::IntRect rect = r;
//     rect.intersect(postion());
//     rect.move(-postion().x(), -postion().y());
//
//     SkPaint clearColorPaint;
//     clearColorPaint.setXfermodeMode(SkXfermode::kClear_Mode);
//     //clearColorPaint.setColor(color ? *color : (0x00ffffff | (layer()->backgroundColor()))); // weolar
// 	   clearColorPaint.setColor(0xff10f0f0);
//     canvas.drawIRect(rect, clearColorPaint);
}

void Tile::increaseUseingRate()
{
    ++m_useingRate;
}

} // cc<commit_msg>* tab改成空格<commit_after>
#include "cc/tiles/Tile.h"

#include "SkBitmap.h"
#include "SkCanvas.h"
#include "cc/tiles/TileGrid.h"
#include "cc/tiles/TileWidthHeight.h"
#include "cc/blink/WebLayerImpl.h" // TODO for backgroundColor

#include "third_party/WebKit/Source/wtf/RefCountedLeakCounter.h"

namespace cc {

#ifndef NDEBUG
DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, tileCounter, ("ccTile"));
#endif

Tile::Tile(TileGrid* tileGrid, int xIndex, int yIndex)
{
    m_isNotInit = true;
    m_refCnt = 1;
    m_xIndex = xIndex;
    m_yIndex = yIndex;
    m_priority = TilePriorityNormal;
    m_postion = blink::IntRect(xIndex * kDefaultTileWidth, yIndex * kDefaultTileHeight, kDefaultTileWidth, kDefaultTileHeight);
    //m_bitmap = nullptr;
    m_useingRate = 0;
    m_tileGrid = tileGrid;
    m_tileGrid->registerTile(this);
    setAllBoundDirty();

#ifndef NDEBUG
    tileCounter.increment();
#endif
}

Tile::~Tile()
{
    for (size_t i = 0; i < m_refFrom.size(); ++i) {
        TileTraceLocation* location = m_refFrom[i];
        delete location;
    }
    //m_refFrom.clear();

    //clearBitmap();
    m_tileGrid->unregisterTile(this);

#ifndef NDEBUG
    tileCounter.decrement();
#endif
}

void Tile::ref(const blink::WebTraceLocation& location)
{
    // m_refFromҪ
	  //m_refFrom.append(new TileTraceLocation(location.functionName(), location.fileName(), true));
	  ASSERT(m_refCnt > 0);
	  (void)sk_atomic_fetch_add(&m_refCnt, +1, sk_memory_order_relaxed);  // No barrier required.
}

void Tile::unref(const blink::WebTraceLocation& location)
{
	  //m_refFrom.append(new TileTraceLocation(location.functionName(), location.fileName(), false));
    ASSERT(m_refCnt > 0);
    if (1 == sk_atomic_fetch_add(&m_refCnt, -1, sk_memory_order_acq_rel)) {
        delete this;
    }
}

int32_t Tile::getRefCnt() const
{
	  return m_refCnt;
}

void Tile::clearBitmap()
{
//     if (m_bitmap)
//         delete m_bitmap;
//     m_bitmap = nullptr;
//     //m_bitmap->eraseColor(0xff000000); // debug test
	  m_bitmap = false;
}

void Tile::allocBitmapIfNeeded()
{
	  m_bitmap = true;
//     WTF::MutexLocker locker(m_mutex);
//     m_isNotInit = false;
//     //ASSERT(!(!m_bitmap && 1 != getRefCnt())); // пڻûդͱclearBitmap
//
//     if (m_bitmap)
//         return;
//
//     m_bitmap = new SkBitmap();
//     m_bitmap->allocN32Pixels(m_postion.width(), m_postion.height(), false);
//     SkColor color = 0x00ffffff;
//     if (m_tileGrid && m_tileGrid->layer())
//         color = 0x00ffffff & (m_tileGrid->layer()->backgroundColor());
// 	// weolar
// 	//color = 0xfff010f0;
//     m_bitmap->eraseColor(color); // Ƿ͸ھɫ
}

bool Tile::isSameTileGrid(const TileGrid* tileGrid) const
{
    return m_tileGrid == tileGrid;
}

void Tile::appendDirtyRect(const blink::IntRect& r)
{
    WTF::MutexLocker locker(m_mutex);
    m_dirtyRect.unite(r);
}

void Tile::clearDirtyRect()
{
    WTF::MutexLocker locker(m_mutex);
    m_dirtyRect = blink::IntRect();
}

cc_blink::WebLayerImpl* Tile::layer() const
{
    if (!m_tileGrid)
        return nullptr;
    return m_tileGrid->layer();
}

TileGrid* Tile::tileGrid() const
{
    return m_tileGrid;
}

blink::IntRect Tile::postion() const
{
    return m_postion;
}

blink::IntRect Tile::dirtyRect()
{
    WTF::MutexLocker locker(m_mutex);
    return m_dirtyRect;
}

void Tile::setAllBoundDirty()
{
    WTF::MutexLocker locker(m_mutex);
    m_dirtyRect = blink::IntRect(0, 0, m_postion.width(), m_postion.height());
}

TilePriority Tile::priority() const
{
    return m_priority;
}

void Tile::setPriority(TilePriority priority)
{
    m_priority = priority;
}

void Tile::eraseColor(const blink::IntRect& r, const SkColor* color)
{
    //tile->bitmap()->eraseColor(0x00ffffff);

//     SkCanvas canvas(*bitmap());
//
//     blink::IntRect rect = r;
//     rect.intersect(postion());
//     rect.move(-postion().x(), -postion().y());
//
//     SkPaint clearColorPaint;
//     clearColorPaint.setXfermodeMode(SkXfermode::kClear_Mode);
//     //clearColorPaint.setColor(color ? *color : (0x00ffffff | (layer()->backgroundColor()))); // weolar
// 	   clearColorPaint.setColor(0xff10f0f0);
//     canvas.drawIRect(rect, clearColorPaint);
}

void Tile::increaseUseingRate()
{
    ++m_useingRate;
}

} // cc<|endoftext|>


<commit_before><commit_msg>[Chromecast] ATV: don't include logs from renderer process in logfile.<commit_after><|endoftext|>


<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "views/examples/radio_button_example.h"

#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "views/controls/button/text_button.h"
#include "views/layout/grid_layout.h"
#include "views/view.h"

namespace examples {

RadioButtonExample::RadioButtonExample(ExamplesMain* main)
    : ExampleBase(main, "Radio Button"), count_(0) {
}

RadioButtonExample::~RadioButtonExample() {
}

void RadioButtonExample::CreateExampleView(views::View* container) {
  select_ = new views::TextButton(this, L"Select");
  status_ = new views::TextButton(this, L"Show Status");

  int group = 1;
  for (size_t i = 0; i < arraysize(radio_buttons_); ++i) {
    radio_buttons_[i] = new views::RadioButton(
        UTF8ToUTF16(base::StringPrintf("Radio %d in group %d", i + 1, group)),
        group);
    radio_buttons_[i]->set_listener(this);
  }

  views::GridLayout* layout = new views::GridLayout(container);
  container->SetLayoutManager(layout);

  views::ColumnSet* column_set = layout->AddColumnSet(0);
  column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
                        1.0f, views::GridLayout::USE_PREF, 0, 0);
  for (size_t i = 0; i < arraysize(radio_buttons_); ++i) {
    layout->StartRow(0, 0);
    layout->AddView(radio_buttons_[i]);
  }
  layout->StartRow(0, 0);
  layout->AddView(select_);
  layout->StartRow(0, 0);
  layout->AddView(status_);
}

void RadioButtonExample::ButtonPressed(views::Button* sender,
                                       const views::Event& event) {
  if (sender == select_) {
    radio_buttons_[2]->SetChecked(true);
  } else if (sender == status_) {
    // Show the state of radio buttons.
    PrintStatus("Group: 1:%s, 2:%s, 3:%s",
                BoolToOnOff(radio_buttons_[0]->checked()),
                BoolToOnOff(radio_buttons_[1]->checked()),
                BoolToOnOff(radio_buttons_[2]->checked()));
  } else {
    PrintStatus("Pressed! count:%d", ++count_);
  }
}

}  // namespace examples
<commit_msg>views/examples: Fix the format string of size_t var in RadioButton example.<commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "views/examples/radio_button_example.h"

#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "views/controls/button/text_button.h"
#include "views/layout/grid_layout.h"
#include "views/view.h"

namespace examples {

RadioButtonExample::RadioButtonExample(ExamplesMain* main)
    : ExampleBase(main, "Radio Button"), count_(0) {
}

RadioButtonExample::~RadioButtonExample() {
}

void RadioButtonExample::CreateExampleView(views::View* container) {
  select_ = new views::TextButton(this, L"Select");
  status_ = new views::TextButton(this, L"Show Status");

  int group = 1;
  for (size_t i = 0; i < arraysize(radio_buttons_); ++i) {
    radio_buttons_[i] = new views::RadioButton(
        UTF8ToUTF16(base::StringPrintf(
            "Radio %d in group %d", static_cast<int>(i) + 1, group)),
        group);
    radio_buttons_[i]->set_listener(this);
  }

  views::GridLayout* layout = new views::GridLayout(container);
  container->SetLayoutManager(layout);

  views::ColumnSet* column_set = layout->AddColumnSet(0);
  column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
                        1.0f, views::GridLayout::USE_PREF, 0, 0);
  for (size_t i = 0; i < arraysize(radio_buttons_); ++i) {
    layout->StartRow(0, 0);
    layout->AddView(radio_buttons_[i]);
  }
  layout->StartRow(0, 0);
  layout->AddView(select_);
  layout->StartRow(0, 0);
  layout->AddView(status_);
}

void RadioButtonExample::ButtonPressed(views::Button* sender,
                                       const views::Event& event) {
  if (sender == select_) {
    radio_buttons_[2]->SetChecked(true);
  } else if (sender == status_) {
    // Show the state of radio buttons.
    PrintStatus("Group: 1:%s, 2:%s, 3:%s",
                BoolToOnOff(radio_buttons_[0]->checked()),
                BoolToOnOff(radio_buttons_[1]->checked()),
                BoolToOnOff(radio_buttons_[2]->checked()));
  } else {
    PrintStatus("Pressed! count:%d", ++count_);
  }
}

}  // namespace examples
<|endoftext|>


<commit_before>#include "Request_wrap.h"

#include <boost/python/class.hpp>
#include <boost/python/pure_virtual.hpp>
#include <boost/python/return_internal_reference.hpp>

using namespace opencog;
using namespace boost::python;

void init_Request_py()
{
    class_<RequestWrap, boost::noncopyable>("Request", no_init)
    ;
}

// For the pure virtual functions..

bool RequestWrap::execute(void)
{
    return this->get_override("execute")();
}

// For the non-pure virtual functions..

void RequestWrap::send(const std::string& msg) const
{
    if (override o = this->get_override("send"))
        o(msg);

    Request::send(msg);
}
void RequestWrap::default_send(const std::string& msg) const
{
    this->Request::send(msg);
}

void RequestWrap::setSocketHolder(SocketHolder *h)
{
    if (override o = this->get_override("setSocketHolder"))
        o(h);

    Request::setSocketHolder(h);
}
void RequestWrap::default_setSocketHolder(SocketHolder *h)
{
    this->Request::setSocketHolder(h);
}

SocketHolder *RequestWrap::getSocketHolder(void)
{
    if (override o = this->get_override("getSocketHolder"))
        return o();

    return Request::getSocketHolder();
}
SocketHolder *RequestWrap::default_getSocketHolder()
{
    return this->Request::getSocketHolder();
}

void RequestWrap::setParameters(const std::list<std::string>& params)
{
    if (override o = this->get_override("setParameters"))
        o(params);

    Request::setParameters(params);
}
void RequestWrap::default_setParameters(const std::list<std::string>& params)
{
    this->Request::setParameters(params);
}

void RequestWrap::addParameter(const std::string& param)
{
    if (override o = this->get_override("addParameter"))
        o(param);

    Request::addParameter(param);
}
void RequestWrap::default_addParameter(const std::string& param)
{
    this->Request::addParameter(param);
}
<commit_msg>Actually exposed 6 methods of Request class.<commit_after>#include "Request_wrap.h"

#include <boost/python/class.hpp>
#include <boost/python/pure_virtual.hpp>
#include <boost/python/return_value_policy.hpp>
#include <boost/python/return_internal_reference.hpp>
#include <boost/python/manage_new_object.hpp>

using namespace opencog;
using namespace boost::python;

void init_Request_py()
{
    class_<RequestWrap, boost::noncopyable>("Request", no_init)
        .def("execute", pure_virtual(&Request::execute))
        .def("send",
            &Request::send,
            &RequestWrap::default_send)
        .def("setSocketHolder",
            &Request::setSocketHolder,
            &RequestWrap::default_setSocketHolder)
        .def("getSocketHolder",
            &Request::getSocketHolder,
            &RequestWrap::default_getSocketHolder,
            return_value_policy<manage_new_object>())
        .def("setParameters",
            &Request::setParameters,
            &RequestWrap::default_setParameters)
        .def("addParameter",
            &Request::addParameter,
            &RequestWrap::default_addParameter)
    ;
}

// For the pure virtual functions..

bool RequestWrap::execute(void)
{
    return this->get_override("execute")();
}

// For the non-pure virtual functions..

void RequestWrap::send(const std::string& msg) const
{
    if (override o = this->get_override("send"))
        o(msg);

    Request::send(msg);
}
void RequestWrap::default_send(const std::string& msg) const
{
    this->Request::send(msg);
}

void RequestWrap::setSocketHolder(SocketHolder *h)
{
    if (override o = this->get_override("setSocketHolder"))
        o(h);

    Request::setSocketHolder(h);
}
void RequestWrap::default_setSocketHolder(SocketHolder *h)
{
    this->Request::setSocketHolder(h);
}

SocketHolder *RequestWrap::getSocketHolder(void)
{
    if (override o = this->get_override("getSocketHolder"))
        return o();

    return Request::getSocketHolder();
}
SocketHolder *RequestWrap::default_getSocketHolder()
{
    return this->Request::getSocketHolder();
}

void RequestWrap::setParameters(const std::list<std::string>& params)
{
    if (override o = this->get_override("setParameters"))
        o(params);

    Request::setParameters(params);
}
void RequestWrap::default_setParameters(const std::list<std::string>& params)
{
    this->Request::setParameters(params);
}

void RequestWrap::addParameter(const std::string& param)
{
    if (override o = this->get_override("addParameter"))
        o(param);

    Request::addParameter(param);
}
void RequestWrap::default_addParameter(const std::string& param)
{
    this->Request::addParameter(param);
}
<|endoftext|>


<commit_before>
/*!
	\file

	\author Igor Mironchik (igor.mironchik at gmail dot com).

	Copyright (c) 2017 Igor Mironchik

	Permission is hereby granted, free of charge, to any person
	obtaining a copy of this software and associated documentation
	files (the "Software"), to deal in the Software without
	restriction, including without limitation the rights to use,
	copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the
	Software is furnished to do so, subject to the following
	conditions:

	The above copyright notice and this permission notice shall be
	included in all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
	OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
	HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
	WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
	OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef CFGFILE__TYPES_HPP__INCLUDED
#define CFGFILE__TYPES_HPP__INCLUDED

#ifdef CFGFILE_WSTRING_BUILD

// C++ include.
#include <string>
#include <list>
#include <iostream>

#elif defined( CFGFILE_QSTRING_BUILD )

// Qt include.
#include <QString>
#include <QTextStream>

#else

// C++ include.
#include <string>
#include <list>
#include <iostream>

#endif

namespace cfgfile {

#ifdef CFGFILE_WSTRING_BUILD

//! String type.
using string_t = std::wstring;

//! Char type.
using char_t = string_t::value_type;

//! Out stream type.
using ostream_t = std::wostream;

//! In stream type.
using istream_t = std::wistream;

//! Type of pos in stream.
using pos_t = std::streamoff;

#define SL(str) L##str

static inline string_t pos_to_string( pos_t pos )
{
	return std::to_wstring( pos );
}

#elif defined( CFGFILE_QSTRING_BUILD )

//! Char type.
using char_t = QChar;

//! Out stream type.
using ostream_t = QTextStream;

//! In stream type.
using istream_t = QTextStream;

//! Type of pos in stream.
using pos_t = quint64;

class string_t {
public:
	using size_type = int;

	string_t()
	{
	}

	string_t( size_type size, char_t ch )
		:	m_str( size, ch )
	{
	}

	string_t( const char * str )
		:	m_str( str )
	{
	}

	string_t( const QString & other )
		:	m_str( other )
	{
	}

	string_t( const char_t * unicode, size_type size = -1 )
		:	m_str( unicode, size )
	{
	}

	string_t( char_t ch )
		:	m_str( ch )
	{
	}

	string_t( QLatin1String str )
		:	m_str( str )
	{
	}

	string_t( const QByteArray & ba )
		:	m_str( ba )
	{
	}

	operator QString ()
	{
		return m_str;
	}

	operator QString () const
	{
		return m_str;
	}

	inline bool empty() const
	{
		return m_str.isEmpty();
	}

	static const int npos = -1;

	inline int find( char_t ch ) const
	{
		return m_str.indexOf( ch );
	}

	inline int find( const string_t & str ) const
	{
		return m_str.indexOf( str.m_str );
	}

	inline int rfind( const string_t & str ) const
	{
		return m_str.lastIndexOf( str.m_str );
	}

	inline int rfind( char_t ch ) const
	{
		return m_str.lastIndexOf( ch );
	}

	string_t & replace( size_type pos, size_type count, const string_t & v )
	{
		m_str.replace( pos, count, v.m_str );

		return *this;
	}

	inline QString::iterator begin()
	{
		return m_str.begin();
	}

	inline QString::iterator end()
	{
		return m_str.end();
	}

	inline QString::const_iterator begin() const
	{
		return m_str.begin();
	}

	inline QString::const_iterator end() const
	{
		return m_str.end();
	}

	inline QString::const_iterator cbegin() const
	{
		return m_str.begin();
	}

	inline QString::const_iterator cend() const
	{
		return m_str.end();
	}

	inline size_type length() const
	{
		return m_str.length();
	}

	inline string_t substr( size_type pos, size_type count = npos ) const
	{
		return m_str.mid( pos, count );
	}

	friend bool operator == ( const string_t & s1, const string_t & s2 )
	{
		return ( s1.m_str == s2.m_str );
	}

	friend string_t operator + ( const string_t & s1, const string_t & s2 )
	{
		return string_t( s1.m_str + s2.m_str );
	}

	friend string_t operator + ( const string_t & s1, const char * s2 )
	{
		return string_t( s1.m_str + s2 );
	}

	friend string_t operator + ( const char * s1, const string_t & s2 )
	{
		return string_t( s1 + s2.m_str );
	}

	friend string_t operator + ( const string_t & s1, const char ch )
	{
		return string_t( s1.m_str + ch );
	}

	friend string_t operator + ( const char ch, const string_t & s2 )
	{
		return string_t( ch + s2.m_str );
	}

	friend ostream_t & operator << ( ostream_t & to,
		const string_t & what )
	{
		to << what.m_str;

		return to;
	}

	inline const char_t operator [] ( size_type pos ) const
	{
		return m_str[ pos ];
	}

	inline string_t & append( const string_t & other )
	{
		m_str.append( other.m_str );

		return *this;
	}

	inline string_t & append( size_type count, char_t ch )
	{
		m_str.append( QString( count, ch ) );

		return *this;
	}

	inline void clear()
	{
		m_str.clear();
	}

	inline void push_back( char_t ch )
	{
		m_str.append( ch );
	}

private:
	//! Actual string.
	QString m_str;
}; // class string_t

#define SL(str) str

static inline string_t pos_to_string( pos_t pos )
{
	return QString::number( pos );
}

#else

//! String type.
using string_t = std::string;

//! Char type.
using char_t = string_t::value_type;

//! Input stream type.
using istream_t = std::istream;

//! Type of pos in stream.
using pos_t = std::streamoff;

//! Output stream type.
using ostream_t = std::ostream;

#define SL(str) str

static inline string_t pos_to_string( pos_t pos )
{
	return std::to_string( pos );
}

#endif

//
// DISABLE_COPY
//

//! Macro for disabling copy.
#define DISABLE_COPY( Class ) \
	Class( const Class & ) = delete; \
	Class & operator= ( const Class & ) = delete;

} /* namespace cfgfile */

#endif // CFGFILE__TYPES_HPP__INCLUDED
<commit_msg>Changed pos_t in Qt build.<commit_after>
/*!
	\file

	\author Igor Mironchik (igor.mironchik at gmail dot com).

	Copyright (c) 2017 Igor Mironchik

	Permission is hereby granted, free of charge, to any person
	obtaining a copy of this software and associated documentation
	files (the "Software"), to deal in the Software without
	restriction, including without limitation the rights to use,
	copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the
	Software is furnished to do so, subject to the following
	conditions:

	The above copyright notice and this permission notice shall be
	included in all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
	OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
	HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
	WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
	OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef CFGFILE__TYPES_HPP__INCLUDED
#define CFGFILE__TYPES_HPP__INCLUDED

#ifdef CFGFILE_WSTRING_BUILD

// C++ include.
#include <string>
#include <list>
#include <iostream>

#elif defined( CFGFILE_QSTRING_BUILD )

// Qt include.
#include <QString>
#include <QTextStream>

#else

// C++ include.
#include <string>
#include <list>
#include <iostream>

#endif

namespace cfgfile {

#ifdef CFGFILE_WSTRING_BUILD

//! String type.
using string_t = std::wstring;

//! Char type.
using char_t = string_t::value_type;

//! Out stream type.
using ostream_t = std::wostream;

//! In stream type.
using istream_t = std::wistream;

//! Type of pos in stream.
using pos_t = std::streamoff;

#define SL(str) L##str

static inline string_t pos_to_string( pos_t pos )
{
	return std::to_wstring( pos );
}

#elif defined( CFGFILE_QSTRING_BUILD )

//! Char type.
using char_t = QChar;

//! Out stream type.
using ostream_t = QTextStream;

//! In stream type.
using istream_t = QTextStream;

//! Type of pos in stream.
using pos_t = qint64;

class string_t {
public:
	using size_type = int;

	string_t()
	{
	}

	string_t( size_type size, char_t ch )
		:	m_str( size, ch )
	{
	}

	string_t( const char * str )
		:	m_str( str )
	{
	}

	string_t( const QString & other )
		:	m_str( other )
	{
	}

	string_t( const char_t * unicode, size_type size = -1 )
		:	m_str( unicode, size )
	{
	}

	string_t( char_t ch )
		:	m_str( ch )
	{
	}

	string_t( QLatin1String str )
		:	m_str( str )
	{
	}

	string_t( const QByteArray & ba )
		:	m_str( ba )
	{
	}

	operator QString ()
	{
		return m_str;
	}

	operator QString () const
	{
		return m_str;
	}

	inline bool empty() const
	{
		return m_str.isEmpty();
	}

	static const int npos = -1;

	inline int find( char_t ch ) const
	{
		return m_str.indexOf( ch );
	}

	inline int find( const string_t & str ) const
	{
		return m_str.indexOf( str.m_str );
	}

	inline int rfind( const string_t & str ) const
	{
		return m_str.lastIndexOf( str.m_str );
	}

	inline int rfind( char_t ch ) const
	{
		return m_str.lastIndexOf( ch );
	}

	string_t & replace( size_type pos, size_type count, const string_t & v )
	{
		m_str.replace( pos, count, v.m_str );

		return *this;
	}

	inline QString::iterator begin()
	{
		return m_str.begin();
	}

	inline QString::iterator end()
	{
		return m_str.end();
	}

	inline QString::const_iterator begin() const
	{
		return m_str.begin();
	}

	inline QString::const_iterator end() const
	{
		return m_str.end();
	}

	inline QString::const_iterator cbegin() const
	{
		return m_str.begin();
	}

	inline QString::const_iterator cend() const
	{
		return m_str.end();
	}

	inline size_type length() const
	{
		return m_str.length();
	}

	inline string_t substr( size_type pos, size_type count = npos ) const
	{
		return m_str.mid( pos, count );
	}

	friend bool operator == ( const string_t & s1, const string_t & s2 )
	{
		return ( s1.m_str == s2.m_str );
	}

	friend string_t operator + ( const string_t & s1, const string_t & s2 )
	{
		return string_t( s1.m_str + s2.m_str );
	}

	friend string_t operator + ( const string_t & s1, const char * s2 )
	{
		return string_t( s1.m_str + s2 );
	}

	friend string_t operator + ( const char * s1, const string_t & s2 )
	{
		return string_t( s1 + s2.m_str );
	}

	friend string_t operator + ( const string_t & s1, const char ch )
	{
		return string_t( s1.m_str + ch );
	}

	friend string_t operator + ( const char ch, const string_t & s2 )
	{
		return string_t( ch + s2.m_str );
	}

	friend ostream_t & operator << ( ostream_t & to,
		const string_t & what )
	{
		to << what.m_str;

		return to;
	}

	inline const char_t operator [] ( size_type pos ) const
	{
		return m_str[ pos ];
	}

	inline string_t & append( const string_t & other )
	{
		m_str.append( other.m_str );

		return *this;
	}

	inline string_t & append( size_type count, char_t ch )
	{
		m_str.append( QString( count, ch ) );

		return *this;
	}

	inline void clear()
	{
		m_str.clear();
	}

	inline void push_back( char_t ch )
	{
		m_str.append( ch );
	}

private:
	//! Actual string.
	QString m_str;
}; // class string_t

#define SL(str) str

static inline string_t pos_to_string( pos_t pos )
{
	return QString::number( pos );
}

#else

//! String type.
using string_t = std::string;

//! Char type.
using char_t = string_t::value_type;

//! Input stream type.
using istream_t = std::istream;

//! Type of pos in stream.
using pos_t = std::streamoff;

//! Output stream type.
using ostream_t = std::ostream;

#define SL(str) str

static inline string_t pos_to_string( pos_t pos )
{
	return std::to_string( pos );
}

#endif

//
// DISABLE_COPY
//

//! Macro for disabling copy.
#define DISABLE_COPY( Class ) \
	Class( const Class & ) = delete; \
	Class & operator= ( const Class & ) = delete;

} /* namespace cfgfile */

#endif // CFGFILE__TYPES_HPP__INCLUDED
<|endoftext|>


<commit_before><commit_msg>some inling<commit_after><|endoftext|>


<commit_before><commit_msg>map 'relief' none/half/normal to flat/bevel/3dlook<commit_after><|endoftext|>


<commit_before><commit_msg>-Werror=deprecated-declarations (on Debian, reportedly)<commit_after><|endoftext|>


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

#include <salunx.h>

#ifndef _SV_SALDISP_HXX
#include <saldisp.hxx>
#endif
#ifndef _SV_SALBMP_HXX
#include <salbmp.hxx>
#endif
#ifndef _SV_SALBTYPE_HXX
#include <salbtype.hxx>
#endif
#ifndef _SV_IMPBMP_HXX
#include <impbmp.hxx>
#endif
#ifndef _SV_BITMAP_HXX
#include <bitmap.hxx>
#endif
#ifndef _SV_BITMAP_HXX
#include <bitmapex.hxx>
#endif
#ifndef _SV_GRAPH_HXX
#include <graph.hxx>
#endif
#ifndef _SV_SOICON_HXX
#include <soicon.hxx>
#endif
#ifndef _SV_SVDATA_HXX
#include <svdata.hxx>
#endif
#ifndef _SV_SALBMP_H
#include <salbmp.h>
#endif
#include <svids.hrc>

BOOL SelectAppIconPixmap( SalDisplay *pDisplay, USHORT nIcon, USHORT iconSize,
                          Pixmap& icon_pixmap, Pixmap& icon_mask)
{
    USHORT nIconSizeOffset;

    if( iconSize >= 48 )
        nIconSizeOffset = SV_ICON_SIZE48_START;
    else if( iconSize >= 32 )
        nIconSizeOffset = SV_ICON_SIZE32_START;
    else if( iconSize >= 16 )
        nIconSizeOffset = SV_ICON_SIZE16_START;
    else
        return FALSE;

    BitmapEx aIcon( ResId(nIconSizeOffset + nIcon, ImplGetResMgr()));
    if( TRUE == aIcon.IsEmpty() )
        return FALSE;

    SalTwoRect aRect;
    aRect.mnSrcX = 0; aRect.mnSrcY = 0;
    aRect.mnSrcWidth = iconSize; aRect.mnSrcHeight = iconSize;
    aRect.mnDestX = 0; aRect.mnDestY = 0;
    aRect.mnDestWidth = iconSize; aRect.mnDestHeight = iconSize;

    X11SalBitmap *pBitmap = static_cast < X11SalBitmap * >
        (aIcon.ImplGetBitmapImpBitmap()->ImplGetSalBitmap());

    icon_pixmap = XCreatePixmap( pDisplay->GetDisplay(), pDisplay->GetRootWindow(),
        iconSize, iconSize, pDisplay->GetRootVisual()->GetDepth());

    pBitmap->ImplDraw(icon_pixmap, pDisplay->GetRootVisual()->GetDepth(),
        aRect, DefaultGC(pDisplay->GetDisplay(), pDisplay->GetScreenNumber()), false);

    icon_mask = None;

    if( TRANSPARENT_BITMAP == aIcon.GetTransparentType() )
    {
        icon_mask = XCreatePixmap( pDisplay->GetDisplay(),
            pDisplay->GetRootWindow(), iconSize, iconSize, 1);

        XGCValues aValues;
        aValues.foreground = 0xffffffff;
        aValues.background = 0;
        aValues.function = GXcopy;
        GC aMonoGC = XCreateGC( pDisplay->GetDisplay(), icon_mask,
            GCFunction|GCForeground|GCBackground, &aValues );

        Bitmap aMask = aIcon.GetMask();
        aMask.Invert();

        X11SalBitmap *pMask = static_cast < X11SalBitmap * >
            (aMask.ImplGetImpBitmap()->ImplGetSalBitmap());

        pMask->ImplDraw(icon_mask, 1, aRect, aMonoGC, false);
        XFreeGC( pDisplay->GetDisplay(), aMonoGC );
    }

    return TRUE;
}

<commit_msg>INTEGRATION: CWS ooo19126 (1.16.212); FILE MERGED 2005/09/05 14:45:41 rt 1.16.212.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: soicon.cxx,v $
 *
 *  $Revision: 1.17 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 13:02:58 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include <salunx.h>

#ifndef _SV_SALDISP_HXX
#include <saldisp.hxx>
#endif
#ifndef _SV_SALBMP_HXX
#include <salbmp.hxx>
#endif
#ifndef _SV_SALBTYPE_HXX
#include <salbtype.hxx>
#endif
#ifndef _SV_IMPBMP_HXX
#include <impbmp.hxx>
#endif
#ifndef _SV_BITMAP_HXX
#include <bitmap.hxx>
#endif
#ifndef _SV_BITMAP_HXX
#include <bitmapex.hxx>
#endif
#ifndef _SV_GRAPH_HXX
#include <graph.hxx>
#endif
#ifndef _SV_SOICON_HXX
#include <soicon.hxx>
#endif
#ifndef _SV_SVDATA_HXX
#include <svdata.hxx>
#endif
#ifndef _SV_SALBMP_H
#include <salbmp.h>
#endif
#include <svids.hrc>

BOOL SelectAppIconPixmap( SalDisplay *pDisplay, USHORT nIcon, USHORT iconSize,
                          Pixmap& icon_pixmap, Pixmap& icon_mask)
{
    USHORT nIconSizeOffset;

    if( iconSize >= 48 )
        nIconSizeOffset = SV_ICON_SIZE48_START;
    else if( iconSize >= 32 )
        nIconSizeOffset = SV_ICON_SIZE32_START;
    else if( iconSize >= 16 )
        nIconSizeOffset = SV_ICON_SIZE16_START;
    else
        return FALSE;

    BitmapEx aIcon( ResId(nIconSizeOffset + nIcon, ImplGetResMgr()));
    if( TRUE == aIcon.IsEmpty() )
        return FALSE;

    SalTwoRect aRect;
    aRect.mnSrcX = 0; aRect.mnSrcY = 0;
    aRect.mnSrcWidth = iconSize; aRect.mnSrcHeight = iconSize;
    aRect.mnDestX = 0; aRect.mnDestY = 0;
    aRect.mnDestWidth = iconSize; aRect.mnDestHeight = iconSize;

    X11SalBitmap *pBitmap = static_cast < X11SalBitmap * >
        (aIcon.ImplGetBitmapImpBitmap()->ImplGetSalBitmap());

    icon_pixmap = XCreatePixmap( pDisplay->GetDisplay(), pDisplay->GetRootWindow(),
        iconSize, iconSize, pDisplay->GetRootVisual()->GetDepth());

    pBitmap->ImplDraw(icon_pixmap, pDisplay->GetRootVisual()->GetDepth(),
        aRect, DefaultGC(pDisplay->GetDisplay(), pDisplay->GetScreenNumber()), false);

    icon_mask = None;

    if( TRANSPARENT_BITMAP == aIcon.GetTransparentType() )
    {
        icon_mask = XCreatePixmap( pDisplay->GetDisplay(),
            pDisplay->GetRootWindow(), iconSize, iconSize, 1);

        XGCValues aValues;
        aValues.foreground = 0xffffffff;
        aValues.background = 0;
        aValues.function = GXcopy;
        GC aMonoGC = XCreateGC( pDisplay->GetDisplay(), icon_mask,
            GCFunction|GCForeground|GCBackground, &aValues );

        Bitmap aMask = aIcon.GetMask();
        aMask.Invert();

        X11SalBitmap *pMask = static_cast < X11SalBitmap * >
            (aMask.ImplGetImpBitmap()->ImplGetSalBitmap());

        pMask->ImplDraw(icon_mask, 1, aRect, aMonoGC, false);
        XFreeGC( pDisplay->GetDisplay(), aMonoGC );
    }

    return TRUE;
}

<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

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

#include "propacc.hxx"

#include <tools/urlobj.hxx>
#include <tools/errcode.hxx>
#include <svl/svarray.hxx>
#include <basic/sbstar.hxx>
#include <sbunoobj.hxx>

using com::sun::star::uno::Reference;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
using namespace cppu;

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

// Declaration conversion from Sbx to UNO with known target type
Any sbxToUnoValue( SbxVariable* pVar, const Type& rType, Property* pUnoProperty = NULL );

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

#ifdef WNT
#define CDECL _cdecl
#endif
#if defined(UNX) || defined(OS2)
#define CDECL
#endif

int CDECL SbCompare_PropertyValues_Impl( const void *arg1, const void *arg2 )
{
   return ((PropertyValue*)arg1)->Name.compareTo( ((PropertyValue*)arg2)->Name );
}

extern "C" int CDECL SbCompare_UString_PropertyValue_Impl( const void *arg1, const void *arg2 )
{
    const ::rtl::OUString *pArg1 = (::rtl::OUString*) arg1;
    const PropertyValue **pArg2 = (const PropertyValue**) arg2;
    return pArg1->compareTo( (*pArg2)->Name );
}

int CDECL SbCompare_Properties_Impl( const void *arg1, const void *arg2 )
{
   return ((Property*)arg1)->Name.compareTo( ((Property*)arg2)->Name );
}

extern "C" int CDECL SbCompare_UString_Property_Impl( const void *arg1, const void *arg2 )
{
    const ::rtl::OUString *pArg1 = (::rtl::OUString*) arg1;
    const Property *pArg2 = (Property*) arg2;
    return pArg1->compareTo( pArg2->Name );
}

//----------------------------------------------------------------------------

SbPropertyValues::SbPropertyValues()
{
}

//----------------------------------------------------------------------------

SbPropertyValues::~SbPropertyValues()
{
    _xInfo = Reference< XPropertySetInfo >();

    for ( sal_uInt16 n = 0; n < _aPropVals.Count(); ++n )
        delete _aPropVals.GetObject( n );
}

//----------------------------------------------------------------------------

Reference< XPropertySetInfo > SbPropertyValues::getPropertySetInfo(void) throw( RuntimeException )
{
    // create on demand?
    if ( !_xInfo.is() )
    {
        SbPropertySetInfo *pInfo = new SbPropertySetInfo( _aPropVals );
        ((SbPropertyValues*)this)->_xInfo = (XPropertySetInfo*)pInfo;
    }
    return _xInfo;
}

//-------------------------------------------------------------------------

sal_Int32 SbPropertyValues::GetIndex_Impl( const ::rtl::OUString &rPropName ) const
{
    PropertyValue **ppPV;
    ppPV = (PropertyValue **)
            bsearch( &rPropName, _aPropVals.GetData(), _aPropVals.Count(),
                      sizeof( PropertyValue* ),
                      SbCompare_UString_PropertyValue_Impl );
    return ppPV ? ( (ppPV-_aPropVals.GetData()) / sizeof(ppPV) ) : USHRT_MAX;
}

//----------------------------------------------------------------------------

void SbPropertyValues::setPropertyValue(
                    const ::rtl::OUString& aPropertyName,
                    const Any& aValue)
                    throw (::com::sun::star::beans::UnknownPropertyException,
                    ::com::sun::star::beans::PropertyVetoException,
                    ::com::sun::star::lang::IllegalArgumentException,
                    ::com::sun::star::lang::WrappedTargetException,
                    ::com::sun::star::uno::RuntimeException)
{
    sal_Int32 nIndex = GetIndex_Impl( aPropertyName );
    PropertyValue *pPropVal = _aPropVals.GetObject(
        sal::static_int_cast< sal_uInt16 >(nIndex));
    pPropVal->Value = aValue;
}

//----------------------------------------------------------------------------

Any SbPropertyValues::getPropertyValue(
                    const ::rtl::OUString& aPropertyName)
                    throw(::com::sun::star::beans::UnknownPropertyException,
                    ::com::sun::star::lang::WrappedTargetException,
                    ::com::sun::star::uno::RuntimeException)
{
    sal_Int32 nIndex = GetIndex_Impl( aPropertyName );
    if ( nIndex != USHRT_MAX )
        return _aPropVals.GetObject(
            sal::static_int_cast< sal_uInt16 >(nIndex))->Value;
    return Any();
}

//----------------------------------------------------------------------------

void SbPropertyValues::addPropertyChangeListener(
                    const ::rtl::OUString& aPropertyName,
                    const Reference< XPropertyChangeListener >& )
                    throw ()
{
    (void)aPropertyName;
}

//----------------------------------------------------------------------------

void SbPropertyValues::removePropertyChangeListener(
                    const ::rtl::OUString& aPropertyName,
                    const Reference< XPropertyChangeListener >& )
                    throw ()
{
    (void)aPropertyName;
}

//----------------------------------------------------------------------------

void SbPropertyValues::addVetoableChangeListener(
                    const ::rtl::OUString& aPropertyName,
                    const Reference< XVetoableChangeListener >& )
                    throw()
{
    (void)aPropertyName;
}

//----------------------------------------------------------------------------

void SbPropertyValues::removeVetoableChangeListener(
                    const ::rtl::OUString& aPropertyName,
                    const Reference< XVetoableChangeListener >& )
                    throw()
{
    (void)aPropertyName;
}

//----------------------------------------------------------------------------

Sequence< PropertyValue > SbPropertyValues::getPropertyValues(void) throw (::com::sun::star::uno::RuntimeException)
{
    Sequence<PropertyValue> aRet( _aPropVals.Count());
    for ( sal_uInt16 n = 0; n < _aPropVals.Count(); ++n )
        aRet.getArray()[n] = *_aPropVals.GetObject(n);
    return aRet;
}

//----------------------------------------------------------------------------

void SbPropertyValues::setPropertyValues(const Sequence< PropertyValue >& rPropertyValues )
                     throw (::com::sun::star::beans::UnknownPropertyException,
                     ::com::sun::star::beans::PropertyVetoException,
                     ::com::sun::star::lang::IllegalArgumentException,
                     ::com::sun::star::lang::WrappedTargetException,
                     ::com::sun::star::uno::RuntimeException)
{
    if ( _aPropVals.Count() )
        throw PropertyExistException();

    const PropertyValue *pPropVals = rPropertyValues.getConstArray();
    for ( sal_Int16 n = 0; n < rPropertyValues.getLength(); ++n )
    {
        PropertyValue *pPropVal = new PropertyValue(pPropVals[n]);
        _aPropVals.Insert( pPropVal, n );
    }
}

//============================================================================
//PropertySetInfoImpl

PropertySetInfoImpl::PropertySetInfoImpl()
{
}

sal_Int32 PropertySetInfoImpl::GetIndex_Impl( const ::rtl::OUString &rPropName ) const
{
    Property *pP;
    pP = (Property*)
            bsearch( &rPropName, _aProps.getConstArray(), _aProps.getLength(),
                      sizeof( Property ),
                      SbCompare_UString_Property_Impl );
    return pP ? sal::static_int_cast<sal_Int32>( (pP-_aProps.getConstArray()) / sizeof(pP) ) : -1;
}

Sequence< Property > PropertySetInfoImpl::getProperties(void) throw()
{
    return _aProps;
}

Property PropertySetInfoImpl::getPropertyByName(const ::rtl::OUString& Name) throw( RuntimeException )
{
    sal_Int32 nIndex = GetIndex_Impl( Name );
    if( USHRT_MAX != nIndex )
        return _aProps.getConstArray()[ nIndex ];
    return Property();
}

sal_Bool PropertySetInfoImpl::hasPropertyByName(const ::rtl::OUString& Name) throw( RuntimeException )
{
    sal_Int32 nIndex = GetIndex_Impl( Name );
    return USHRT_MAX != nIndex;
}

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

SbPropertySetInfo::SbPropertySetInfo()
{
}

//----------------------------------------------------------------------------

SbPropertySetInfo::SbPropertySetInfo( const SbPropertyValueArr_Impl &rPropVals )
{
    aImpl._aProps.realloc( rPropVals.Count() );
    for ( sal_uInt16 n = 0; n < rPropVals.Count(); ++n )
    {
        Property &rProp = aImpl._aProps.getArray()[n];
        const PropertyValue &rPropVal = *rPropVals.GetObject(n);
        rProp.Name = rPropVal.Name;
        rProp.Handle = rPropVal.Handle;
        rProp.Type = getCppuVoidType();
        rProp.Attributes = 0;
    }
}

//----------------------------------------------------------------------------

SbPropertySetInfo::~SbPropertySetInfo()
{
}

//-------------------------------------------------------------------------

Sequence< Property > SbPropertySetInfo::getProperties(void) throw( RuntimeException )
{
    return aImpl.getProperties();
}

Property SbPropertySetInfo::getPropertyByName(const ::rtl::OUString& Name)
    throw( RuntimeException )
{
    return aImpl.getPropertyByName( Name );
}

sal_Bool SbPropertySetInfo::hasPropertyByName(const ::rtl::OUString& Name)
    throw( RuntimeException )
{
    return aImpl.hasPropertyByName( Name );
}

//----------------------------------------------------------------------------

SbPropertyContainer::SbPropertyContainer()
{
}

//----------------------------------------------------------------------------

SbPropertyContainer::~SbPropertyContainer()
{
}

//----------------------------------------------------------------------------
void SbPropertyContainer::addProperty(const ::rtl::OUString& Name,
                                      sal_Int16 Attributes,
                                      const Any& DefaultValue)
    throw(  PropertyExistException, IllegalTypeException,
            IllegalArgumentException, RuntimeException )
{
    (void)Name;
    (void)Attributes;
    (void)DefaultValue;
}

//----------------------------------------------------------------------------
void SbPropertyContainer::removeProperty(const ::rtl::OUString& Name)
    throw( UnknownPropertyException, RuntimeException )
{
    (void)Name;
}

//----------------------------------------------------------------------------
// XPropertySetInfo
Sequence< Property > SbPropertyContainer::getProperties(void) throw ()
{
    return aImpl.getProperties();
}

Property SbPropertyContainer::getPropertyByName(const ::rtl::OUString& Name)
    throw( RuntimeException )
{
    return aImpl.getPropertyByName( Name );
}

sal_Bool SbPropertyContainer::hasPropertyByName(const ::rtl::OUString& Name)
    throw( RuntimeException )
{
    return aImpl.hasPropertyByName( Name );
}

//----------------------------------------------------------------------------

Sequence< PropertyValue > SbPropertyContainer::getPropertyValues(void)
{
    return Sequence<PropertyValue>();
}

//----------------------------------------------------------------------------

void SbPropertyContainer::setPropertyValues(const Sequence< PropertyValue >& PropertyValues_)
{
    (void)PropertyValues_;
}

//----------------------------------------------------------------------------

void RTL_Impl_CreatePropertySet( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
{
    (void)pBasic;
    (void)bWrite;

    // We need at least one parameter
    // TODO: In this case < 2 is not correct ;-)
    if ( rPar.Count() < 2 )
    {
        StarBASIC::Error( SbERR_BAD_ARGUMENT );
        return;
    }

    // Get class names of struct
    String aServiceName( RTL_CONSTASCII_USTRINGPARAM("stardiv.uno.beans.PropertySet") );

    Reference< XInterface > xInterface = (OWeakObject*) new SbPropertyValues();

    SbxVariableRef refVar = rPar.Get(0);
    if( xInterface.is() )
    {
        // Set PropertyValues
        Any aArgAsAny = sbxToUnoValue( rPar.Get(1),
                getCppuType( (Sequence<PropertyValue>*)0 ) );
        Sequence<PropertyValue> *pArg =
                (Sequence<PropertyValue>*) aArgAsAny.getValue();
        Reference< XPropertyAccess > xPropAcc = Reference< XPropertyAccess >::query( xInterface );
        xPropAcc->setPropertyValues( *pArg );

        // Build a SbUnoObject and return it
        Any aAny;
        aAny <<= xInterface;
        SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, aAny );
        if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID )
        {
            // Return object
            refVar->PutObject( (SbUnoObject*)xUnoObj );
            return;
        }
    }

    // Object could not be created
    refVar->PutObject( NULL );
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>pointer diff. _is_ the index already<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

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

#include "propacc.hxx"

#include <tools/urlobj.hxx>
#include <tools/errcode.hxx>
#include <svl/svarray.hxx>
#include <basic/sbstar.hxx>
#include <sbunoobj.hxx>

using com::sun::star::uno::Reference;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
using namespace cppu;

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

// Declaration conversion from Sbx to UNO with known target type
Any sbxToUnoValue( SbxVariable* pVar, const Type& rType, Property* pUnoProperty = NULL );

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

#ifdef WNT
#define CDECL _cdecl
#endif
#if defined(UNX) || defined(OS2)
#define CDECL
#endif

int CDECL SbCompare_PropertyValues_Impl( const void *arg1, const void *arg2 )
{
   return ((PropertyValue*)arg1)->Name.compareTo( ((PropertyValue*)arg2)->Name );
}

extern "C" int CDECL SbCompare_UString_PropertyValue_Impl( const void *arg1, const void *arg2 )
{
    const ::rtl::OUString *pArg1 = (::rtl::OUString*) arg1;
    const PropertyValue **pArg2 = (const PropertyValue**) arg2;
    return pArg1->compareTo( (*pArg2)->Name );
}

int CDECL SbCompare_Properties_Impl( const void *arg1, const void *arg2 )
{
   return ((Property*)arg1)->Name.compareTo( ((Property*)arg2)->Name );
}

extern "C" int CDECL SbCompare_UString_Property_Impl( const void *arg1, const void *arg2 )
{
    const ::rtl::OUString *pArg1 = (::rtl::OUString*) arg1;
    const Property *pArg2 = (Property*) arg2;
    return pArg1->compareTo( pArg2->Name );
}

//----------------------------------------------------------------------------

SbPropertyValues::SbPropertyValues()
{
}

//----------------------------------------------------------------------------

SbPropertyValues::~SbPropertyValues()
{
    _xInfo = Reference< XPropertySetInfo >();

    for ( sal_uInt16 n = 0; n < _aPropVals.Count(); ++n )
        delete _aPropVals.GetObject( n );
}

//----------------------------------------------------------------------------

Reference< XPropertySetInfo > SbPropertyValues::getPropertySetInfo(void) throw( RuntimeException )
{
    // create on demand?
    if ( !_xInfo.is() )
    {
        SbPropertySetInfo *pInfo = new SbPropertySetInfo( _aPropVals );
        ((SbPropertyValues*)this)->_xInfo = (XPropertySetInfo*)pInfo;
    }
    return _xInfo;
}

//-------------------------------------------------------------------------

sal_Int32 SbPropertyValues::GetIndex_Impl( const ::rtl::OUString &rPropName ) const
{
    PropertyValue **ppPV;
    ppPV = (PropertyValue **)
            bsearch( &rPropName, _aPropVals.GetData(), _aPropVals.Count(),
                      sizeof( PropertyValue* ),
                      SbCompare_UString_PropertyValue_Impl );
    return ppPV ? ppPV - _aPropVals.GetData() : USHRT_MAX;
}

//----------------------------------------------------------------------------

void SbPropertyValues::setPropertyValue(
                    const ::rtl::OUString& aPropertyName,
                    const Any& aValue)
                    throw (::com::sun::star::beans::UnknownPropertyException,
                    ::com::sun::star::beans::PropertyVetoException,
                    ::com::sun::star::lang::IllegalArgumentException,
                    ::com::sun::star::lang::WrappedTargetException,
                    ::com::sun::star::uno::RuntimeException)
{
    sal_Int32 nIndex = GetIndex_Impl( aPropertyName );
    PropertyValue *pPropVal = _aPropVals.GetObject(
        sal::static_int_cast< sal_uInt16 >(nIndex));
    pPropVal->Value = aValue;
}

//----------------------------------------------------------------------------

Any SbPropertyValues::getPropertyValue(
                    const ::rtl::OUString& aPropertyName)
                    throw(::com::sun::star::beans::UnknownPropertyException,
                    ::com::sun::star::lang::WrappedTargetException,
                    ::com::sun::star::uno::RuntimeException)
{
    sal_Int32 nIndex = GetIndex_Impl( aPropertyName );
    if ( nIndex != USHRT_MAX )
        return _aPropVals.GetObject(
            sal::static_int_cast< sal_uInt16 >(nIndex))->Value;
    return Any();
}

//----------------------------------------------------------------------------

void SbPropertyValues::addPropertyChangeListener(
                    const ::rtl::OUString& aPropertyName,
                    const Reference< XPropertyChangeListener >& )
                    throw ()
{
    (void)aPropertyName;
}

//----------------------------------------------------------------------------

void SbPropertyValues::removePropertyChangeListener(
                    const ::rtl::OUString& aPropertyName,
                    const Reference< XPropertyChangeListener >& )
                    throw ()
{
    (void)aPropertyName;
}

//----------------------------------------------------------------------------

void SbPropertyValues::addVetoableChangeListener(
                    const ::rtl::OUString& aPropertyName,
                    const Reference< XVetoableChangeListener >& )
                    throw()
{
    (void)aPropertyName;
}

//----------------------------------------------------------------------------

void SbPropertyValues::removeVetoableChangeListener(
                    const ::rtl::OUString& aPropertyName,
                    const Reference< XVetoableChangeListener >& )
                    throw()
{
    (void)aPropertyName;
}

//----------------------------------------------------------------------------

Sequence< PropertyValue > SbPropertyValues::getPropertyValues(void) throw (::com::sun::star::uno::RuntimeException)
{
    Sequence<PropertyValue> aRet( _aPropVals.Count());
    for ( sal_uInt16 n = 0; n < _aPropVals.Count(); ++n )
        aRet.getArray()[n] = *_aPropVals.GetObject(n);
    return aRet;
}

//----------------------------------------------------------------------------

void SbPropertyValues::setPropertyValues(const Sequence< PropertyValue >& rPropertyValues )
                     throw (::com::sun::star::beans::UnknownPropertyException,
                     ::com::sun::star::beans::PropertyVetoException,
                     ::com::sun::star::lang::IllegalArgumentException,
                     ::com::sun::star::lang::WrappedTargetException,
                     ::com::sun::star::uno::RuntimeException)
{
    if ( _aPropVals.Count() )
        throw PropertyExistException();

    const PropertyValue *pPropVals = rPropertyValues.getConstArray();
    for ( sal_Int16 n = 0; n < rPropertyValues.getLength(); ++n )
    {
        PropertyValue *pPropVal = new PropertyValue(pPropVals[n]);
        _aPropVals.Insert( pPropVal, n );
    }
}

//============================================================================
//PropertySetInfoImpl

PropertySetInfoImpl::PropertySetInfoImpl()
{
}

sal_Int32 PropertySetInfoImpl::GetIndex_Impl( const ::rtl::OUString &rPropName ) const
{
    Property *pP;
    pP = (Property*)
            bsearch( &rPropName, _aProps.getConstArray(), _aProps.getLength(),
                      sizeof( Property ),
                      SbCompare_UString_Property_Impl );
    return pP ? sal::static_int_cast<sal_Int32>( (pP-_aProps.getConstArray()) / sizeof(pP) ) : -1;
}

Sequence< Property > PropertySetInfoImpl::getProperties(void) throw()
{
    return _aProps;
}

Property PropertySetInfoImpl::getPropertyByName(const ::rtl::OUString& Name) throw( RuntimeException )
{
    sal_Int32 nIndex = GetIndex_Impl( Name );
    if( USHRT_MAX != nIndex )
        return _aProps.getConstArray()[ nIndex ];
    return Property();
}

sal_Bool PropertySetInfoImpl::hasPropertyByName(const ::rtl::OUString& Name) throw( RuntimeException )
{
    sal_Int32 nIndex = GetIndex_Impl( Name );
    return USHRT_MAX != nIndex;
}

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

SbPropertySetInfo::SbPropertySetInfo()
{
}

//----------------------------------------------------------------------------

SbPropertySetInfo::SbPropertySetInfo( const SbPropertyValueArr_Impl &rPropVals )
{
    aImpl._aProps.realloc( rPropVals.Count() );
    for ( sal_uInt16 n = 0; n < rPropVals.Count(); ++n )
    {
        Property &rProp = aImpl._aProps.getArray()[n];
        const PropertyValue &rPropVal = *rPropVals.GetObject(n);
        rProp.Name = rPropVal.Name;
        rProp.Handle = rPropVal.Handle;
        rProp.Type = getCppuVoidType();
        rProp.Attributes = 0;
    }
}

//----------------------------------------------------------------------------

SbPropertySetInfo::~SbPropertySetInfo()
{
}

//-------------------------------------------------------------------------

Sequence< Property > SbPropertySetInfo::getProperties(void) throw( RuntimeException )
{
    return aImpl.getProperties();
}

Property SbPropertySetInfo::getPropertyByName(const ::rtl::OUString& Name)
    throw( RuntimeException )
{
    return aImpl.getPropertyByName( Name );
}

sal_Bool SbPropertySetInfo::hasPropertyByName(const ::rtl::OUString& Name)
    throw( RuntimeException )
{
    return aImpl.hasPropertyByName( Name );
}

//----------------------------------------------------------------------------

SbPropertyContainer::SbPropertyContainer()
{
}

//----------------------------------------------------------------------------

SbPropertyContainer::~SbPropertyContainer()
{
}

//----------------------------------------------------------------------------
void SbPropertyContainer::addProperty(const ::rtl::OUString& Name,
                                      sal_Int16 Attributes,
                                      const Any& DefaultValue)
    throw(  PropertyExistException, IllegalTypeException,
            IllegalArgumentException, RuntimeException )
{
    (void)Name;
    (void)Attributes;
    (void)DefaultValue;
}

//----------------------------------------------------------------------------
void SbPropertyContainer::removeProperty(const ::rtl::OUString& Name)
    throw( UnknownPropertyException, RuntimeException )
{
    (void)Name;
}

//----------------------------------------------------------------------------
// XPropertySetInfo
Sequence< Property > SbPropertyContainer::getProperties(void) throw ()
{
    return aImpl.getProperties();
}

Property SbPropertyContainer::getPropertyByName(const ::rtl::OUString& Name)
    throw( RuntimeException )
{
    return aImpl.getPropertyByName( Name );
}

sal_Bool SbPropertyContainer::hasPropertyByName(const ::rtl::OUString& Name)
    throw( RuntimeException )
{
    return aImpl.hasPropertyByName( Name );
}

//----------------------------------------------------------------------------

Sequence< PropertyValue > SbPropertyContainer::getPropertyValues(void)
{
    return Sequence<PropertyValue>();
}

//----------------------------------------------------------------------------

void SbPropertyContainer::setPropertyValues(const Sequence< PropertyValue >& PropertyValues_)
{
    (void)PropertyValues_;
}

//----------------------------------------------------------------------------

void RTL_Impl_CreatePropertySet( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
{
    (void)pBasic;
    (void)bWrite;

    // We need at least one parameter
    // TODO: In this case < 2 is not correct ;-)
    if ( rPar.Count() < 2 )
    {
        StarBASIC::Error( SbERR_BAD_ARGUMENT );
        return;
    }

    // Get class names of struct
    String aServiceName( RTL_CONSTASCII_USTRINGPARAM("stardiv.uno.beans.PropertySet") );

    Reference< XInterface > xInterface = (OWeakObject*) new SbPropertyValues();

    SbxVariableRef refVar = rPar.Get(0);
    if( xInterface.is() )
    {
        // Set PropertyValues
        Any aArgAsAny = sbxToUnoValue( rPar.Get(1),
                getCppuType( (Sequence<PropertyValue>*)0 ) );
        Sequence<PropertyValue> *pArg =
                (Sequence<PropertyValue>*) aArgAsAny.getValue();
        Reference< XPropertyAccess > xPropAcc = Reference< XPropertyAccess >::query( xInterface );
        xPropAcc->setPropertyValues( *pArg );

        // Build a SbUnoObject and return it
        Any aAny;
        aAny <<= xInterface;
        SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, aAny );
        if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID )
        {
            // Return object
            refVar->PutObject( (SbUnoObject*)xUnoObj );
            return;
        }
    }

    // Object could not be created
    refVar->PutObject( NULL );
}

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


<commit_before>/*
 * Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
 * Copyright CERN 2015
 * @author Maciej Suminski (maciej.suminski@cern.ch)
 *
 *    This source code is free software; you can redistribute it
 *    and/or modify it in source code form under the terms of the GNU
 *    General Public License as published by the Free Software
 *    Foundation; either version 2 of the License, or (at your option)
 *    any later version.
 *
 *    This program 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 General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

# include  "expression.h"
# include  "architec.h"
# include  <ivl_assert.h>

bool Expression::evaluate(ScopeBase*, int64_t&) const
{
      return false;
}

bool Expression::evaluate(Entity*, ScopeBase*scope, int64_t&val) const
{
      return evaluate(scope, val);
}

bool ExpArithmetic::evaluate(ScopeBase*scope, int64_t&val) const
{
      int64_t val1, val2;
      bool rc;

      rc = eval_operand1(scope, val1);
      if (rc == false)
	    return false;

      rc = eval_operand2(scope, val2);
      if (rc == false)
	    return false;

      switch (fun_) {
	  case PLUS:
	    val = val1 + val2;
	    break;
	  case MINUS:
	    val = val1 - val2;
	    break;
	  case MULT:
	    val = val1 * val2;
	    break;
	  case DIV:
	    if (val2 == 0)
		  return false;
	    val = val1 / val2;
	    break;
	  case MOD:
	    if (val2 == 0)
		  return false;
	    val = val1 % val2;
	    break;
	  case REM:
	    return false;
	  case POW:
	    return false;
	  case xCONCAT: // not possible
	    return false;
      }

      return true;
}

bool ExpAttribute::evaluate(ScopeBase*scope, int64_t&val) const
{
	/* Special Case: The array attributes can sometimes be calculated all
	   the down to a literal integer at compile time, and all it
	   needs is the type of the base expression. (The base
	   expression doesn't even need to be evaluated.) */
      if (name_ == "length" || name_ == "right" || name_ == "left") {
	    const VType*base_type = base_->peek_type();

            if(!base_type) {
                const ExpName*name = NULL;

                if(scope && (name = dynamic_cast<const ExpName*>(base_))) {
                    const perm_string& n = name->peek_name();
                    if(const Variable*var = scope->find_variable(n))
                        base_type = var->peek_type();
                    else if(const Signal*sig = scope->find_signal(n))
                        base_type = sig->peek_type();
                    else if(const InterfacePort*port = scope->find_param(n))
                        base_type = port->type;
                }
            }

            if(!base_type)
                return false;      // I tried really hard, sorry

	    const VTypeArray*arr = dynamic_cast<const VTypeArray*>(base_type);
	    if (arr == 0) {
		  cerr << get_fileline() << ": error: "
		       << "Cannot apply the 'length attribute to non-array objects"
		       << endl;
		  return false;
	    }

            if(name_ == "length") {
                int64_t size = arr->get_width(scope);

                if(size > 0)
                    val = size;
                else
                    return false;
            } else if(name_ == "left") {
		  arr->dimension(0).msb()->evaluate(scope, val);
            } else if(name_ == "right") {
		  arr->dimension(0).lsb()->evaluate(scope, val);
            } else ivl_assert(*this, false);

	    return true;
      }

      return false;
}

bool ExpAttribute::evaluate(Entity*ent, ScopeBase*scope, int64_t&val) const
{
      if (!ent || !scope) {   // it's impossible to evaluate, probably it is inside a subprogram
            return false;
      }

      if (name_ == "left" || name_ == "right") {
	    const VType*base_type = base_->peek_type();
	    if (base_type == 0)
		  base_type = base_->probe_type(ent, scope);

	    ivl_assert(*this, base_type);

	    const VTypeArray*arr = dynamic_cast<const VTypeArray*>(base_type);
	    if (arr == 0) {
		  cerr << get_fileline() << ": error: "
		       << "Cannot apply the '" << name_
		       << " attribute to non-array objects" << endl;
		  return false;
	    }

	    ivl_assert(*this, arr->dimensions() == 1);
	    if(name_ == "left")
		  arr->dimension(0).msb()->evaluate(ent, scope, val);
	    else    // "right"
		  arr->dimension(0).lsb()->evaluate(ent, scope, val);

	    return true;
      }

      return evaluate(scope, val);
}

/*
 * I don't yet know how to evaluate concatenations. It is not likely
 * to come up anyhow.
 */
bool ExpConcat::evaluate(ScopeBase*, int64_t&) const
{
      return false;
}

bool ExpName::evaluate(ScopeBase*scope, int64_t&val) const
{
      const VType*type;
      Expression*exp;

      if (prefix_.get()) {
	    cerr << get_fileline() << ": sorry: I don't know how to evaluate ExpName prefix parts." << endl;
	    return false;
      }

      if (!scope)
	    return false;

      if (!scope->find_constant(name_, type, exp))
	    return false;

      return exp->evaluate(scope, val);
}

bool ExpName::evaluate(Entity*ent, ScopeBase*scope, int64_t&val) const
{
      if (prefix_.get()) {
	    cerr << get_fileline() << ": sorry: I don't know how to evaluate ExpName prefix parts." << endl;
	    return false;
      }

      const InterfacePort*gen = ent->find_generic(name_);
      if (gen) {
	    cerr << get_fileline() << ": sorry: I don't necessarily handle generic overrides." << endl;

	      // Evaluate the default expression and use that.
	    if (gen->expr)
		  return gen->expr->evaluate(ent, scope, val);
      }

      return evaluate(scope, val);
}

bool ExpShift::evaluate(ScopeBase*scope, int64_t&val) const
{
      int64_t val1, val2;
      bool rc;

      rc = eval_operand1(scope, val1);
      if (rc == false)
	    return false;

      rc = eval_operand2(scope, val2);
      if (rc == false)
	    return false;

      switch (shift_) {
	  case SRL:
	    val = (uint64_t)val1 >> (uint64_t)val2;
	    break;
	  case SLL:
	    val = (uint64_t)val1 << (uint64_t)val2;
	    break;
	  case SRA:
	    val = (int64_t)val1 >> (int64_t)val2;
	    break;
	  case SLA:
	    val = (int64_t)val1 << (int64_t)val2;
	    break;
	  case ROR:
	  case ROL:
	    return false;
      }

      return true;
}
<commit_msg>vhdlpp: Stop compilation on invalid attributes.<commit_after>/*
 * Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
 * Copyright CERN 2015
 * @author Maciej Suminski (maciej.suminski@cern.ch)
 *
 *    This source code is free software; you can redistribute it
 *    and/or modify it in source code form under the terms of the GNU
 *    General Public License as published by the Free Software
 *    Foundation; either version 2 of the License, or (at your option)
 *    any later version.
 *
 *    This program 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 General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

# include  "expression.h"
# include  "architec.h"
# include  <ivl_assert.h>

bool Expression::evaluate(ScopeBase*, int64_t&) const
{
      return false;
}

bool Expression::evaluate(Entity*, ScopeBase*scope, int64_t&val) const
{
      return evaluate(scope, val);
}

bool ExpArithmetic::evaluate(ScopeBase*scope, int64_t&val) const
{
      int64_t val1, val2;
      bool rc;

      rc = eval_operand1(scope, val1);
      if (rc == false)
	    return false;

      rc = eval_operand2(scope, val2);
      if (rc == false)
	    return false;

      switch (fun_) {
	  case PLUS:
	    val = val1 + val2;
	    break;
	  case MINUS:
	    val = val1 - val2;
	    break;
	  case MULT:
	    val = val1 * val2;
	    break;
	  case DIV:
	    if (val2 == 0)
		  return false;
	    val = val1 / val2;
	    break;
	  case MOD:
	    if (val2 == 0)
		  return false;
	    val = val1 % val2;
	    break;
	  case REM:
	    return false;
	  case POW:
	    return false;
	  case xCONCAT: // not possible
	    return false;
      }

      return true;
}

bool ExpAttribute::evaluate(ScopeBase*scope, int64_t&val) const
{
	/* Special Case: The array attributes can sometimes be calculated all
	   the down to a literal integer at compile time, and all it
	   needs is the type of the base expression. (The base
	   expression doesn't even need to be evaluated.) */
      if (name_ == "length" || name_ == "right" || name_ == "left") {
	    const VType*base_type = base_->peek_type();

            if(!base_type) {
                const ExpName*name = NULL;

                if(scope && (name = dynamic_cast<const ExpName*>(base_))) {
                    const perm_string& n = name->peek_name();
                    if(const Variable*var = scope->find_variable(n))
                        base_type = var->peek_type();
                    else if(const Signal*sig = scope->find_signal(n))
                        base_type = sig->peek_type();
                    else if(const InterfacePort*port = scope->find_param(n))
                        base_type = port->type;
                }
            }

            if(!base_type)
                return false;      // I tried really hard, sorry

	    const VTypeArray*arr = dynamic_cast<const VTypeArray*>(base_type);
	    if (arr == 0) {
		  cerr << endl << get_fileline() << ": error: "
		       << "Cannot apply the 'length attribute to non-array objects"
		       << endl;
                  ivl_assert(*this, false);
		  return false;
	    }

            if(name_ == "length") {
                int64_t size = arr->get_width(scope);

                if(size > 0)
                    val = size;
                else
                    return false;
            } else if(name_ == "left") {
		  arr->dimension(0).msb()->evaluate(scope, val);
            } else if(name_ == "right") {
		  arr->dimension(0).lsb()->evaluate(scope, val);
            } else ivl_assert(*this, false);

	    return true;
      }

      return false;
}

bool ExpAttribute::evaluate(Entity*ent, ScopeBase*scope, int64_t&val) const
{
      if (!ent || !scope) {   // it's impossible to evaluate, probably it is inside a subprogram
            return false;
      }

      if (name_ == "left" || name_ == "right") {
	    const VType*base_type = base_->peek_type();
	    if (base_type == 0)
		  base_type = base_->probe_type(ent, scope);

	    ivl_assert(*this, base_type);

	    const VTypeArray*arr = dynamic_cast<const VTypeArray*>(base_type);
	    if (arr == 0) {
		  cerr << endl << get_fileline() << ": error: "
		       << "Cannot apply the '" << name_
		       << " attribute to non-array objects" << endl;
                  ivl_assert(*this, false);
		  return false;
	    }

	    ivl_assert(*this, arr->dimensions() == 1);
	    if(name_ == "left")
		  arr->dimension(0).msb()->evaluate(ent, scope, val);
	    else    // "right"
		  arr->dimension(0).lsb()->evaluate(ent, scope, val);

	    return true;
      }

      return evaluate(scope, val);
}

/*
 * I don't yet know how to evaluate concatenations. It is not likely
 * to come up anyhow.
 */
bool ExpConcat::evaluate(ScopeBase*, int64_t&) const
{
      return false;
}

bool ExpName::evaluate(ScopeBase*scope, int64_t&val) const
{
      const VType*type;
      Expression*exp;

      if (prefix_.get()) {
	    cerr << get_fileline() << ": sorry: I don't know how to evaluate ExpName prefix parts." << endl;
	    return false;
      }

      if (!scope)
	    return false;

      if (!scope->find_constant(name_, type, exp))
	    return false;

      return exp->evaluate(scope, val);
}

bool ExpName::evaluate(Entity*ent, ScopeBase*scope, int64_t&val) const
{
      if (prefix_.get()) {
	    cerr << get_fileline() << ": sorry: I don't know how to evaluate ExpName prefix parts." << endl;
	    return false;
      }

      const InterfacePort*gen = ent->find_generic(name_);
      if (gen) {
	    cerr << get_fileline() << ": sorry: I don't necessarily handle generic overrides." << endl;

	      // Evaluate the default expression and use that.
	    if (gen->expr)
		  return gen->expr->evaluate(ent, scope, val);
      }

      return evaluate(scope, val);
}

bool ExpShift::evaluate(ScopeBase*scope, int64_t&val) const
{
      int64_t val1, val2;
      bool rc;

      rc = eval_operand1(scope, val1);
      if (rc == false)
	    return false;

      rc = eval_operand2(scope, val2);
      if (rc == false)
	    return false;

      switch (shift_) {
	  case SRL:
	    val = (uint64_t)val1 >> (uint64_t)val2;
	    break;
	  case SLL:
	    val = (uint64_t)val1 << (uint64_t)val2;
	    break;
	  case SRA:
	    val = (int64_t)val1 >> (int64_t)val2;
	    break;
	  case SLA:
	    val = (int64_t)val1 << (int64_t)val2;
	    break;
	  case ROR:
	  case ROL:
	    return false;
      }

      return true;
}
<|endoftext|>


<commit_before>/*
Copyright (C) 2007 <SWGEmu>

This File is part of Core3.

This program 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 of the License,
or (at your option) any later version.

This program 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 program; if not, write to
the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Linking Engine3 statically or dynamically with other modules
is making a combined work based on Engine3.
Thus, the terms and conditions of the GNU Lesser General Public License
cover the whole combination.

In addition, as a special exception, the copyright holders of Engine3
give you permission to combine Engine3 program with free software
programs or libraries that are released under the GNU LGPL and with
code included in the standard release of Core3 under the GNU LGPL
license (or modified versions of such code, with unchanged license).
You may copy and distribute such a system following the terms of the
GNU LGPL for Engine3 and the licenses of the other code concerned,
provided that you include the source code of that other code when
and as the GNU LGPL requires distribution of source code.

Note that people who make modified versions of Engine3 are not obligated
to grant this special exception for their modified versions;
it is their choice whether to do so. The GNU Lesser General Public License
gives permission to release a modified version without this exception;
this exception also makes it possible to release a modified version
which carries forward this exception.
*/

#include "server/zone/objects/tangible/component/dna/DnaComponent.h"
#include "server/zone/objects/manufactureschematic/ManufactureSchematic.h"
#include "server/zone/objects/tangible/weapon/WeaponObject.h"
#include "server/zone/templates/mobile/CreatureTemplate.h"

void DnaComponentImplementation::initializeTransientMembers() {
	ComponentImplementation::initializeTransientMembers();
}

void DnaComponentImplementation::updateCraftingValues(CraftingValues* values, bool firstUpdate) {
	ComponentImplementation::updateCraftingValues(values, firstUpdate);
}
String DnaComponentImplementation::convertSpecialAttack(String &attackName) {
	if (attackName == "defaultattack")
		return "@combat_effects:none";
	else
		return "@combat_effects:" + attackName;
}
String DnaComponentImplementation::resistValue(float input){
	if (input < 0) {
		return "Vulnerable";
	} else {
		StringBuffer displayvalue;
		displayvalue << Math::getPrecision(input, 10);
		return displayvalue.toString();
	}
}
void DnaComponentImplementation::fillAttributeList(AttributeListMessage* alm, CreatureObject* object) {
	ComponentImplementation::fillAttributeList(alm,object);
	alm->insertAttribute("dna_comp_source",source);
	switch (quality){
		case 1:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_very_high");
			break;
		case 2:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_high");
			break;
		case 3:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_above_average");
			break;
		case 4:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_average");
			break;
		case 5:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_below_average");
			break;
		case 6:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_low");
			break;
		case 7:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_very_low");
			break;
	}
	alm->insertAttribute("dna_comp_hardiness",(int)hardiness);
	alm->insertAttribute("dna_comp_fortitude",(int)fortitude);
	alm->insertAttribute("dna_comp_endurance",(int)endurance);
	alm->insertAttribute("dna_comp_intellect",(int)intelligence);
	alm->insertAttribute("dna_comp_cleverness",(int)cleverness);
	alm->insertAttribute("dna_comp_dependability",(int)dependency);
	alm->insertAttribute("dna_comp_courage",(int)courage);
	alm->insertAttribute("dna_comp_dexterity",(int)dexterity);
	alm->insertAttribute("dna_comp_fierceness",(int)fierceness);
	alm->insertAttribute("dna_comp_power",(int)power);
	if (armorRating == 0)
		alm->insertAttribute("dna_comp_armor_rating","@obj_attr_n:armor_pierce_none");
	else if (armorRating == 1)
		alm->insertAttribute("dna_comp_armor_rating","@obj_attr_n:armor_pierce_light");
	else if (armorRating == 2)
		alm->insertAttribute("dna_comp_armor_rating","@obj_attr_n:armor_pierce_medium");
	else if (armorRating == 3)
		alm->insertAttribute("dna_comp_armor_rating","@obj_attr_n:armor_pierce_none");
	// Add resists
	alm->insertAttribute("dna_comp_armor_kinetic",resistValue(kinResist));
	alm->insertAttribute("dna_comp_armor_energy",resistValue(energyResist));
	alm->insertAttribute("dna_comp_armor_blast",resistValue(blastResist));
	alm->insertAttribute("dna_comp_armor_heat",resistValue(heatResist));
	alm->insertAttribute("dna_comp_armor_cold",resistValue(coldResist));
	alm->insertAttribute("dna_comp_armor_electric",resistValue(elecResist));
	alm->insertAttribute("dna_comp_armor_acid",resistValue(acidResist));
	alm->insertAttribute("dna_comp_armor_stun",resistValue(stunResist));
	alm->insertAttribute("dna_comp_armor_saber",resistValue(saberResist));
	alm->insertAttribute("spec_atk_1",convertSpecialAttack(special1));
	alm->insertAttribute("spec_atk_2",convertSpecialAttack(special2));
	alm->insertAttribute("dna_comp_ranged_attack",ranged ? "Yes" : "No");
}
<commit_msg>[fix] creature area attack should not be a special on dna sample. no combat effect is generated for this, its a command only.<commit_after>/*
Copyright (C) 2007 <SWGEmu>

This File is part of Core3.

This program 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 of the License,
or (at your option) any later version.

This program 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 program; if not, write to
the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Linking Engine3 statically or dynamically with other modules
is making a combined work based on Engine3.
Thus, the terms and conditions of the GNU Lesser General Public License
cover the whole combination.

In addition, as a special exception, the copyright holders of Engine3
give you permission to combine Engine3 program with free software
programs or libraries that are released under the GNU LGPL and with
code included in the standard release of Core3 under the GNU LGPL
license (or modified versions of such code, with unchanged license).
You may copy and distribute such a system following the terms of the
GNU LGPL for Engine3 and the licenses of the other code concerned,
provided that you include the source code of that other code when
and as the GNU LGPL requires distribution of source code.

Note that people who make modified versions of Engine3 are not obligated
to grant this special exception for their modified versions;
it is their choice whether to do so. The GNU Lesser General Public License
gives permission to release a modified version without this exception;
this exception also makes it possible to release a modified version
which carries forward this exception.
*/

#include "server/zone/objects/tangible/component/dna/DnaComponent.h"
#include "server/zone/objects/manufactureschematic/ManufactureSchematic.h"
#include "server/zone/objects/tangible/weapon/WeaponObject.h"
#include "server/zone/templates/mobile/CreatureTemplate.h"

void DnaComponentImplementation::initializeTransientMembers() {
	ComponentImplementation::initializeTransientMembers();
}

void DnaComponentImplementation::updateCraftingValues(CraftingValues* values, bool firstUpdate) {
	ComponentImplementation::updateCraftingValues(values, firstUpdate);
}
String DnaComponentImplementation::convertSpecialAttack(String &attackName) {
	// default attack and basic area attack for creatures are not valid for samples
	if (attackName == "defaultattack" || attackName == "creatureareattack")
		return "@combat_effects:none";
	else
		return "@combat_effects:" + attackName;
}
String DnaComponentImplementation::resistValue(float input){
	if (input < 0) {
		return "Vulnerable";
	} else {
		StringBuffer displayvalue;
		displayvalue << Math::getPrecision(input, 10);
		return displayvalue.toString();
	}
}
void DnaComponentImplementation::fillAttributeList(AttributeListMessage* alm, CreatureObject* object) {
	ComponentImplementation::fillAttributeList(alm,object);
	alm->insertAttribute("dna_comp_source",source);
	switch (quality){
		case 1:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_very_high");
			break;
		case 2:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_high");
			break;
		case 3:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_above_average");
			break;
		case 4:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_average");
			break;
		case 5:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_below_average");
			break;
		case 6:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_low");
			break;
		case 7:
			alm->insertAttribute("dna_comp_quality","@obj_attr_n:dna_comp_very_low");
			break;
	}
	alm->insertAttribute("dna_comp_hardiness",(int)hardiness);
	alm->insertAttribute("dna_comp_fortitude",(int)fortitude);
	alm->insertAttribute("dna_comp_endurance",(int)endurance);
	alm->insertAttribute("dna_comp_intellect",(int)intelligence);
	alm->insertAttribute("dna_comp_cleverness",(int)cleverness);
	alm->insertAttribute("dna_comp_dependability",(int)dependency);
	alm->insertAttribute("dna_comp_courage",(int)courage);
	alm->insertAttribute("dna_comp_dexterity",(int)dexterity);
	alm->insertAttribute("dna_comp_fierceness",(int)fierceness);
	alm->insertAttribute("dna_comp_power",(int)power);
	if (armorRating == 0)
		alm->insertAttribute("dna_comp_armor_rating","@obj_attr_n:armor_pierce_none");
	else if (armorRating == 1)
		alm->insertAttribute("dna_comp_armor_rating","@obj_attr_n:armor_pierce_light");
	else if (armorRating == 2)
		alm->insertAttribute("dna_comp_armor_rating","@obj_attr_n:armor_pierce_medium");
	else if (armorRating == 3)
		alm->insertAttribute("dna_comp_armor_rating","@obj_attr_n:armor_pierce_none");
	// Add resists
	alm->insertAttribute("dna_comp_armor_kinetic",resistValue(kinResist));
	alm->insertAttribute("dna_comp_armor_energy",resistValue(energyResist));
	alm->insertAttribute("dna_comp_armor_blast",resistValue(blastResist));
	alm->insertAttribute("dna_comp_armor_heat",resistValue(heatResist));
	alm->insertAttribute("dna_comp_armor_cold",resistValue(coldResist));
	alm->insertAttribute("dna_comp_armor_electric",resistValue(elecResist));
	alm->insertAttribute("dna_comp_armor_acid",resistValue(acidResist));
	alm->insertAttribute("dna_comp_armor_stun",resistValue(stunResist));
	alm->insertAttribute("dna_comp_armor_saber",resistValue(saberResist));
	alm->insertAttribute("spec_atk_1",convertSpecialAttack(special1));
	alm->insertAttribute("spec_atk_2",convertSpecialAttack(special2));
	alm->insertAttribute("dna_comp_ranged_attack",ranged ? "Yes" : "No");
}
<|endoftext|>


<commit_before><commit_msg>INTEGRATION: CWS rowlimit2 (1.28.4); FILE MERGED 2004/07/30 16:59:35 er 1.28.4.2: #i28834# reduce memory consumption of increased row limit; compressed arrays for flags and heights 2004/06/18 20:02:00 er 1.28.4.1: #i28834# increased row limit memory footprint reduction, compressed array; raw check-in before vacation<commit_after><|endoftext|>