<commit_before>/************************************************************************
	filename: 	CEGUISlider.cpp
	created:	13/4/2004
	author:		Paul D Turner

	purpose:	Implementation of Slider widget base class
*************************************************************************/
/*************************************************************************
    Crazy Eddie's GUI System (http://crayzedsgui.sourceforge.net)
    Copyright (C)2004 Paul D Turner (crayzed@users.sourceforge.net)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*************************************************************************/
#include "elements/CEGUISlider.h"
#include "elements/CEGUIThumb.h"
#include <boost/bind.hpp>

// Start of CEGUI namespace section
namespace CEGUI
{

/*************************************************************************
	Event name constants
*************************************************************************/
const utf8	Slider::ValueChanged[]		= "ValueChanged";

/*************************************************************************
	Slider base class constructor
*************************************************************************/
Slider::Slider(const String& type, const String& name) :
	Window(type, name),
	d_value(0.0f),
	d_maxValue(1.0f),
	d_step(0.01f),
	d_thumb(NULL)
{
	addSliderEvents();
}

/*************************************************************************
	Slider base class destructor
*************************************************************************/
Slider::~Slider(void)
{
}

/*************************************************************************
	Initialises the Window based object ready for use.
*************************************************************************/
void Slider::initialise(void)
{
	// create and attach thumb
	d_thumb = createThumb();
	addChildWindow(d_thumb);

	// bind handler to thumb event triggered when thumb moves
	d_thumb->subscribeEvent(Thumb::ThumbPositionChanged, boost::bind(&CEGUI::Slider::handleThumbMoved, this, _1));

	layoutComponentWidgets();
}

/*************************************************************************
	set the maximum value for the slider.
	Note that the minimum value is fixed at 0.
*************************************************************************/
void Slider::setMaxValue(float maxVal)
{
	d_maxValue = maxVal;

	float oldval = d_value;

	// limit current value to be within new max
	if (d_value > d_maxValue) {
		d_value = d_maxValue;
	}

	updateThumb();

	// send notification if slider value changed.
	if (d_value != oldval)
	{
		onValueChanged(WindowEventArgs(this));
	}

}

/*************************************************************************
	set the current slider value.
*************************************************************************/
void Slider::setCurrentValue(float value)
{
	float oldval = d_value;

	// range for value: 0 <= value <= maxValue
	d_value = (value <= d_maxValue) ? value : d_maxValue;

	updateThumb();

	// send notification if slider value changed.
	if (d_value != oldval)
	{
		onValueChanged(WindowEventArgs(this));
	}

}

/*************************************************************************
	Add slider specific events
*************************************************************************/
void Slider::addSliderEvents(void)
{
	addEvent(ValueChanged);
}

/*************************************************************************
	Handler triggered when the slider value changes
*************************************************************************/
void Slider::onValueChanged(WindowEventArgs& e)
{
	fireEvent(ValueChanged, e);
}

/*************************************************************************
	Handler for when a mouse button is pressed
*************************************************************************/
void Slider::onMouseButtonDown(MouseEventArgs& e)
{
	// base class processing
	Window::onMouseButtonDown(e);

	if (e.button == LeftButton)
	{
		float adj = getAdjustDirectionFromPoint(e.position);

		// adjust slider position in whichever direction as required.
		if (adj != 0)
		{
			setCurrentValue(d_value + (adj * d_step));
		}

		e.handled = true;
	}

}

/*************************************************************************
	Handler for when the size of the slider widget changes.
*************************************************************************/
void Slider::onSized(EventArgs& e)
{
	// base class processing
	Window::onSized(e);

	layoutComponentWidgets();

	e.handled = true;
}

/*************************************************************************
	handler function for when thumb moves.
*************************************************************************/
void Slider::handleThumbMoved(const EventArgs& e)
{
	setCurrentValue(getValueFromThumb());
}

} // End of  CEGUI namespace section
<commit_msg>Bug fix to range checking in CEGUI::Slider::setCurrentValue.<commit_after>/************************************************************************
	filename: 	CEGUISlider.cpp
	created:	13/4/2004
	author:		Paul D Turner

	purpose:	Implementation of Slider widget base class
*************************************************************************/
/*************************************************************************
    Crazy Eddie's GUI System (http://crayzedsgui.sourceforge.net)
    Copyright (C)2004 Paul D Turner (crayzed@users.sourceforge.net)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*************************************************************************/
#include "elements/CEGUISlider.h"
#include "elements/CEGUIThumb.h"
#include <boost/bind.hpp>

// Start of CEGUI namespace section
namespace CEGUI
{

/*************************************************************************
	Event name constants
*************************************************************************/
const utf8	Slider::ValueChanged[]		= "ValueChanged";

/*************************************************************************
	Slider base class constructor
*************************************************************************/
Slider::Slider(const String& type, const String& name) :
	Window(type, name),
	d_value(0.0f),
	d_maxValue(1.0f),
	d_step(0.01f),
	d_thumb(NULL)
{
	addSliderEvents();
}

/*************************************************************************
	Slider base class destructor
*************************************************************************/
Slider::~Slider(void)
{
}

/*************************************************************************
	Initialises the Window based object ready for use.
*************************************************************************/
void Slider::initialise(void)
{
	// create and attach thumb
	d_thumb = createThumb();
	addChildWindow(d_thumb);

	// bind handler to thumb event triggered when thumb moves
	d_thumb->subscribeEvent(Thumb::ThumbPositionChanged, boost::bind(&CEGUI::Slider::handleThumbMoved, this, _1));

	layoutComponentWidgets();
}

/*************************************************************************
	set the maximum value for the slider.
	Note that the minimum value is fixed at 0.
*************************************************************************/
void Slider::setMaxValue(float maxVal)
{
	d_maxValue = maxVal;

	float oldval = d_value;

	// limit current value to be within new max
	if (d_value > d_maxValue) {
		d_value = d_maxValue;
	}

	updateThumb();

	// send notification if slider value changed.
	if (d_value != oldval)
	{
		onValueChanged(WindowEventArgs(this));
	}

}

/*************************************************************************
	set the current slider value.
*************************************************************************/
void Slider::setCurrentValue(float value)
{
	float oldval = d_value;

	// range for value: 0 <= value <= maxValue
	d_value = (value >= 0.0f) ? ((value <= d_maxValue) ? value : d_maxValue) : 0.0f;

	updateThumb();

	// send notification if slider value changed.
	if (d_value != oldval)
	{
		onValueChanged(WindowEventArgs(this));
	}

}

/*************************************************************************
	Add slider specific events
*************************************************************************/
void Slider::addSliderEvents(void)
{
	addEvent(ValueChanged);
}

/*************************************************************************
	Handler triggered when the slider value changes
*************************************************************************/
void Slider::onValueChanged(WindowEventArgs& e)
{
	fireEvent(ValueChanged, e);
}

/*************************************************************************
	Handler for when a mouse button is pressed
*************************************************************************/
void Slider::onMouseButtonDown(MouseEventArgs& e)
{
	// base class processing
	Window::onMouseButtonDown(e);

	if (e.button == LeftButton)
	{
		float adj = getAdjustDirectionFromPoint(e.position);

		// adjust slider position in whichever direction as required.
		if (adj != 0)
		{
			setCurrentValue(d_value + (adj * d_step));
		}

		e.handled = true;
	}

}

/*************************************************************************
	Handler for when the size of the slider widget changes.
*************************************************************************/
void Slider::onSized(EventArgs& e)
{
	// base class processing
	Window::onSized(e);

	layoutComponentWidgets();

	e.handled = true;
}

/*************************************************************************
	handler function for when thumb moves.
*************************************************************************/
void Slider::handleThumbMoved(const EventArgs& e)
{
	setCurrentValue(getValueFromThumb());
}

} // End of  CEGUI namespace section
<|endoftext|>


<commit_before>/************************************************************************
	filename: 	CEGUIStatic.cpp
	created:	13/4/2004
	author:		Paul D Turner

	purpose:	Implementation of Static widget base class
*************************************************************************/
/*************************************************************************
    Crazy Eddie's GUI System (http://crayzedsgui.sourceforge.net)
    Copyright (C)2004 Paul D Turner (crayzed@users.sourceforge.net)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*************************************************************************/
#include "elements/CEGUIStatic.h"
#include "CEGUIImagesetManager.h"
#include "CEGUIImageset.h"

// Start of CEGUI namespace section
namespace CEGUI
{
/*************************************************************************
	Definitions of Properties for this class
*************************************************************************/
StaticProperties::FrameEnabled				Static::d_frameEnabledProperty;
StaticProperties::BackgroundEnabled			Static::d_backgroundEnabledProperty;
StaticProperties::FrameColours				Static::d_frameColoursProperty;
StaticProperties::BackgroundColours			Static::d_backgroundColoursProperty;
StaticProperties::BackgroundImage			Static::d_backgroundImageProperty;
StaticProperties::TopLeftFrameImage			Static::d_topLeftFrameProperty;
StaticProperties::TopRightFrameImage		Static::d_topRightFrameProperty;
StaticProperties::BottomLeftFrameImage		Static::d_bottomLeftFrameProperty;
StaticProperties::BottomRightFrameImage		Static::d_bottomRightFrameProperty;
StaticProperties::LeftFrameImage			Static::d_leftFrameProperty;
StaticProperties::RightFrameImage			Static::d_rightFrameProperty;
StaticProperties::TopFrameImage				Static::d_topFrameProperty;
StaticProperties::BottomFrameImage			Static::d_bottomFrameProperty;

/*************************************************************************
	Constructor for static widget base class
*************************************************************************/
Static::Static(const String& type, const String& name) :
	Window(type, name),
	d_frameEnabled(false),
	d_frameCols(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF),
	d_backgroundCols(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)
{
	addStaticProperties();
}

/*************************************************************************
	Destructor for static widget base class.
*************************************************************************/
Static::~Static(void)
{
}

/*************************************************************************
	overridden so derived classes are auto-clipped to within the inner
	area of the frame when it's active.
*************************************************************************/
Rect Static::getUnclippedInnerRect(void) const
{
	// if frame is enabled, return rect for area inside frame
	if (d_frameEnabled)
	{
		Rect tmp(Window::getUnclippedInnerRect());
		tmp.d_left		+= d_left_width;
		tmp.d_right		-= d_right_width;
		tmp.d_top		+= d_top_height;
		tmp.d_bottom	-= d_bottom_height;
		return tmp;
	}
	// no frame, so return default inner rect.
	else
	{
		return Window::getUnclippedInnerRect();
	}

}

/*************************************************************************
	Enable or disable rendering of the frame for this static widget.
*************************************************************************/
void Static::setFrameEnabled(bool setting)
{
	if (d_frameEnabled != setting)
	{
		d_frameEnabled = setting;
		WindowEventArgs args(this);
		onStaticFrameChanged(args);
		requestRedraw();
	}
}

/*************************************************************************
	specify the Image objects to use for each part of the frame.
	A NULL may be used to omit any part.
*************************************************************************/
void Static::setFrameImages(const Image* topleft, const Image* topright, const Image* bottomleft, const Image* bottomright, const Image* left, const Image* top, const Image* right, const Image* bottom)
{
	// install the new images into the RenderableFrame
	d_frame.setImages(topleft, topright, bottomleft, bottomright, left, top, right, bottom);

	// get sizes of frame edges
	d_left_width	= (left != NULL) ? left->getWidth() : 0.0f;
	d_right_width	= (right != NULL) ? right->getWidth() : 0.0f;
	d_top_height	= (top != NULL) ? top->getHeight() : 0.0f;
	d_bottom_height	= (bottom != NULL) ? bottom->getHeight() : 0.0f;

	// redraw only if change would be seen.
	if (d_frameEnabled)
	{
		WindowEventArgs args(this);
		onStaticFrameChanged(args);
		requestRedraw();
	}

}

/*************************************************************************
	Sets the colours to be applied when rendering the frame
*************************************************************************/
void Static::setFrameColours(const ColourRect& colours)
{
	d_frameCols = colours;
	updateRenderableFrameColours();

	// redraw only if change would be seen.
	if (d_frameEnabled)
	{
		WindowEventArgs args(this);
		onStaticFrameChanged(args);
		requestRedraw();
	}

}

/*************************************************************************
	Sets the colours to be applied when rendering the frame
*************************************************************************/
void Static::setFrameColours(colour top_left_colour, colour top_right_colour, colour bottom_left_colour, colour bottom_right_colour)
{
	d_frameCols.d_top_left		= top_left_colour;
	d_frameCols.d_top_right		= top_right_colour;
	d_frameCols.d_bottom_left	= bottom_left_colour;
	d_frameCols.d_bottom_right	= bottom_right_colour;
	updateRenderableFrameColours();

	// redraw only if change would be seen.
	if (d_frameEnabled)
	{
		WindowEventArgs args(this);
		onStaticFrameChanged(args);
		requestRedraw();
	}

}

/*************************************************************************
	Enable or disable rendering of the background for this static widget.
*************************************************************************/
void Static::setBackgroundEnabled(bool setting)
{
	if (d_backgroundEnabled != setting)
	{
		d_backgroundEnabled = setting;
		requestRedraw();
	}

}

/*************************************************************************
	Set the image to use as the background for the static widget.
*************************************************************************/
void Static::setBackgroundImage(const Image* image)
{
	d_background = image;

	if (d_backgroundEnabled)
	{
		requestRedraw();
	}

}

/*************************************************************************
	Set the image to use as the background for the static widget.
*************************************************************************/
void Static::setBackgroundImage(const String& imageset, const String& image)
{
	setBackgroundImage(&ImagesetManager::getSingleton().getImageset(imageset)->getImage(image));
}

/*************************************************************************
	Sets the colours to be applied when rendering the background.
*************************************************************************/
void Static::setBackgroundColours(const ColourRect& colours)
{
	d_backgroundCols = colours;

	if (d_backgroundEnabled)
	{
		requestRedraw();
	}

}

/*************************************************************************
	Sets the colours to be applied when rendering the background.
*************************************************************************/
void Static::setBackgroundColours(colour top_left_colour, colour top_right_colour, colour bottom_left_colour, colour bottom_right_colour)
{
	d_backgroundCols.d_top_left		= top_left_colour;
	d_backgroundCols.d_top_right	= top_right_colour;
	d_backgroundCols.d_bottom_left	= bottom_left_colour;
	d_backgroundCols.d_bottom_right	= bottom_right_colour;

	if (d_backgroundEnabled)
	{
		requestRedraw();
	}

}

/*************************************************************************
	update the internal RenderableFrame with currently set colours and
	alpha settings.
*************************************************************************/
void Static::updateRenderableFrameColours(void)
{
	float alpha = getEffectiveAlpha();

	d_frame.setColours(
		calculateModulatedAlphaColour(d_frameCols.d_top_left, alpha),
		calculateModulatedAlphaColour(d_frameCols.d_top_right, alpha),
		calculateModulatedAlphaColour(d_frameCols.d_bottom_left, alpha),
		calculateModulatedAlphaColour(d_frameCols.d_bottom_right, alpha)
	);

}

/*************************************************************************
	given an ARGB colour value and a alpha float value return the colour
	value with the alpha component modulated by the given alpha float.
*************************************************************************/
colour Static::calculateModulatedAlphaColour(colour col, float alpha) const
{
	return ((col & 0x00FFFFFF) | (((colour)(((float)(col >> 24)) * alpha)) << 24));
}

/*************************************************************************
	Perform the actual rendering for this Window.
*************************************************************************/
void Static::drawSelf(float z)
{
	Rect clipper(getPixelRect());

	// do nothing if the widget is totally clipped.
	if (clipper.getWidth() == 0)
	{
		return;
	}

	Rect absrect(getUnclippedPixelRect());

	// draw frame
	if (d_frameEnabled)
	{
		d_frame.draw(Vector3(absrect.d_left, absrect.d_top, z), clipper);

		// adjust absrect and clipper so that later stages of render to not overwite frame
		absrect.d_left		+= d_left_width;
		absrect.d_right		-= d_right_width;
		absrect.d_top		+= d_top_height;
		absrect.d_bottom	-= d_bottom_height;

		clipper = clipper.getIntersection(absrect);
	}

	// draw backdrop
	if (d_backgroundEnabled && (d_background != NULL))
	{
		// factor window alpha into colours to use when rendering background
		float alpha = getEffectiveAlpha();
		ColourRect colours;
		colours.d_top_left		= calculateModulatedAlphaColour(d_backgroundCols.d_top_left, alpha);
		colours.d_top_right		= calculateModulatedAlphaColour(d_backgroundCols.d_top_right, alpha);
		colours.d_bottom_left	= calculateModulatedAlphaColour(d_backgroundCols.d_bottom_left, alpha);
		colours.d_bottom_right	= calculateModulatedAlphaColour(d_backgroundCols.d_bottom_right, alpha);

		d_background->draw(absrect, z, clipper, colours);
	}

}

/*************************************************************************
	Handler for when window is sized
*************************************************************************/
void Static::onSized(WindowEventArgs& e)
{
	// base class processing
	Window::onSized(e);

	// update frame size.
	d_frame.setSize(getAbsoluteSize());

	e.handled = true;
}

/*************************************************************************
	Handler for when alpha value changes
*************************************************************************/
void Static::onAlphaChanged(WindowEventArgs& e)
{
	// base class processing
	Window::onAlphaChanged(e);

	// update frame colours to use new alpha value
	updateRenderableFrameColours();

	e.handled = true;
}

/*************************************************************************
	Return the Image being used for the specified location of the frame.
*************************************************************************/
const Image* Static::getImageForFrameLocation(FrameLocation location) const
{
	return d_frame.getImageForLocation(location);
}

/*************************************************************************
	Return the Image currently set as the background image for the widget.
*************************************************************************/
const Image* Static::getBackgroundImage(void) const
{
	return d_background;
}

/*************************************************************************
	Set the Image to use for the specified location of the frame.
*************************************************************************/
void Static::setImageForFrameLocation(FrameLocation location, const Image* image)
{
	d_frame.setImageForLocation(location, image);
}

/*************************************************************************
	Adds properties for the static widget base class
*************************************************************************/
void Static::addStaticProperties(void)
{
	addProperty(&d_frameEnabledProperty);
	addProperty(&d_backgroundEnabledProperty);
	addProperty(&d_frameColoursProperty);
	addProperty(&d_backgroundColoursProperty);
	addProperty(&d_backgroundImageProperty);
	addProperty(&d_topLeftFrameProperty);
	addProperty(&d_topRightFrameProperty);
	addProperty(&d_bottomLeftFrameProperty);
	addProperty(&d_bottomRightFrameProperty);
	addProperty(&d_leftFrameProperty);
	addProperty(&d_topFrameProperty);
	addProperty(&d_rightFrameProperty);
	addProperty(&d_bottomFrameProperty);
}

} // End of  CEGUI namespace section
<commit_msg>Fixed Static::setImageForFrameLocation to update state properly so backgound image is set to correct size.<commit_after>/************************************************************************
	filename: 	CEGUIStatic.cpp
	created:	13/4/2004
	author:		Paul D Turner

	purpose:	Implementation of Static widget base class
*************************************************************************/
/*************************************************************************
    Crazy Eddie's GUI System (http://crayzedsgui.sourceforge.net)
    Copyright (C)2004 Paul D Turner (crayzed@users.sourceforge.net)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*************************************************************************/
#include "elements/CEGUIStatic.h"
#include "CEGUIImagesetManager.h"
#include "CEGUIImageset.h"

// Start of CEGUI namespace section
namespace CEGUI
{
/*************************************************************************
	Definitions of Properties for this class
*************************************************************************/
StaticProperties::FrameEnabled				Static::d_frameEnabledProperty;
StaticProperties::BackgroundEnabled			Static::d_backgroundEnabledProperty;
StaticProperties::FrameColours				Static::d_frameColoursProperty;
StaticProperties::BackgroundColours			Static::d_backgroundColoursProperty;
StaticProperties::BackgroundImage			Static::d_backgroundImageProperty;
StaticProperties::TopLeftFrameImage			Static::d_topLeftFrameProperty;
StaticProperties::TopRightFrameImage		Static::d_topRightFrameProperty;
StaticProperties::BottomLeftFrameImage		Static::d_bottomLeftFrameProperty;
StaticProperties::BottomRightFrameImage		Static::d_bottomRightFrameProperty;
StaticProperties::LeftFrameImage			Static::d_leftFrameProperty;
StaticProperties::RightFrameImage			Static::d_rightFrameProperty;
StaticProperties::TopFrameImage				Static::d_topFrameProperty;
StaticProperties::BottomFrameImage			Static::d_bottomFrameProperty;

/*************************************************************************
	Constructor for static widget base class
*************************************************************************/
Static::Static(const String& type, const String& name) :
	Window(type, name),
	d_frameEnabled(false),
	d_frameCols(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF),
	d_backgroundCols(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)
{
	addStaticProperties();
}

/*************************************************************************
	Destructor for static widget base class.
*************************************************************************/
Static::~Static(void)
{
}

/*************************************************************************
	overridden so derived classes are auto-clipped to within the inner
	area of the frame when it's active.
*************************************************************************/
Rect Static::getUnclippedInnerRect(void) const
{
	// if frame is enabled, return rect for area inside frame
	if (d_frameEnabled)
	{
		Rect tmp(Window::getUnclippedInnerRect());
		tmp.d_left		+= d_left_width;
		tmp.d_right		-= d_right_width;
		tmp.d_top		+= d_top_height;
		tmp.d_bottom	-= d_bottom_height;
		return tmp;
	}
	// no frame, so return default inner rect.
	else
	{
		return Window::getUnclippedInnerRect();
	}

}

/*************************************************************************
	Enable or disable rendering of the frame for this static widget.
*************************************************************************/
void Static::setFrameEnabled(bool setting)
{
	if (d_frameEnabled != setting)
	{
		d_frameEnabled = setting;
		WindowEventArgs args(this);
		onStaticFrameChanged(args);
		requestRedraw();
	}
}

/*************************************************************************
	specify the Image objects to use for each part of the frame.
	A NULL may be used to omit any part.
*************************************************************************/
void Static::setFrameImages(const Image* topleft, const Image* topright, const Image* bottomleft, const Image* bottomright, const Image* left, const Image* top, const Image* right, const Image* bottom)
{
	// install the new images into the RenderableFrame
	d_frame.setImages(topleft, topright, bottomleft, bottomright, left, top, right, bottom);

	// get sizes of frame edges
	d_left_width	= (left != NULL) ? left->getWidth() : 0.0f;
	d_right_width	= (right != NULL) ? right->getWidth() : 0.0f;
	d_top_height	= (top != NULL) ? top->getHeight() : 0.0f;
	d_bottom_height	= (bottom != NULL) ? bottom->getHeight() : 0.0f;

	// redraw only if change would be seen.
	if (d_frameEnabled)
	{
		WindowEventArgs args(this);
		onStaticFrameChanged(args);
		requestRedraw();
	}

}

/*************************************************************************
	Sets the colours to be applied when rendering the frame
*************************************************************************/
void Static::setFrameColours(const ColourRect& colours)
{
	d_frameCols = colours;
	updateRenderableFrameColours();

	// redraw only if change would be seen.
	if (d_frameEnabled)
	{
		WindowEventArgs args(this);
		onStaticFrameChanged(args);
		requestRedraw();
	}

}

/*************************************************************************
	Sets the colours to be applied when rendering the frame
*************************************************************************/
void Static::setFrameColours(colour top_left_colour, colour top_right_colour, colour bottom_left_colour, colour bottom_right_colour)
{
	d_frameCols.d_top_left		= top_left_colour;
	d_frameCols.d_top_right		= top_right_colour;
	d_frameCols.d_bottom_left	= bottom_left_colour;
	d_frameCols.d_bottom_right	= bottom_right_colour;
	updateRenderableFrameColours();

	// redraw only if change would be seen.
	if (d_frameEnabled)
	{
		WindowEventArgs args(this);
		onStaticFrameChanged(args);
		requestRedraw();
	}

}

/*************************************************************************
	Enable or disable rendering of the background for this static widget.
*************************************************************************/
void Static::setBackgroundEnabled(bool setting)
{
	if (d_backgroundEnabled != setting)
	{
		d_backgroundEnabled = setting;
		requestRedraw();
	}

}

/*************************************************************************
	Set the image to use as the background for the static widget.
*************************************************************************/
void Static::setBackgroundImage(const Image* image)
{
	d_background = image;

	if (d_backgroundEnabled)
	{
		requestRedraw();
	}

}

/*************************************************************************
	Set the image to use as the background for the static widget.
*************************************************************************/
void Static::setBackgroundImage(const String& imageset, const String& image)
{
	setBackgroundImage(&ImagesetManager::getSingleton().getImageset(imageset)->getImage(image));
}

/*************************************************************************
	Sets the colours to be applied when rendering the background.
*************************************************************************/
void Static::setBackgroundColours(const ColourRect& colours)
{
	d_backgroundCols = colours;

	if (d_backgroundEnabled)
	{
		requestRedraw();
	}

}

/*************************************************************************
	Sets the colours to be applied when rendering the background.
*************************************************************************/
void Static::setBackgroundColours(colour top_left_colour, colour top_right_colour, colour bottom_left_colour, colour bottom_right_colour)
{
	d_backgroundCols.d_top_left		= top_left_colour;
	d_backgroundCols.d_top_right	= top_right_colour;
	d_backgroundCols.d_bottom_left	= bottom_left_colour;
	d_backgroundCols.d_bottom_right	= bottom_right_colour;

	if (d_backgroundEnabled)
	{
		requestRedraw();
	}

}

/*************************************************************************
	update the internal RenderableFrame with currently set colours and
	alpha settings.
*************************************************************************/
void Static::updateRenderableFrameColours(void)
{
	float alpha = getEffectiveAlpha();

	d_frame.setColours(
		calculateModulatedAlphaColour(d_frameCols.d_top_left, alpha),
		calculateModulatedAlphaColour(d_frameCols.d_top_right, alpha),
		calculateModulatedAlphaColour(d_frameCols.d_bottom_left, alpha),
		calculateModulatedAlphaColour(d_frameCols.d_bottom_right, alpha)
	);

}

/*************************************************************************
	given an ARGB colour value and a alpha float value return the colour
	value with the alpha component modulated by the given alpha float.
*************************************************************************/
colour Static::calculateModulatedAlphaColour(colour col, float alpha) const
{
	return ((col & 0x00FFFFFF) | (((colour)(((float)(col >> 24)) * alpha)) << 24));
}

/*************************************************************************
	Perform the actual rendering for this Window.
*************************************************************************/
void Static::drawSelf(float z)
{
	Rect clipper(getPixelRect());

	// do nothing if the widget is totally clipped.
	if (clipper.getWidth() == 0)
	{
		return;
	}

	Rect absrect(getUnclippedPixelRect());

	// draw frame
	if (d_frameEnabled)
	{
		d_frame.draw(Vector3(absrect.d_left, absrect.d_top, z), clipper);

		// adjust absrect and clipper so that later stages of render to not overwite frame
		absrect.d_left		+= d_left_width;
		absrect.d_right		-= d_right_width;
		absrect.d_top		+= d_top_height;
		absrect.d_bottom	-= d_bottom_height;

		clipper = clipper.getIntersection(absrect);
	}

	// draw backdrop
	if (d_backgroundEnabled && (d_background != NULL))
	{
		// factor window alpha into colours to use when rendering background
		float alpha = getEffectiveAlpha();
		ColourRect colours;
		colours.d_top_left		= calculateModulatedAlphaColour(d_backgroundCols.d_top_left, alpha);
		colours.d_top_right		= calculateModulatedAlphaColour(d_backgroundCols.d_top_right, alpha);
		colours.d_bottom_left	= calculateModulatedAlphaColour(d_backgroundCols.d_bottom_left, alpha);
		colours.d_bottom_right	= calculateModulatedAlphaColour(d_backgroundCols.d_bottom_right, alpha);

		d_background->draw(absrect, z, clipper, colours);
	}

}

/*************************************************************************
	Handler for when window is sized
*************************************************************************/
void Static::onSized(WindowEventArgs& e)
{
	// base class processing
	Window::onSized(e);

	// update frame size.
	d_frame.setSize(getAbsoluteSize());

	e.handled = true;
}

/*************************************************************************
	Handler for when alpha value changes
*************************************************************************/
void Static::onAlphaChanged(WindowEventArgs& e)
{
	// base class processing
	Window::onAlphaChanged(e);

	// update frame colours to use new alpha value
	updateRenderableFrameColours();

	e.handled = true;
}

/*************************************************************************
	Return the Image being used for the specified location of the frame.
*************************************************************************/
const Image* Static::getImageForFrameLocation(FrameLocation location) const
{
	return d_frame.getImageForLocation(location);
}

/*************************************************************************
	Return the Image currently set as the background image for the widget.
*************************************************************************/
const Image* Static::getBackgroundImage(void) const
{
	return d_background;
}

/*************************************************************************
	Set the Image to use for the specified location of the frame.
*************************************************************************/
void Static::setImageForFrameLocation(FrameLocation location, const Image* image)
{
	d_frame.setImageForLocation(location, image);

	// update our record of image size
	switch (location)
	{
	case LeftEdge:
		d_left_width = (image != NULL) ? image->getWidth() : 0;
		break;

	case RightEdge:
		d_right_width = (image != NULL) ? image->getWidth() : 0;
		break;

	case TopEdge:
		d_top_height = (image != NULL) ? image->getHeight() : 0;
		break;

	case BottomEdge:
		d_bottom_height = (image != NULL) ? image->getHeight() : 0;
		break;

	default:
		break;
	}

}

/*************************************************************************
	Adds properties for the static widget base class
*************************************************************************/
void Static::addStaticProperties(void)
{
	addProperty(&d_frameEnabledProperty);
	addProperty(&d_backgroundEnabledProperty);
	addProperty(&d_frameColoursProperty);
	addProperty(&d_backgroundColoursProperty);
	addProperty(&d_backgroundImageProperty);
	addProperty(&d_topLeftFrameProperty);
	addProperty(&d_topRightFrameProperty);
	addProperty(&d_bottomLeftFrameProperty);
	addProperty(&d_bottomRightFrameProperty);
	addProperty(&d_leftFrameProperty);
	addProperty(&d_topFrameProperty);
	addProperty(&d_rightFrameProperty);
	addProperty(&d_bottomFrameProperty);
}

} // End of  CEGUI namespace section
<|endoftext|>


<commit_before>#include "App.h"

#include "error.h"
#include "OsPath.h"

int App::run() {
  // TODO:
  // put merged repositories to the project from config, options; and more
  // (repositories from options have more priority - put in the beginning)
  // create/init project
  // create/init build
  // compile

  // TODO:
  // make watch mode from command line options,
  // incremental build.

  return ERROR_OK;
}

int App::initOptions(int argc, const char *argv[]) {
  return argParser.parse(options, argc, argv);
}

int App::initConfig() {
  std::string content;
  int error = loadConfig(content);
  if (error < ERROR_OK) return error;

  return iniParser(config, content);
}

int App::loadConfig(std::string& content) {
  // take DEFAULT_CONFIG_PATH or overriden from options
  auto search = options.flags.find(CONFIG_FLAG);
  std::string path = search != options.flags.end() ?
    search->second : DEFAULT_CONFIG_PATH;

  if (!OsPath::exists(path) || !OsPath::isFile(path))
    return APP_CONFIG_NOT_EXISTS;

  content = OsPath::load(path);
  return ERROR_OK;
}
<commit_msg>fix iniParser.parse<commit_after>#include "App.h"

#include "error.h"
#include "OsPath.h"

int App::run() {
  // TODO:
  // put merged repositories to the project from config, options; and more
  // (repositories from options have more priority - put in the beginning)
  // create/init project
  // create/init build
  // compile

  // TODO:
  // make watch mode from command line options,
  // incremental build.

  return ERROR_OK;
}

int App::initOptions(int argc, const char *argv[]) {
  return argParser.parse(options, argc, argv);
}

int App::initConfig() {
  std::string content;
  int error = loadConfig(content);
  if (error < ERROR_OK) return error;

  return iniParser.parse(config, content);
}

int App::loadConfig(std::string& content) {
  // take DEFAULT_CONFIG_PATH or overriden from options
  auto search = options.flags.find(CONFIG_FLAG);
  std::string path = search != options.flags.end() ?
    search->second : DEFAULT_CONFIG_PATH;

  if (!OsPath::exists(path) || !OsPath::isFile(path))
    return APP_CONFIG_NOT_EXISTS;

  content = OsPath::load(path);
  return ERROR_OK;
}
<|endoftext|>


<commit_before>#include "system/Logger.hpp"
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <glm/gtx/io.hpp>

#ifdef _WIN32
#	include <io.h>
#	include <cstdio>
#else
#	include <unistd.h>
#endif

// We statically initialize the default logger.
// We don't really care about its exact construction/destruction moments,
// but we want it to always be created.
Log * Log::_defaultLogger = new Log();

void Log::set(Level l) {
	_level		  = l;
	_appendPrefix = true;
	if(_level == Level::VERBOSE && !_verbose) {
		// In this case, we want to ignore until the next flush.
		_ignoreUntilFlush = true;
		_appendPrefix	 = false;
	}
}

Log::Log() {

	// Setup glm objects delimiters.
	_stream << glm::io::delimeter<char>('(', ')', ',');

#ifdef _WIN32
	// Enable color output.
	HANDLE h = GetStdHandle( STD_OUTPUT_HANDLE );
	if( h != INVALID_HANDLE_VALUE ) {
		DWORD dwMode = 0;
		if( GetConsoleMode( h, &dwMode ) ) {
			dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
			if( SetConsoleMode( h, dwMode ) ) {
				_useColors = true;
			}
		}
	}

#else
	// Check if the output is indeed a terminal, and not piped.
	const bool isTerminal = isatty(fileno(stdout));
	char * env_p		  = std::getenv("TERM");
	if(isTerminal && env_p) {
		// Check if the output support colors.
		const std::vector<std::string> terms = {"xterm", "xterm-256", "xterm-256color", "vt100", "color", "ansi", "cygwin", "linux"};
		const std::string term(env_p);
		for(const auto & possibleTerm : terms) {
			if(term == possibleTerm) {
				_useColors = true;
				break;
			}
		}
	}
#endif
}

Log::Log(const std::string & filePath, bool logToStdin, bool verbose) :
	_logToStdOut(logToStdin), _verbose(verbose) {

	// Setup glm objects delimiters.
	_stream << glm::io::delimeter<char>('(', ')', ',');
	// Create file if it doesnt exist.
	setFile(filePath, false);
}

void Log::setFile(const std::string & filePath, bool flushExisting) {
	if(flushExisting) {
		_stream << std::endl;
		flush();
	}
	if(_file.is_open()) {
		_file.close();
	}
	_file.open(filePath, std::ofstream::app);
	if(_file.is_open()) {
		_file << "-- New session - " << time(nullptr) << " -------------------------------" << std::endl;
		_useColors = false;
	} else {
		std::cerr << "[Logger] Unable to create log file at path " << filePath << "." << std::endl;
	}
}

void Log::setVerbose(bool verbose) {
	_verbose = verbose;
}

void Log::setDefaultFile(const std::string & filePath) {
	_defaultLogger->setFile(filePath);
}

void Log::setDefaultVerbose(bool verbose) {
	_defaultLogger->setVerbose(verbose);
}

Log & Log::Info() {
	_defaultLogger->set(Level::INFO);
	return *_defaultLogger;
}

Log & Log::Warning() {
	_defaultLogger->set(Level::WARNING);
	return *_defaultLogger;
}

Log & Log::Error() {
	_defaultLogger->set(Level::ERROR);
	return *_defaultLogger;
}

Log & Log::Verbose() {
	_defaultLogger->set(Level::VERBOSE);
	return *_defaultLogger;
}

void Log::flush() {
	if(!_ignoreUntilFlush) {
		const std::string finalStr = _stream.str();

		if(_logToStdOut) {
			if(_level == Level::INFO || _level == Level::VERBOSE) {
				std::cout << finalStr << std::flush;
			} else {
				std::cerr << finalStr << std::flush;
			}
		}
		if(_file.is_open()) {
			_file << finalStr << std::flush;
		}
	}
	_ignoreUntilFlush = false;
	_appendPrefix	 = false;
	_stream.str(std::string());
	_stream.clear();
	_level = Level::INFO;
}

void Log::appendIfNeeded() {
	if(_appendPrefix) {
		_appendPrefix = false;
		if(_useColors) {
			_stream << _colorStrings[int(_level)];
		}
		_stream << _levelStrings[int(_level)];
	}
}

Log & Log::operator<<(const Domain & domain) {

	if(_appendPrefix && _useColors) {
		_stream << _colorStrings[int(_level)];
	}
	_stream << "[" << _domainStrings[domain] << "] ";

	if(_appendPrefix) {
		_stream << _levelStrings[int(_level)];
		_appendPrefix = false;
	}
	return *this;
}

Log & Log::operator<<(std::ostream & (*modif)(std::ostream &)) {
	appendIfNeeded();

	modif(_stream);

	flush();
	return *this;
}

Log & Log::operator<<(std::ios_base & (*modif)(std::ios_base &)) {
	modif(_stream);
	return *this;
}
<commit_msg>Logger: fix Windows compilation.<commit_after>#include "system/Logger.hpp"
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <glm/gtx/io.hpp>

#ifdef _WIN32
#	include <io.h>
#	include <cstdio>
#	include <windows.h>
#	ifdef ERROR
#		undef ERROR
#	endif
#else
#	include <unistd.h>
#endif

// We statically initialize the default logger.
// We don't really care about its exact construction/destruction moments,
// but we want it to always be created.
Log * Log::_defaultLogger = new Log();

void Log::set(Level l) {
	_level		  = l;
	_appendPrefix = true;
	if(_level == Level::VERBOSE && !_verbose) {
		// In this case, we want to ignore until the next flush.
		_ignoreUntilFlush = true;
		_appendPrefix	 = false;
	}
}

Log::Log() {

	// Setup glm objects delimiters.
	_stream << glm::io::delimeter<char>('(', ')', ',');

#ifdef _WIN32
	// Enable color output.
	HANDLE h = GetStdHandle( STD_OUTPUT_HANDLE );
	if( h != INVALID_HANDLE_VALUE ) {
		DWORD dwMode = 0;
		if( GetConsoleMode( h, &dwMode ) ) {
			dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
			if( SetConsoleMode( h, dwMode ) ) {
				_useColors = true;
			}
		}
	}

#else
	// Check if the output is indeed a terminal, and not piped.
	const bool isTerminal = isatty(fileno(stdout));
	char * env_p		  = std::getenv("TERM");
	if(isTerminal && env_p) {
		// Check if the output support colors.
		const std::vector<std::string> terms = {"xterm", "xterm-256", "xterm-256color", "vt100", "color", "ansi", "cygwin", "linux"};
		const std::string term(env_p);
		for(const auto & possibleTerm : terms) {
			if(term == possibleTerm) {
				_useColors = true;
				break;
			}
		}
	}
#endif
}

Log::Log(const std::string & filePath, bool logToStdin, bool verbose) :
	_logToStdOut(logToStdin), _verbose(verbose) {

	// Setup glm objects delimiters.
	_stream << glm::io::delimeter<char>('(', ')', ',');
	// Create file if it doesnt exist.
	setFile(filePath, false);
}

void Log::setFile(const std::string & filePath, bool flushExisting) {
	if(flushExisting) {
		_stream << std::endl;
		flush();
	}
	if(_file.is_open()) {
		_file.close();
	}
	_file.open(filePath, std::ofstream::app);
	if(_file.is_open()) {
		_file << "-- New session - " << time(nullptr) << " -------------------------------" << std::endl;
		_useColors = false;
	} else {
		std::cerr << "[Logger] Unable to create log file at path " << filePath << "." << std::endl;
	}
}

void Log::setVerbose(bool verbose) {
	_verbose = verbose;
}

void Log::setDefaultFile(const std::string & filePath) {
	_defaultLogger->setFile(filePath);
}

void Log::setDefaultVerbose(bool verbose) {
	_defaultLogger->setVerbose(verbose);
}

Log & Log::Info() {
	_defaultLogger->set(Level::INFO);
	return *_defaultLogger;
}

Log & Log::Warning() {
	_defaultLogger->set(Level::WARNING);
	return *_defaultLogger;
}

Log & Log::Error() {
	_defaultLogger->set(Level::ERROR);
	return *_defaultLogger;
}

Log & Log::Verbose() {
	_defaultLogger->set(Level::VERBOSE);
	return *_defaultLogger;
}

void Log::flush() {
	if(!_ignoreUntilFlush) {
		const std::string finalStr = _stream.str();

		if(_logToStdOut) {
			if(_level == Level::INFO || _level == Level::VERBOSE) {
				std::cout << finalStr << std::flush;
			} else {
				std::cerr << finalStr << std::flush;
			}
		}
		if(_file.is_open()) {
			_file << finalStr << std::flush;
		}
	}
	_ignoreUntilFlush = false;
	_appendPrefix	 = false;
	_stream.str(std::string());
	_stream.clear();
	_level = Level::INFO;
}

void Log::appendIfNeeded() {
	if(_appendPrefix) {
		_appendPrefix = false;
		if(_useColors) {
			_stream << _colorStrings[int(_level)];
		}
		_stream << _levelStrings[int(_level)];
	}
}

Log & Log::operator<<(const Domain & domain) {

	if(_appendPrefix && _useColors) {
		_stream << _colorStrings[int(_level)];
	}
	_stream << "[" << _domainStrings[domain] << "] ";

	if(_appendPrefix) {
		_stream << _levelStrings[int(_level)];
		_appendPrefix = false;
	}
	return *this;
}

Log & Log::operator<<(std::ostream & (*modif)(std::ostream &)) {
	appendIfNeeded();

	modif(_stream);

	flush();
	return *this;
}

Log & Log::operator<<(std::ios_base & (*modif)(std::ios_base &)) {
	modif(_stream);
	return *this;
}
<|endoftext|>


<commit_before>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 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 VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3112
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3112 to 3113<commit_after>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 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 VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3113
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 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 VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3242
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3242 to 3243<commit_after>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 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 VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3243
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>#pragma once

#include <cassert>
#include <iostream>
#include <string>

#include <Python.h>

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

namespace py {

class Object;
class Unicode;

constexpr PyMethodDef METHODDEF_END{nullptr, nullptr, 0, nullptr};

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

class Exception
{
public:

  Exception() {}

};

inline void check_return(int value)
{
  assert(value == 0 || value == -1);
  if (value != 0)
    throw Exception();
}

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

template<typename T>
inline T* cast(PyObject* obj)
{
  assert(T::Check(obj));  // FIXME: TypeError?
  return static_cast<T*>(obj);
}

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

template<typename T>
class ref
{
public:

  // FIXME: Do we need this?
  static ref<T> take(T* obj)
    { return ref(obj); }

  static ref<T> take(PyObject* obj)
    { return ref(cast<T>(obj)); }

  static ref<T> of(T* obj)
    { incref(obj); return ref{obj}; }

  static ref<T> of(PyObject* obj)
    { return of(cast<T>(obj)); }

  ref()
    : obj_(nullptr) {}
  ref(ref<T>&& ref)
    : obj_(ref.release()) {}
  ~ref()
    { if (obj_ != nullptr) decref(obj_); }

  operator T*() const
    { return obj_; }

  T* operator->() const
    { return obj_; }

  T* release()
    { auto obj = obj_; obj_ = nullptr; return obj; }

private:

  ref(T* obj)
    : obj_(obj) {}

  T* obj_;

};

inline PyObject* incref(PyObject* obj)
{
  Py_INCREF(obj);
  return obj;
}

inline PyObject* decref(PyObject* obj)
{
  Py_DECREF(obj);
  return obj;
}

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

class Object
  : public PyObject
{
public:

  static bool Check(PyObject* obj)
    { return true; }

  Object() = delete;
  ~Object() = delete;

  auto length()
    { return PyObject_Length(this); }
  auto repr()
    { return ref<Unicode>::take(PyObject_Repr(this)); }
  auto str()
    { return ref<Unicode>::take(PyObject_Str(this)); }

};

template<typename T>
inline std::ostream& operator<<(std::ostream& os, ref<T>& ref)
{
  os << ref->str()->as_utf8();
  return os;
}

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

class Unicode
  : public Object
{
public:

  static bool Check(PyObject* obj)
    { return PyUnicode_Check(obj); }

  static auto FromString(char* utf8)
    { return ref<Unicode>::take(PyUnicode_FromString(utf8)); }
  // FIXME: Cast on const here?
  static auto FromStringAndSize(char* utf8, size_t length)
    { return ref<Unicode>::take(PyUnicode_FromStringAndSize(utf8, length)); }

  static auto from(std::string const& str)
    { return FromStringAndSize(const_cast<char*>(str.c_str()), str.length()); }

  char* as_utf8() { return PyUnicode_AsUTF8(this); }

  std::string as_utf8_string()
  {
    Py_ssize_t length;
    char* const utf8 = PyUnicode_AsUTF8AndSize(this, &length);
    if (utf8 == nullptr)
      throw Exception();
    else
      return std::string(utf8, length);
  }

};

template<>
inline std::ostream& operator<<(std::ostream& os, ref<Unicode>& ref)
{
  os << ref->as_utf8();
  return os;
}

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

class Long
  : public Object
{
public:

  static bool Check(PyObject* obj)
    { return PyLong_Check(obj); }
  static auto create(long val)
    { return ref<Long>::take(PyLong_FromLong(val)); }

  operator long()
    { return PyLong_AsLong(this); }

};

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

class Module
  : public Object
{
public:

  static bool Check(PyObject* obj)
    { return PyModule_Check(obj); }
  static auto Create(PyModuleDef* def)
    { return ref<Module>::take(PyModule_Create(def)); }

  void AddObject(char const* name, PyObject* val)
    { check_return(PyModule_AddObject(this, name, incref(val))); }

  void add(PyTypeObject* type)
  {
    // Make sure the qualified name of the type includes this module's name.
    std::string const qualname = type->tp_name;
    std::string const mod_name = PyModule_GetName(this);
    auto dot = qualname.find_last_of('.');
    assert(dot != std::string::npos);
    assert(qualname.compare(0, dot, mod_name) == 1);
    // Add it, under its unqualified name.
    AddObject(qualname.substr(dot + 1).c_str(), (PyObject*) type);
  }

};

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

class ExtensionType
  : public Object
{
public:

  PyObject_HEAD

};

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

class Type
  : public PyTypeObject
{
public:

  Type(PyTypeObject o) : PyTypeObject(o) {}

  void Ready()
    { check_return(PyType_Ready(this)); }

};

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

}  // namespace py

<commit_msg>Method wrapper.<commit_after>#pragma once

#include <cassert>
#include <iostream>
#include <string>

#include <Python.h>

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

namespace py {

class Object;
class Unicode;

constexpr PyMethodDef METHODDEF_END{nullptr, nullptr, 0, nullptr};

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

class Exception
{
public:

  Exception() {}

};

inline void check_return(int value)
{
  assert(value == 0 || value == -1);
  if (value != 0)
    throw Exception();
}

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

template<typename T>
inline T* cast(PyObject* obj)
{
  assert(T::Check(obj));  // FIXME: TypeError?
  return static_cast<T*>(obj);
}

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

template<typename T>
class ref
{
public:

  // FIXME: Do we need this?
  static ref<T> take(T* obj)
    { return ref(obj); }

  static ref<T> take(PyObject* obj)
    { return ref(cast<T>(obj)); }

  static ref<T> of(T* obj)
    { incref(obj); return ref{obj}; }

  static ref<T> of(PyObject* obj)
    { return of(cast<T>(obj)); }

  ref()
    : obj_(nullptr) {}
  ref(ref<T>&& ref)
    : obj_(ref.release()) {}
  ~ref()
    { if (obj_ != nullptr) decref(obj_); }

  operator T*() const
    { return obj_; }

  T* operator->() const
    { return obj_; }

  T* release()
    { auto obj = obj_; obj_ = nullptr; return obj; }

private:

  ref(T* obj)
    : obj_(obj) {}

  T* obj_;

};

inline PyObject* incref(PyObject* obj)
{
  Py_INCREF(obj);
  return obj;
}

inline PyObject* decref(PyObject* obj)
{
  Py_DECREF(obj);
  return obj;
}

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

class Object
  : public PyObject
{
public:

  static bool Check(PyObject* obj)
    { return true; }

  Object() = delete;
  ~Object() = delete;

  auto length()
    { return PyObject_Length(this); }
  auto repr()
    { return ref<Unicode>::take(PyObject_Repr(this)); }
  auto str()
    { return ref<Unicode>::take(PyObject_Str(this)); }

};

template<typename T>
inline std::ostream& operator<<(std::ostream& os, ref<T>& ref)
{
  os << ref->str()->as_utf8();
  return os;
}

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

class Unicode
  : public Object
{
public:

  static bool Check(PyObject* obj)
    { return PyUnicode_Check(obj); }

  static auto FromString(char* utf8)
    { return ref<Unicode>::take(PyUnicode_FromString(utf8)); }
  // FIXME: Cast on const here?
  static auto FromStringAndSize(char* utf8, size_t length)
    { return ref<Unicode>::take(PyUnicode_FromStringAndSize(utf8, length)); }

  static auto from(std::string const& str)
    { return FromStringAndSize(const_cast<char*>(str.c_str()), str.length()); }

  char* as_utf8() { return PyUnicode_AsUTF8(this); }

  std::string as_utf8_string()
  {
    Py_ssize_t length;
    char* const utf8 = PyUnicode_AsUTF8AndSize(this, &length);
    if (utf8 == nullptr)
      throw Exception();
    else
      return std::string(utf8, length);
  }

};

template<>
inline std::ostream& operator<<(std::ostream& os, ref<Unicode>& ref)
{
  os << ref->as_utf8();
  return os;
}

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

class Long
  : public Object
{
public:

  static bool Check(PyObject* obj)
    { return PyLong_Check(obj); }
  static auto create(long val)
    { return ref<Long>::take(PyLong_FromLong(val)); }

  operator long()
    { return PyLong_AsLong(this); }

};

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

class Module
  : public Object
{
public:

  static bool Check(PyObject* obj)
    { return PyModule_Check(obj); }
  static auto Create(PyModuleDef* def)
    { return ref<Module>::take(PyModule_Create(def)); }

  void AddObject(char const* name, PyObject* val)
    { check_return(PyModule_AddObject(this, name, incref(val))); }

  void add(PyTypeObject* type)
  {
    // Make sure the qualified name of the type includes this module's name.
    std::string const qualname = type->tp_name;
    std::string const mod_name = PyModule_GetName(this);
    auto dot = qualname.find_last_of('.');
    assert(dot != std::string::npos);
    assert(qualname.compare(0, dot, mod_name) == 1);
    // Add it, under its unqualified name.
    AddObject(qualname.substr(dot + 1).c_str(), (PyObject*) type);
  }

};

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

class ExtensionType
  : public Object
{
public:

  PyObject_HEAD

};

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

class Type
  : public PyTypeObject
{
public:

  Type(PyTypeObject o) : PyTypeObject(o) {}

  void Ready()
    { check_return(PyType_Ready(this)); }

};

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

template<typename T>
using Method = ref<Object> (*)(T*, Object*, Object*);

template<typename T, Method<T> M>
PyObject* wrap_method(PyObject* self, PyObject* args, PyObject* kw_args)
{
  try {
    return M((T*) self, (Object*) args, (Object*) kw_args).release();
  }
  catch (Exception) {
    return nullptr;
  }
}

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

}  // namespace py

<|endoftext|>


<commit_before>/*  This file is part of the KDE libraries
 *    Copyright (C) 2016 Kåre Särs <kare.sars@iki.fi>
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Library General Public
 *    License as published by the Free Software Foundation; either
 *    version 2 of the License, or (at your option) any later version.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Library General Public License for more details.
 *
 *    You should have received a copy of the GNU Library General Public License
 *    along with this library; see the file COPYING.LIB.  If not, write to
 *    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *    Boston, MA 02110-1301, USA.
 */
#include <QCoreApplication>
#include <QFile>
#include <QFileInfo>
#include <QString>
#include <QRegularExpression>
#include <QDebug>
#include <QCommandLineParser>

QString link(const QString &path, const QString &fileName)
{
    QFile in(path + QLatin1Char('/') + fileName);
    if (!in.open(QIODevice::ReadOnly)) {
        qDebug() << "failed to read" << path << fileName << in.fileName();
        return QString();
    }

    QString firstLine = QString::fromLocal8Bit(in.readLine());
    if (firstLine.isEmpty()) {
        qDebug() << in.fileName() << "line could not be read...";
        return QString();
    }
    QRegularExpression fNameReg(QStringLiteral("(.*\\.(?:svg|png|gif|ico))"));
    QRegularExpressionMatch match = fNameReg.match(firstLine);
    if (!match.hasMatch()) {
        return QString();
    }

    QFileInfo linkInfo(path + QLatin1Char('/') + match.captured(1));
    QString aliasLink = link(linkInfo.path(), linkInfo.fileName());
    if (!aliasLink.isEmpty()) {
        //qDebug() <<  fileName << "=" << match.captured(1) << "=" << aliasLink;
        return aliasLink;
    }

    return  path + QLatin1Char('/') + match.captured(1);
}

int parseFile(const QString &infile, const QString &outfile)
{
    QFile in(infile);
    QFile out(outfile);
    QRegularExpression imageReg(QStringLiteral("<file>(.*\\.(?:svg|png|gif|ico))</file>"));

    if (!in.open(QIODevice::ReadOnly)) {
        qDebug() << "Failed to open" << infile;
        return -1;
    }
    if (!out.open(QIODevice::WriteOnly)) {
        qDebug() << "Failed to create" << outfile;
        return -2;
    }

    while (in.bytesAvailable()) {
        QString line = QString::fromLocal8Bit(in.readLine());
        QRegularExpressionMatch match = imageReg.match(line);
        if (!match.hasMatch()) {
            //qDebug() << "No Match: " << line;
            out.write(qPrintable(line));
            continue;
        }

        QFileInfo info(match.captured(1));

        QString aliasLink = link(info.path(), info.fileName());
        if (aliasLink.isEmpty()) {
            //qDebug() << "No alias: " << line;
            out.write(qPrintable(line));
            continue;
        }

        QString newLine = QStringLiteral("<file alias=\"%1\">%2</file>\n").arg(match.captured(1), aliasLink);
        //qDebug() << newLine;
        out.write(qPrintable(newLine));
    }
    return 0;
}

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    QCommandLineParser parser;

    QCommandLineOption inOption(QStringList() << QLatin1String("i") << QLatin1String("infile"), QStringLiteral("Input qrc file"), QStringLiteral("infile"));
    QCommandLineOption outOption(QStringList() << QLatin1String("o") << QLatin1String("outfile"), QStringLiteral("Output qrc file"), QStringLiteral("outfile"));
    parser.setApplicationDescription(
        QLatin1String("On Windows git handles symbolic links by converting them "
        "to text files containing the links to the actual file. This application "
        "takes a .qrc file as input and outputs a .qrc file with the symbolic "
        "links converted to qrc-aliases."));
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addOption(inOption);
    parser.addOption(outOption);
    parser.process(app);

    const QString inName = parser.value(inOption);
    const QString outName = parser.value(outOption);

    return parseFile(inName, outName);
}
<commit_msg>Fix fNameReg regex<commit_after>/*  This file is part of the KDE libraries
 *    Copyright (C) 2016 Kåre Särs <kare.sars@iki.fi>
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Library General Public
 *    License as published by the Free Software Foundation; either
 *    version 2 of the License, or (at your option) any later version.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Library General Public License for more details.
 *
 *    You should have received a copy of the GNU Library General Public License
 *    along with this library; see the file COPYING.LIB.  If not, write to
 *    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *    Boston, MA 02110-1301, USA.
 */
#include <QCoreApplication>
#include <QFile>
#include <QFileInfo>
#include <QString>
#include <QRegularExpression>
#include <QDebug>
#include <QCommandLineParser>

QString link(const QString &path, const QString &fileName)
{
    QFile in(path + QLatin1Char('/') + fileName);
    if (!in.open(QIODevice::ReadOnly)) {
        qDebug() << "failed to read" << path << fileName << in.fileName();
        return QString();
    }

    QString firstLine = QString::fromLocal8Bit(in.readLine());
    if (firstLine.isEmpty()) {
        qDebug() << in.fileName() << "line could not be read...";
        return QString();
    }
    QRegularExpression fNameReg(QStringLiteral("(.*\\.(?:svg|png|gif|ico))$"));
    QRegularExpressionMatch match = fNameReg.match(firstLine);
    if (!match.hasMatch()) {
        return QString();
    }

    QFileInfo linkInfo(path + QLatin1Char('/') + match.captured(1));
    QString aliasLink = link(linkInfo.path(), linkInfo.fileName());
    if (!aliasLink.isEmpty()) {
        //qDebug() <<  fileName << "=" << match.captured(1) << "=" << aliasLink;
        return aliasLink;
    }

    return  path + QLatin1Char('/') + match.captured(1);
}

int parseFile(const QString &infile, const QString &outfile)
{
    QFile in(infile);
    QFile out(outfile);
    QRegularExpression imageReg(QStringLiteral("<file>(.*\\.(?:svg|png|gif|ico))</file>"));

    if (!in.open(QIODevice::ReadOnly)) {
        qDebug() << "Failed to open" << infile;
        return -1;
    }
    if (!out.open(QIODevice::WriteOnly)) {
        qDebug() << "Failed to create" << outfile;
        return -2;
    }

    while (in.bytesAvailable()) {
        QString line = QString::fromLocal8Bit(in.readLine());
        QRegularExpressionMatch match = imageReg.match(line);
        if (!match.hasMatch()) {
            //qDebug() << "No Match: " << line;
            out.write(qPrintable(line));
            continue;
        }

        QFileInfo info(match.captured(1));

        QString aliasLink = link(info.path(), info.fileName());
        if (aliasLink.isEmpty()) {
            //qDebug() << "No alias: " << line;
            out.write(qPrintable(line));
            continue;
        }

        QString newLine = QStringLiteral("<file alias=\"%1\">%2</file>\n").arg(match.captured(1), aliasLink);
        //qDebug() << newLine;
        out.write(qPrintable(newLine));
    }
    return 0;
}

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    QCommandLineParser parser;

    QCommandLineOption inOption(QStringList() << QLatin1String("i") << QLatin1String("infile"), QStringLiteral("Input qrc file"), QStringLiteral("infile"));
    QCommandLineOption outOption(QStringList() << QLatin1String("o") << QLatin1String("outfile"), QStringLiteral("Output qrc file"), QStringLiteral("outfile"));
    parser.setApplicationDescription(
        QLatin1String("On Windows git handles symbolic links by converting them "
        "to text files containing the links to the actual file. This application "
        "takes a .qrc file as input and outputs a .qrc file with the symbolic "
        "links converted to qrc-aliases."));
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addOption(inOption);
    parser.addOption(outOption);
    parser.process(app);

    const QString inName = parser.value(inOption);
    const QString outName = parser.value(outOption);

    return parseFile(inName, outName);
}
<|endoftext|>


<commit_before>#include "lesh.hpp"

namespace Primitive {
Value apply_plus(const Vlist& arguments);
Value apply_minus(const Vlist& arguments);
Value apply_multiply(const Vlist& arguments);
Value apply_equal(const Vlist& arguments);
Value apply_null(const Vlist& arguments);
Value apply_list(const Vlist& arguments);
Value apply_car(const Vlist& arguments);
Value apply_cdr(const Vlist& arguments);

const Symbol END_OF_FUNC_LIST = "__END_OF_FUNC_LIST__";

typedef Value (*PrimitiveFuncp)(const Vlist&);

/**
 * symbol and function table
 */
const pair<Symbol, PrimitiveFuncp> func_table[] = {
	make_pair(SYMBOL_PLUS, &apply_plus),
	make_pair(SYMBOL_MINUS, &apply_minus),
	make_pair(SYMBOL_MULTIPLY, &apply_multiply),
	make_pair(SYMBOL_EQUAL, &apply_equal),
	make_pair(SYMBOL_NULL, &apply_null),
	make_pair(SYMBOL_LIST, &apply_list),
	make_pair(SYMBOL_CAR, &apply_car),
	make_pair(SYMBOL_CDR, &apply_cdr),
	make_pair(END_OF_FUNC_LIST, &apply_plus),
};

void define_variables(Env &env) {
	env.define_variable( SYMBOL_TRUE, Value(SYMBOL_TRUE));
	env.define_variable( SYMBOL_FALSE, Value(SYMBOL_FALSE));
	for ( auto i=0; func_table[i].first!=END_OF_FUNC_LIST; i++ ) {
		env.define_variable( func_table[i].first, Value(func_table[i].first, PRIMITIVE));
	}
}

Value apply_procedure(const Symbol& sym, const Vlist& arguments) {
	for ( auto i=0; func_table[i].first!=END_OF_FUNC_LIST; i++ ) {
		if ( func_table[i].first == sym ) {
			return func_table[i].second(arguments);
		}
	}
	return Value(SYMBOL_ERROR);
}

Value apply_plus(const Vlist& arguments) {
		auto ret=0;
		for( auto itr=arguments.begin(); itr!=arguments.end(); itr++ ){
			ret += itr->num;
		}
		return Value(ret);
}

Value apply_minus(const Vlist& arguments) {
		auto itr=arguments.begin();
		auto ret = itr->num;
		for( itr++; itr!=arguments.end(); itr++ ){
			ret -= itr->num;
		}
		return Value(ret);
}

Value apply_multiply(const Vlist& arguments) {
		auto ret=1;
		for( auto itr=arguments.begin(); itr!=arguments.end(); itr++ ){
			ret *= itr->num;
		}
		return Value(ret);
}

Value apply_equal(const Vlist& arguments) {
		auto itr=arguments.cbegin();
		auto j = itr;
		++itr;
		//assert( j->type == NUM );
		if ( itr->num == j->num )
			return  Value(SYMBOL_TRUE);
		else
			return  Value(SYMBOL_FALSE);
}

Value apply_null(const Vlist& arguments) {
		auto first=arguments.cbegin();
		if ( first->type == LIST && first->vlist.size()==0 )
			return  Value(SYMBOL_TRUE);
		else
			return  Value(SYMBOL_FALSE);
}

Value apply_list(const Vlist& arguments) {
		return Vlist(arguments.begin(),arguments.end());
}

Value apply_car(const Vlist& arguments) {
		if ( arguments.size() != 1 ) cerr << "err-argument" << endl;
		auto first=arguments.cbegin();
		return *(first->vlist.begin());
}

Value apply_cdr(const Vlist& arguments) {
		if ( arguments.size() != 1 ) cerr << "err-argument" << endl;
		auto first=arguments.begin();
		return Vlist(first->vlist.begin()+1,first->vlist.end());
}

}

<commit_msg>macosx clang not support cbegin<commit_after>#include "lesh.hpp"

namespace Primitive {
Value apply_plus(const Vlist& arguments);
Value apply_minus(const Vlist& arguments);
Value apply_multiply(const Vlist& arguments);
Value apply_equal(const Vlist& arguments);
Value apply_null(const Vlist& arguments);
Value apply_list(const Vlist& arguments);
Value apply_car(const Vlist& arguments);
Value apply_cdr(const Vlist& arguments);

const Symbol END_OF_FUNC_LIST = "__END_OF_FUNC_LIST__";

typedef Value (*PrimitiveFuncp)(const Vlist&);

/**
 * symbol and function table
 */
const pair<Symbol, PrimitiveFuncp> func_table[] = {
	make_pair(SYMBOL_PLUS, &apply_plus),
	make_pair(SYMBOL_MINUS, &apply_minus),
	make_pair(SYMBOL_MULTIPLY, &apply_multiply),
	make_pair(SYMBOL_EQUAL, &apply_equal),
	make_pair(SYMBOL_NULL, &apply_null),
	make_pair(SYMBOL_LIST, &apply_list),
	make_pair(SYMBOL_CAR, &apply_car),
	make_pair(SYMBOL_CDR, &apply_cdr),
	make_pair(END_OF_FUNC_LIST, &apply_plus),
};

void define_variables(Env &env) {
	env.define_variable( SYMBOL_TRUE, Value(SYMBOL_TRUE));
	env.define_variable( SYMBOL_FALSE, Value(SYMBOL_FALSE));
	for ( auto i=0; func_table[i].first!=END_OF_FUNC_LIST; i++ ) {
		env.define_variable( func_table[i].first, Value(func_table[i].first, PRIMITIVE));
	}
}

Value apply_procedure(const Symbol& sym, const Vlist& arguments) {
	for ( auto i=0; func_table[i].first!=END_OF_FUNC_LIST; i++ ) {
		if ( func_table[i].first == sym ) {
			return func_table[i].second(arguments);
		}
	}
	return Value(SYMBOL_ERROR);
}

Value apply_plus(const Vlist& arguments) {
		auto ret=0;
		for( auto itr=arguments.begin(); itr!=arguments.end(); itr++ ){
			ret += itr->num;
		}
		return Value(ret);
}

Value apply_minus(const Vlist& arguments) {
		auto itr=arguments.begin();
		auto ret = itr->num;
		for( itr++; itr!=arguments.end(); itr++ ){
			ret -= itr->num;
		}
		return Value(ret);
}

Value apply_multiply(const Vlist& arguments) {
		auto ret=1;
		for( auto itr=arguments.begin(); itr!=arguments.end(); itr++ ){
			ret *= itr->num;
		}
		return Value(ret);
}

Value apply_equal(const Vlist& arguments) {
		auto itr=arguments.begin();
		auto j = itr;
		++itr;
		//assert( j->type == NUM );
		if ( itr->num == j->num )
			return  Value(SYMBOL_TRUE);
		else
			return  Value(SYMBOL_FALSE);
}

Value apply_null(const Vlist& arguments) {
		auto first=arguments.begin();
		if ( first->type == LIST && first->vlist.size()==0 )
			return  Value(SYMBOL_TRUE);
		else
			return  Value(SYMBOL_FALSE);
}

Value apply_list(const Vlist& arguments) {
		return Vlist(arguments.begin(),arguments.end());
}

Value apply_car(const Vlist& arguments) {
		if ( arguments.size() != 1 ) cerr << "err-argument" << endl;
		auto first=arguments.begin();
		return *(first->vlist.begin());
}

Value apply_cdr(const Vlist& arguments) {
		if ( arguments.size() != 1 ) cerr << "err-argument" << endl;
		auto first=arguments.begin();
		return Vlist(first->vlist.begin()+1,first->vlist.end());
}

}

<|endoftext|>