<commit_before>#include "stdafx.h"
#include <dukat/application.h>
#include <dukat/audiomanager.h>
#include <dukat/log.h>
#include <dukat/perfcounter.h>
#include <dukat/sysutil.h>
#include <dukat/window.h>
#include <dukat/devicemanager.h>
#include <dukat/keyboarddevice.h>
#include <dukat/settings.h>
#include <ctime>

namespace dukat
{
	Application::Application(Settings& settings)
		: title(settings.get_string("window.title")), runtime(0.0f), paused(false), done(false), last_update(0), settings(settings)
	{
		init_logging(settings);
		log->info("Initializing application.");

		SDL_version compiled;
		SDL_version linked;
		SDL_VERSION(&compiled);
		SDL_GetVersion(&linked);
		log->debug("SDL version {}.{}.{} ({}.{}.{})",
			static_cast<int>(compiled.major), static_cast<int>(compiled.minor), static_cast<int>(compiled.patch),
			static_cast<int>(linked.major), static_cast<int>(linked.minor), static_cast<int>(linked.patch));

		sdl_check_result(SDL_Init(SDL_INIT_EVERYTHING), "Initialize SDL");
		window = std::make_unique<Window>(settings.get_int("window.width", 640), settings.get_int("window.height", 480),
			settings.get_bool("window.fullscreen"), settings.get_bool("window.vsync", true), settings.get_bool("window.msaa"));
		window->set_title(title);

		auto show_cursor = settings.get_bool("input.mouse.cursor", false);
		if (!show_cursor)
		{
			SDL_ShowCursor(SDL_DISABLE);
		}

#ifndef __ANDROID__
		audio_manager = std::make_unique<AudioManager>(settings.get_int("audio.channels", 16));
		audio_manager->set_music_volume(settings.get_float("audio.music.volume", 1.0f));
		audio_manager->set_sample_volume(settings.get_float("audio.sample.volume", 1.0f));
#endif

		device_manager = std::make_unique<DeviceManager>(settings);
		device_manager->add_keyboard(window.get());
		gl_check_error();
	}

	Application::~Application(void)
	{
		// Force release of device manager before call to SDL_Quit
		device_manager = nullptr;
		// Always show cursor before exiting
		SDL_ShowCursor(SDL_ENABLE);
		SDL_Quit();
	}

	int Application::run(void)
	{
		log->debug("Entering application loop.");
		uint32_t ticks, last_frame = 0;
		SDL_Event e;
		while (!done)
		{
			ticks = SDL_GetTicks();

			device_manager->update();
			if (!paused)
			{
				auto delta = static_cast<float>(ticks - last_update) / 1000.0f;
				runtime += delta;
				update(delta);
			}
			last_update = ticks;

			// update FPS counter
			if (ticks - last_frame >= 1000)
			{
				last_fps = perfc.sum(PerformanceCounter::FRAMES);
				last_frame = ticks;
				perfc.collect_stats();
			}

			// process events
			while (SDL_PollEvent(&e))
			{
				handle_event(e);
			}

			// render to screen
			render();
			perfc.inc(PerformanceCounter::FRAMES);
			perfc.reset();
		}

		return 0;
	}

	void Application::handle_event(const SDL_Event& e)
	{
		switch (e.type)
		{
		case SDL_QUIT:
			done = true;
			break;
		case SDL_KEYDOWN:
			handle_keyboard(e);
			break;
		case SDL_WINDOWEVENT:
			handle_window_event(e);
			break;
		case SDL_JOYDEVICEADDED:
			device_manager->add_joystick(window.get(), e.jdevice.which);
			break;
		case SDL_JOYDEVICEREMOVED:
			device_manager->remove_joystick(e.jdevice.which);
			break;
		}
	}

	void Application::handle_keyboard(const SDL_Event& e)
	{
		switch (e.key.keysym.sym)
		{
		case SDLK_RETURN:
			if (e.key.keysym.mod & KMOD_ALT)
			{
				window->toggle_fullscreen();
			}
			break;
		case SDLK_PAUSE:
			toggle_pause();
			break;
		case SDLK_PRINTSCREEN:
			{
				std::stringstream ss;
				ss << "screenshot_" << std::time(nullptr) << ".png";
				save_screenshot(ss.str());
			}
			break;
		}
	}

	void Application::handle_window_event(const SDL_Event& e)
	{
		switch (e.window.event)
		{
		case SDL_WINDOWEVENT_FOCUS_GAINED:
			if (settings.get_bool("input.mouse.lock", true))
			{
				sdl_check_result(SDL_SetRelativeMouseMode(SDL_TRUE), "Set mouse mode");
			}
	        break;
        case SDL_WINDOWEVENT_FOCUS_LOST:
    		if (settings.get_bool("input.mouse.lock", true))
			{
				sdl_check_result(SDL_SetRelativeMouseMode(SDL_FALSE), "Set mouse mode");
			}
	        break;
		case SDL_WINDOWEVENT_RESIZED:
			window->on_resize();
			break;
		case SDL_WINDOWEVENT_SIZE_CHANGED:
			break;
		}
	}
}<commit_msg>Change when we handle device events to properly handle last_update reset<commit_after>#include "stdafx.h"
#include <dukat/application.h>
#include <dukat/audiomanager.h>
#include <dukat/log.h>
#include <dukat/perfcounter.h>
#include <dukat/sysutil.h>
#include <dukat/window.h>
#include <dukat/devicemanager.h>
#include <dukat/keyboarddevice.h>
#include <dukat/settings.h>
#include <ctime>

namespace dukat
{
	Application::Application(Settings& settings)
		: title(settings.get_string("window.title")), runtime(0.0f), paused(false), done(false), last_update(0), settings(settings)
	{
		init_logging(settings);
		log->info("Initializing application.");

		SDL_version compiled;
		SDL_version linked;
		SDL_VERSION(&compiled);
		SDL_GetVersion(&linked);
		log->debug("SDL version {}.{}.{} ({}.{}.{})",
			static_cast<int>(compiled.major), static_cast<int>(compiled.minor), static_cast<int>(compiled.patch),
			static_cast<int>(linked.major), static_cast<int>(linked.minor), static_cast<int>(linked.patch));

		sdl_check_result(SDL_Init(SDL_INIT_EVERYTHING), "Initialize SDL");
		window = std::make_unique<Window>(settings.get_int("window.width", 640), settings.get_int("window.height", 480),
			settings.get_bool("window.fullscreen"), settings.get_bool("window.vsync", true), settings.get_bool("window.msaa"));
		window->set_title(title);

		auto show_cursor = settings.get_bool("input.mouse.cursor", false);
		if (!show_cursor)
		{
			SDL_ShowCursor(SDL_DISABLE);
		}

#ifndef __ANDROID__
		audio_manager = std::make_unique<AudioManager>(settings.get_int("audio.channels", 16));
		audio_manager->set_music_volume(settings.get_float("audio.music.volume", 1.0f));
		audio_manager->set_sample_volume(settings.get_float("audio.sample.volume", 1.0f));
#endif

		device_manager = std::make_unique<DeviceManager>(settings);
		device_manager->add_keyboard(window.get());
		gl_check_error();
	}

	Application::~Application(void)
	{
		// Force release of device manager before call to SDL_Quit
		device_manager = nullptr;
		// Always show cursor before exiting
		SDL_ShowCursor(SDL_ENABLE);
		SDL_Quit();
	}

	int Application::run(void)
	{
		log->debug("Entering application loop.");
		uint32_t ticks, last_frame = 0;
		SDL_Event e;
		while (!done)
		{
			ticks = SDL_GetTicks();

			if (!paused)
			{
				auto delta = static_cast<float>(ticks - last_update) / 1000.0f;
				runtime += delta;
				update(delta);
			}
			last_update = ticks;

			// update FPS counter
			if (ticks - last_frame >= 1000)
			{
				last_fps = perfc.sum(PerformanceCounter::FRAMES);
				last_frame = ticks;
				perfc.collect_stats();
			}

			// process events
			while (SDL_PollEvent(&e))
			{
				handle_event(e);
			}

			device_manager->update();

			// render to screen
			render();
			perfc.inc(PerformanceCounter::FRAMES);
			perfc.reset();
		}

		return 0;
	}

	void Application::handle_event(const SDL_Event& e)
	{
		switch (e.type)
		{
		case SDL_QUIT:
			done = true;
			break;
		case SDL_KEYDOWN:
			handle_keyboard(e);
			break;
		case SDL_WINDOWEVENT:
			handle_window_event(e);
			break;
		case SDL_JOYDEVICEADDED:
			device_manager->add_joystick(window.get(), e.jdevice.which);
			break;
		case SDL_JOYDEVICEREMOVED:
			device_manager->remove_joystick(e.jdevice.which);
			break;
		}
	}

	void Application::handle_keyboard(const SDL_Event& e)
	{
		switch (e.key.keysym.sym)
		{
		case SDLK_RETURN:
			if (e.key.keysym.mod & KMOD_ALT)
			{
				window->toggle_fullscreen();
			}
			break;
		case SDLK_PAUSE:
			toggle_pause();
			break;
		case SDLK_PRINTSCREEN:
			{
				std::stringstream ss;
				ss << "screenshot_" << std::time(nullptr) << ".png";
				save_screenshot(ss.str());
			}
			break;
		}
	}

	void Application::handle_window_event(const SDL_Event& e)
	{
		switch (e.window.event)
		{
		case SDL_WINDOWEVENT_FOCUS_GAINED:
			if (settings.get_bool("input.mouse.lock", true))
			{
				sdl_check_result(SDL_SetRelativeMouseMode(SDL_TRUE), "Set mouse mode");
			}
	        break;
        case SDL_WINDOWEVENT_FOCUS_LOST:
    		if (settings.get_bool("input.mouse.lock", true))
			{
				sdl_check_result(SDL_SetRelativeMouseMode(SDL_FALSE), "Set mouse mode");
			}
	        break;
		case SDL_WINDOWEVENT_RESIZED:
			window->on_resize();
			break;
		case SDL_WINDOWEVENT_SIZE_CHANGED:
			break;
		}
	}
}<|endoftext|>


<commit_before>/*!
 * \file Common.hpp
 * \brief Documentation and include file for Common namespace.
 * \author mstefanc
 * \date 26.04.2010
 */

/*!
 * \namespace Common
 * \brief This namespace contains classes useful in different tasks,
 * like region segmentators, space color transformers, LUT color classifiers, etc.
 * \author tkornuta
 */

#include "FraDIAException.hpp"
#include "Panel_Empty.hpp"
<commit_msg>unused (FraDIA?) Common.hpp file removed<commit_after><|endoftext|>


<commit_before>#pragma once

#include <string>
#include <set>
#include <cstdint>

#include "zcm/zcm-cpp.hpp"
#include "zcm/json/json.h"

//
// Remember you must inherit from this class and implement your functions
// inside your cpp file. That way you can then compile a shared library of your
// plugins.
//
// REPEAT: ALL FUNCTIONS MUST BE *DEFINED* OUTSIDE OF CLASS *DECLARATION*
//
// Do this:
//
// class CustomPlugin : IndexerPlugin
// {
//     static IndexerPlugin* makeIndexerPlugin();
// };
// IndexerPlugin* CustomPlugin::makeIndexerPlugin() { return new CustomPlugin(); }
//
//
// Not This:
//
// class CustomPlugin : IndexerPlugin
// {
//     static IndexerPlugin* makeIndexerPlugin() { return new CustomPlugin(); }
// };
//
//
// Note that an hpp file is not even required. You only need a cpp file containing
// your custom plugin. Then compile it into a shared library by doing the following:
//
// g++ -std=c++11 -fPIC -shared CustomPlugin.cpp -o plugins.so
//

namespace zcm {

class IndexerPlugin
{
  public:
    // Must declare the following function for your plugin. Unable to enforce
    // declaration of static functions in inheritance, so this API trusts you
    // to define this function for your type
    static IndexerPlugin* makeIndexerPlugin();

    virtual ~IndexerPlugin();

    // This defines the key of the object you will be passed in the functions
    // below as pluginIndex. Further explanation below.
    virtual std::string name() const;

    // Returns a set of names of other plugins that this plugin depends on.
    // Ie if a custom plugin depends on the timestamp plugin's output, it would
    // return {"timestamp"} and no indexing functions would be called on this
    // plugin until the "timestamp" plugin finished its indexing
    // Specifying "timestamp" as a dependency allows this plugin to use the
    // timestamp-indexed data while performing its own indexing operations
    // In other words, returning {"timestamp"} ensures that the index passed
    // into the following functions will contain the entire (not partial)
    // "timestamp" index. The full index passed into the following functions
    // is just for your reference, your indexEvent function will still be called
    // on every single event in the log in the order in which they are stored in
    // the log.
    virtual std::set<std::string> dependsOn() const;

    // Do anything that your plugin requires doing before the indexing process
    // starts but after all dependencies have run
    //
    // the index argument refers to the entirety of the index created thus far.
    // If you had specifided "timestamp" as a dependency of this plugin, index
    // might look like this:
    //
    // {
    //     "timestamp" : {
    //         "IMAGES" : {
    //             "image_t" : [
    //                 "0",
    //                 "1001000",
    //                 "2002000",
    //                 ...
    //                 "37037000"
    //             ]
    //         },
    //         "BEACON_COORDS" : {
    //             "beacon_t" : [
    //                 "1000000",
    //                 "1000100",
    //                 "1000200",
    //                 "1000300",
    //                 ...
    //                 "37036900"
    //             ]
    //         }
    //     },
    //     "custom plugin" : {
    //     }
    // }
    //
    // pluginIndex would be the object in json that you will modify to create
    // your index. In the case above, pluginIndex would be empty when passed
    // into this function:
    //
    //     "custom plugin" : {
    //     }
    //
    // return true from this if you would like the below indexEvent function to
    // be called on every event in the log. returning false from here would
    // skip the log traversal step that calls indexEvent on each event and would
    // skip straight to tear down
    //
    virtual bool setUp(const zcm::Json::Value& index,
                       zcm::Json::Value& pluginIndex,
                       zcm::LogFile& log);

    // pluginIndex is the index you should modify. It is your json object that
    // will be passed back to this function every time the function is called.
    //
    // index is the entire json object containing the output of every plugin run
    // so far
    //
    // channel is the channel name of the event
    //
    // typeName is the name of the zcmtype encoded inside the event
    //
    // offset is the index into the eventlog where this event is stored
    // each susbequent indexEvent call will be called with a larger offset
    // than the last. In other words, "offset" is monotonically increasing
    // across indexEvent calls
    //
    // timestamp is the timestamp of the event. Not to be confused with any
    // fields contained in the zcmtype message itself. This is the timestamp
    // of the event as reported by the transport that originally received it.
    //
    // hash is the hash of the type encoded inside the event
    //
    // data and datalen is the payload of the event
    // To recover the zcmtype message from these arguments, simply call:
    //
    //  if (hash == msg_t::getHash()) {
    //      msg_t msg;
    //      msg.decode(data, 0, datalen);
    //  }
    //
    // The default plugin indexes in the following way. You might want to
    // follow suit but that decision is left completely up to you.
    //
    // pluginIndex[channel][typeName].append(offset);
    //
    //
    virtual void indexEvent(const zcm::Json::Value& index,
                            zcm::Json::Value& pluginIndex,
                            std::string channel,
                            std::string typeName,
                            off_t offset,
                            uint64_t timestamp,
                            int64_t hash,
                            const char* data,
                            int32_t datalen);

    // Do anything that your plugin requires doing before the indexer exits
    // If your data needs to be sorted, do so here
    virtual void tearDown(const zcm::Json::Value& index,
                          zcm::Json::Value& pluginIndex,
                          zcm::LogFile& log);
};

}
<commit_msg>Updated docs<commit_after>#pragma once

#include <string>
#include <set>
#include <cstdint>

#include "zcm/zcm-cpp.hpp"
#include "zcm/json/json.h"

//
// Remember you must inherit from this class and implement your functions
// inside your cpp file. That way you can then compile a shared library of your
// plugins.
//
// REPEAT: ALL FUNCTIONS MUST BE *DEFINED* OUTSIDE OF CLASS *DECLARATION*
//
// Do this:
//
// class CustomPlugin : IndexerPlugin
// {
//     static IndexerPlugin* makeIndexerPlugin();
// };
// IndexerPlugin* CustomPlugin::makeIndexerPlugin() { return new CustomPlugin(); }
//
//
// Not This:
//
// class CustomPlugin : IndexerPlugin
// {
//     static IndexerPlugin* makeIndexerPlugin() { return new CustomPlugin(); }
// };
//
//
// Note that an hpp file is not even required. You only need a cpp file containing
// your custom plugin. Then compile it into a shared library by doing the following:
//
// g++ -std=c++11 -fPIC -shared CustomPlugin.cpp -o plugins.so
//

namespace zcm {

class IndexerPlugin
{
  public:
    // Must declare the following function for your plugin. Unable to enforce
    // declaration of static functions in inheritance, so this API trusts you
    // to define this function for your type
    static IndexerPlugin* makeIndexerPlugin();

    virtual ~IndexerPlugin();

    // This defines the key of the object you will be passed in the functions
    // below as pluginIndex. Further explanation below.
    virtual std::string name() const;

    // Returns a set of names of other plugins that this plugin depends on.
    // Ie if a custom plugin depends on the timestamp plugin's output, it would
    // return {"timestamp"} and no indexing functions would be called on this
    // plugin until the "timestamp" plugin finished its indexing
    // Specifying "timestamp" as a dependency allows this plugin to use the
    // timestamp-indexed data while performing its own indexing operations
    // In other words, returning {"timestamp"} ensures that the index passed
    // into the following functions will contain the entire (not partial)
    // "timestamp" index. The full index passed into the following functions
    // is just for your reference, your indexEvent function will still be called
    // on every single event in the log in the order in which they are stored in
    // the log.
    virtual std::set<std::string> dependsOn() const;

    // Do anything that your plugin requires doing before the indexing process
    // starts but after all dependencies have run
    //
    // the index argument refers to the entirety of the index created thus far.
    // If you had specifided "timestamp" as a dependency of this plugin, index
    // might look like this:
    //
    // {
    //     "timestamp" : {
    //         "IMAGES" : {
    //             "image_t" : [
    //                 "0",
    //                 "1001000",
    //                 "2002000",
    //                 ...
    //                 "37037000"
    //             ]
    //         },
    //         "BEACON_COORDS" : {
    //             "beacon_t" : [
    //                 "1000000",
    //                 "1000100",
    //                 "1000200",
    //                 "1000300",
    //                 ...
    //                 "37036900"
    //             ]
    //         }
    //     },
    //     "custom plugin" : {
    //     }
    // }
    //
    // pluginIndex would be the object in json that you will modify to create
    // your index. In the case above, pluginIndex would be empty when passed
    // into this function:
    //
    //     "custom plugin" : {
    //     }
    //
    // return true from this if you would like the below indexEvent function to
    // be called on every event in the log. returning false from here would
    // skip the log traversal step that calls indexEvent on each event and would
    // skip straight to tear down
    //
    virtual bool setUp(const zcm::Json::Value& index,
                       zcm::Json::Value& pluginIndex,
                       zcm::LogFile& log);

    // pluginIndex is the index you should modify. It is your json object that
    // will be passed back to this function every time the function is called.
    // This function will be called on every event in the log
    //
    // index is the entire json object containing the output of every plugin run
    // so far
    //
    // channel is the channel name of the event
    //
    // typeName is the name of the zcmtype encoded inside the event
    //
    // offset is the index into the eventlog where this event is stored
    // each susbequent indexEvent call will be called with a larger offset
    // than the last. In other words, "offset" is monotonically increasing
    // across indexEvent calls
    //
    // timestamp is the timestamp of the event. Not to be confused with any
    // fields contained in the zcmtype message itself. This is the timestamp
    // of the event as reported by the transport that originally received it.
    //
    // hash is the hash of the type encoded inside the event
    //
    // data and datalen is the payload of the event
    // To recover the zcmtype message from these arguments, simply call:
    //
    //  if (hash == msg_t::getHash()) {
    //      msg_t msg;
    //      msg.decode(data, 0, datalen);
    //  }
    //
    // The default plugin indexes in the following way. You might want to
    // follow suit but that decision is left completely up to you.
    //
    // pluginIndex[channel][typeName].append(offset);
    //
    //
    virtual void indexEvent(const zcm::Json::Value& index,
                            zcm::Json::Value& pluginIndex,
                            std::string channel,
                            std::string typeName,
                            off_t offset,
                            uint64_t timestamp,
                            int64_t hash,
                            const char* data,
                            int32_t datalen);

    // Do anything that your plugin requires doing before the indexer exits
    // If your data needs to be sorted, do so here
    virtual void tearDown(const zcm::Json::Value& index,
                          zcm::Json::Value& pluginIndex,
                          zcm::LogFile& log);
};

}
<|endoftext|>


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

#ifndef _VCL_GTKGDI_HXX
#define _VCL_GTKGDI_HXX

#include <prex.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
#include <postx.h>

#ifndef _SV_SALGDI_H
#include <salgdi.h>
#endif

class GtkSalGraphics : public X11SalGraphics
{
    GtkWidget           *m_pWindow;
public:
                        GtkSalGraphics( GtkWidget *window ) { m_pWindow = window; }
    virtual             ~GtkSalGraphics();

    inline GtkWidget*  GetGtkWidget() const { return m_pWindow; }
    inline GdkWindow*  GetGdkWindow() const { return m_pWindow->window; }
    inline GtkSalFrame* GetGtkFrame() const { return static_cast<GtkSalFrame*>(m_pFrame); }

    // will be set when UI theme was changed
    static  BOOL        bThemeChanged;

    // native widget methods
    virtual BOOL        IsNativeControlSupported( ControlType nType, ControlPart nPart );
    virtual BOOL        hitTestNativeControl( ControlType nType, ControlPart nPart, const Region& rControlRegion,
                                              const Point& aPos, SalControlHandle& rControlHandle, BOOL& rIsInside );
    virtual BOOL        drawNativeControl( ControlType nType, ControlPart nPart, const Region& rControlRegion,
                                           ControlState nState, const ImplControlValue& aValue, SalControlHandle& rControlHandle,
                                           rtl::OUString aCaption );
    virtual BOOL        drawNativeControlText( ControlType nType, ControlPart nPart, const Region& rControlRegion,
                                               ControlState nState, const ImplControlValue& aValue,
                                               SalControlHandle& rControlHandle, rtl::OUString aCaption );
    virtual BOOL        getNativeControlRegion( ControlType nType, ControlPart nPart, const Region& rControlRegion, ControlState nState,
                                                const ImplControlValue& aValue, SalControlHandle& rControlHandle, rtl::OUString aCaption,
                                                Region &rNativeBoundingRegion, Region &rNativeContentRegion );

protected:
    GdkPixmap* NWGetPixmapFromScreen( Rectangle srcRect );
    BOOL NWRenderPixmapToScreen( GdkPixmap* pPixmap, Rectangle dstRect );

    BOOL NWPaintGTKButton( ControlType nType, ControlPart nPart,
                           const Region& rControlRegion, ControlState nState, const ImplControlValue& aValue,
                           SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKRadio( ControlType nType, ControlPart nPart,
                            const Region& rControlRegion, ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKCheck( ControlType nType, ControlPart nPart,
                            const Region& rControlRegion, ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKScrollbar( ControlType nType, ControlPart nPart,
                            const Region& rControlRegion, ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKEditBox( ControlType nType, ControlPart nPart,
                            const Region& rControlRegion, ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKSpinBox( ControlType nType, ControlPart nPart,
                            const Region& rControlRegion, ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKComboBox( ControlType nType, ControlPart nPart,
                            const Region& rControlRegion, ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKTabItem( ControlType nType, ControlPart nPart,
                            const Region& rControlRegion, ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKListBox( ControlType nType, ControlPart nPart,
                            const Region& rControlRegion, ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );

};

#endif // _VCL_GTKGDI_HXX
<commit_msg>INTEGRATION: CWS docking4 (1.2.92); FILE MERGED 2004/10/20 09:18:44 pl 1.2.92.6: #i28454# speedup paint fix 2004/10/19 19:46:16 pl 1.2.92.5: #i28454# cleaned up LOTS ofpainting issues 2004/10/17 15:12:24 pl 1.2.92.4: #i32193# menu background 2004/10/15 14:10:34 pl 1.2.92.3: global widget cleanup 2004/10/14 17:03:04 pl 1.2.92.2: #i32193# native menubar 2004/09/03 16:46:46 pl 1.2.92.1: #32193# nwf for toolbar background and grip<commit_after>/*************************************************************************
 *
 *  $RCSfile: gtkgdi.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: obo $ $Date: 2004-11-16 15:15:07 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _VCL_GTKGDI_HXX
#define _VCL_GTKGDI_HXX

#include <prex.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
#include <postx.h>

#ifndef _SV_SALGDI_H
#include <salgdi.h>
#endif

class GtkSalGraphics : public X11SalGraphics
{
    GtkWidget           *m_pWindow;
    Region               m_aClipRegion;

public:
                        GtkSalGraphics( GtkWidget *window )
                            : m_pWindow( window ),
                              m_aClipRegion( REGION_NULL )
                              {}
    virtual             ~GtkSalGraphics();

    inline GtkWidget*  GetGtkWidget() const { return m_pWindow; }
    inline GdkWindow*  GetGdkWindow() const { return m_pWindow->window; }
    inline GtkSalFrame* GetGtkFrame() const { return static_cast<GtkSalFrame*>(m_pFrame); }

    // will be set when UI theme was changed
    static  BOOL        bThemeChanged;

    // native widget methods
    virtual BOOL        IsNativeControlSupported( ControlType nType, ControlPart nPart );
    virtual BOOL        hitTestNativeControl( ControlType nType, ControlPart nPart, const Region& rControlRegion,
                                              const Point& aPos, SalControlHandle& rControlHandle, BOOL& rIsInside );
    virtual BOOL        drawNativeControl( ControlType nType, ControlPart nPart, const Region& rControlRegion,
                                           ControlState nState, const ImplControlValue& aValue, SalControlHandle& rControlHandle,
                                           rtl::OUString aCaption );
    virtual BOOL        drawNativeControlText( ControlType nType, ControlPart nPart, const Region& rControlRegion,
                                               ControlState nState, const ImplControlValue& aValue,
                                               SalControlHandle& rControlHandle, rtl::OUString aCaption );
    virtual BOOL        getNativeControlRegion( ControlType nType, ControlPart nPart, const Region& rControlRegion, ControlState nState,
                                                const ImplControlValue& aValue, SalControlHandle& rControlHandle, rtl::OUString aCaption,
                                                Region &rNativeBoundingRegion, Region &rNativeContentRegion );

    //helper methods for frame's UpdateSettings
    void updateSettings( AllSettings& rSettings );

    virtual void            ResetClipRegion();
    virtual void            BeginSetClipRegion( ULONG nCount );
    virtual BOOL            unionClipRegion( long nX, long nY, long nWidth, long nHeight );
    virtual void            EndSetClipRegion();

protected:
    typedef std::list< Rectangle > clipList;

    GdkPixmap* NWGetPixmapFromScreen( Rectangle srcRect );
    BOOL NWRenderPixmapToScreen( GdkPixmap* pPixmap, Rectangle dstRect );

    BOOL NWPaintGTKButton( ControlType nType, ControlPart nPart,
                           const Rectangle& rControlRectangle,
                           const clipList& rClipList,
                           ControlState nState, const ImplControlValue& aValue,
                           SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKRadio( ControlType nType, ControlPart nPart,
                          const Rectangle& rControlRectangle,
                          const clipList& rClipList,
                          ControlState nState, const ImplControlValue& aValue,
                          SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKCheck( ControlType nType, ControlPart nPart,
                          const Rectangle& rControlRectangle,
                          const clipList& rClipList,
                          ControlState nState, const ImplControlValue& aValue,
                          SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKScrollbar( ControlType nType, ControlPart nPart,
                              const Rectangle& rControlRectangle,
                              const clipList& rClipList,
                              ControlState nState, const ImplControlValue& aValue,
                              SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKEditBox( ControlType nType, ControlPart nPart,
                            const Rectangle& rControlRectangle,
                            const clipList& rClipList,
                            ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKSpinBox( ControlType nType, ControlPart nPart,
                            const Rectangle& rControlRectangle,
                            const clipList& rClipList,
                            ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKComboBox( ControlType nType, ControlPart nPart,
                             const Rectangle& rControlRectangle,
                             const clipList& rClipList,
                             ControlState nState, const ImplControlValue& aValue,
                             SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKTabItem( ControlType nType, ControlPart nPart,
                            const Rectangle& rControlRectangle,
                            const clipList& rClipList,
                            ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKListBox( ControlType nType, ControlPart nPart,
                            const Rectangle& rControlRectangle,
                            const clipList& rClipList,
                            ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );

    BOOL NWPaintGTKToolbar( ControlType nType, ControlPart nPart,
                            const Rectangle& rControlRectangle,
                            const clipList& rClipList,
                            ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKMenubar( ControlType nType, ControlPart nPart,
                            const Rectangle& rControlRectangle,
                            const clipList& rClipList,
                            ControlState nState, const ImplControlValue& aValue,
                            SalControlHandle& rControlHandle, OUString aCaption );
    BOOL NWPaintGTKPopupMenu( ControlType nType, ControlPart nPart,
                              const Rectangle& rControlRectangle,
                              const clipList& rClipList,
                              ControlState nState, const ImplControlValue& aValue,
                              SalControlHandle& rControlHandle, OUString aCaption );

};

#endif // _VCL_GTKGDI_HXX
<|endoftext|>


<commit_before>#include <v8.h>
#include <node.h>
#include <nan.h>
#include <pHash.h>
#include <sstream>
#include <fstream>
#include <iomanip>
using namespace node;

bool fileExists(const char* filename) {
    ifstream file(filename);
    return !!file;
}

template <typename T>
string NumberToString ( T Number ) {
    ostringstream ss;
    ss << Number;
    return ss.str();
}

// https://gist.github.com/rvagg/bb08a8bd2b6cbc264056#file-phash-cpp
class PhashRequest : public Nan::AsyncWorker {
 public:
  PhashRequest(Nan::Callback *callback, string file)
    : Nan::AsyncWorker(callback), error(false), file(file), bigint("") {}
  ~PhashRequest() {}

  void Execute () {
    // prevent segfault on an empty file, see https://github.com/aaronm67/node-phash/issues/8
    const char* _file = file.c_str();
    if (!fileExists(_file)) {
        error = true;
        return;
    }

    try {
        ph_dct_imagehash(_file, hash);
        bigint = NumberToString(hash);
    }
    catch(...) {
        error = true;
        // something went wrong with hashing
        // probably a CImg or ImageMagick IO Problem
    }
  }

  void HandleOKCallback () {
    Nan::HandleScope scope;

    v8::Local<v8::Value> argv[3];

    if (error) {
        argv[0] = Nan::Error("Error getting image phash.");
    }
    else {
        argv[0] = Nan::Null();
    }

    // A bit messy - converts the ulong64 into a char* (byte array) needed to create a Buffer
    // The problem is that the number's bytes are in the reverse of the needed order
    // That's why this loop pulls values in reverse
    size_t size = sizeof hash;
    char* hashPtr = (char*) &hash;
    char buffer[size];
    for (unsigned int i = 0; i < size; i++) {
      buffer[i] = hashPtr[size - i - 1];
    }

    argv[1] = Nan::NewBuffer(buffer, sizeof hash).ToLocalChecked();
    argv[2] = Nan::New<v8::String>(bigint).ToLocalChecked();

    callback->Call(3, argv);
  }

 private:
    bool error;
    string file;
    ulong64 hash;
    string bigint;
};

NAN_METHOD(ImageHashAsync) {
    v8::String::Utf8Value str(info[0]);
    Nan::Callback *callback = new Nan::Callback(info[1].As<v8::Function>());
    Nan::AsyncQueueWorker(new PhashRequest(callback, string(*str)));
    return;
}

// https://gist.github.com/rvagg/bb08a8bd2b6cbc264056#file-phash-cpp
class MHPhashRequest : public Nan::AsyncWorker {
 public:
  MHPhashRequest(Nan::Callback *callback, string file)
    : Nan::AsyncWorker(callback), error(false), file(file) {}
  ~MHPhashRequest() {}

  void Execute () {
    // prevent segfault on an empty file, see https://github.com/aaronm67/node-phash/issues/8
    const char* _file = file.c_str();
    if (!fileExists(_file)) {
        error = true;
        return;
    }

    try {
        int alpha = 2;
        int level = 1;
        hash = ph_mh_imagehash(_file, hashlen, alpha, level);
    }
    catch(...) {
        error = true;
        // something went wrong with hashing
        // probably a CImg or ImageMagick IO Problem
    }
  }

  void HandleOKCallback () {
    Nan::HandleScope scope;

    v8::Local<v8::Value> argv[2];

    if (error) {
        argv[0] = Nan::Error("Error getting image phash.");
    }
    else {
        argv[0] = Nan::Null();
    }

    argv[1] = Nan::NewBuffer((char*) hash, hashlen * sizeof hash[0]).ToLocalChecked();

    callback->Call(2, argv);

  }

 private:
    bool error;
    string file;
    uint8_t* hash;
    int hashlen = 0;
};

NAN_METHOD(MHImageHashAsync) {
    v8::String::Utf8Value str(info[0]);
    Nan::Callback *callback = new Nan::Callback(info[1].As<v8::Function>());
    Nan::AsyncQueueWorker(new MHPhashRequest(callback, string(*str)));
    return;
}

void RegisterModule(v8::Local<v8::Object> target) {
  Nan::SetMethod(target, "imageHash", ImageHashAsync);
  Nan::SetMethod(target, "imageHashMH", MHImageHashAsync);
}

NODE_MODULE(pHash, RegisterModule);
<commit_msg>Properly allocate buffer<commit_after>#include <v8.h>
#include <node.h>
#include <nan.h>
#include <pHash.h>
#include <sstream>
#include <fstream>
#include <iomanip>
using namespace node;

bool fileExists(const char* filename) {
    ifstream file(filename);
    return !!file;
}

template <typename T>
string NumberToString ( T Number ) {
    ostringstream ss;
    ss << Number;
    return ss.str();
}

// https://gist.github.com/rvagg/bb08a8bd2b6cbc264056#file-phash-cpp
class PhashRequest : public Nan::AsyncWorker {
 public:
  PhashRequest(Nan::Callback *callback, string file)
    : Nan::AsyncWorker(callback), error(false), file(file), bigint("") {}
  ~PhashRequest() {}

  void Execute () {
    // prevent segfault on an empty file, see https://github.com/aaronm67/node-phash/issues/8
    const char* _file = file.c_str();
    if (!fileExists(_file)) {
        error = true;
        return;
    }

    try {
        ph_dct_imagehash(_file, hash);
        bigint = NumberToString(hash);
    }
    catch(...) {
        error = true;
        // something went wrong with hashing
        // probably a CImg or ImageMagick IO Problem
    }
  }

  void HandleOKCallback () {
    Nan::HandleScope scope;

    v8::Local<v8::Value> argv[3];

    if (error) {
        argv[0] = Nan::Error("Error getting image phash.");
    }
    else {
        argv[0] = Nan::Null();
    }

    // A bit messy - converts the ulong64 into a char* (byte array) needed to create a Buffer
    // The problem is that the number's bytes are in the reverse of the needed order
    // That's why this loop pulls values in reverse
    size_t size = sizeof hash;
    char* hashPtr = (char*) &hash;
    char* buffer = (char*) malloc(size);
    for (unsigned int i = 0; i < size; i++) {
      buffer[i] = hashPtr[size - i - 1];
    }

    argv[1] = Nan::NewBuffer(buffer, size).ToLocalChecked();
    argv[2] = Nan::New<v8::String>(bigint).ToLocalChecked();

    callback->Call(3, argv);
  }

 private:
    bool error;
    string file;
    ulong64 hash;
    string bigint;
};

NAN_METHOD(ImageHashAsync) {
    v8::String::Utf8Value str(info[0]);
    Nan::Callback *callback = new Nan::Callback(info[1].As<v8::Function>());
    Nan::AsyncQueueWorker(new PhashRequest(callback, string(*str)));
    return;
}

// https://gist.github.com/rvagg/bb08a8bd2b6cbc264056#file-phash-cpp
class MHPhashRequest : public Nan::AsyncWorker {
 public:
  MHPhashRequest(Nan::Callback *callback, string file)
    : Nan::AsyncWorker(callback), error(false), file(file) {}
  ~MHPhashRequest() {}

  void Execute () {
    // prevent segfault on an empty file, see https://github.com/aaronm67/node-phash/issues/8
    const char* _file = file.c_str();
    if (!fileExists(_file)) {
        error = true;
        return;
    }

    try {
        int alpha = 2;
        int level = 1;
        hash = ph_mh_imagehash(_file, hashlen, alpha, level);
    }
    catch(...) {
        error = true;
        // something went wrong with hashing
        // probably a CImg or ImageMagick IO Problem
    }
  }

  void HandleOKCallback () {
    Nan::HandleScope scope;

    v8::Local<v8::Value> argv[2];

    if (error) {
        argv[0] = Nan::Error("Error getting image phash.");
    }
    else {
        argv[0] = Nan::Null();
    }

    argv[1] = Nan::NewBuffer((char*) hash, hashlen * sizeof hash[0]).ToLocalChecked();

    callback->Call(2, argv);

  }

 private:
    bool error;
    string file;
    uint8_t* hash;
    int hashlen = 0;
};

NAN_METHOD(MHImageHashAsync) {
    v8::String::Utf8Value str(info[0]);
    Nan::Callback *callback = new Nan::Callback(info[1].As<v8::Function>());
    Nan::AsyncQueueWorker(new MHPhashRequest(callback, string(*str)));
    return;
}

void RegisterModule(v8::Local<v8::Object> target) {
  Nan::SetMethod(target, "imageHash", ImageHashAsync);
  Nan::SetMethod(target, "imageHashMH", MHImageHashAsync);
}

NODE_MODULE(pHash, RegisterModule);
<|endoftext|>


<commit_before>/**
 ** \file ast/visitor.hxx
 ** \brief Definition of ast::Visitor.
 */

#ifndef AST_VISITOR_HXX
# define AST_VISITOR_HXX

# include <ast/visitor.hh>

namespace ast
{
  template < template <typename> class Const >
  GenVisitor<Const>::~GenVisitor ()
  {
  }

  template < template <typename> class Const >
  inline
  void
  GenVisitor<Const>::operator() (ast_type e)
  {
    if (e)
      e->accept(*this);
  }

} // namespace ast

#endif // !AST_VISITOR_HXX
<commit_msg>Add forgotten include.<commit_after>/**
 ** \file ast/visitor.hxx
 ** \brief Definition of ast::Visitor.
 */

#ifndef AST_VISITOR_HXX
# define AST_VISITOR_HXX

# include <ast/ast.hh>
# include <ast/visitor.hh>

namespace ast
{
  template < template <typename> class Const >
  GenVisitor<Const>::~GenVisitor ()
  {
  }

  template < template <typename> class Const >
  inline
  void
  GenVisitor<Const>::operator() (ast_type e)
  {
    if (e)
      e->accept(*this);
  }

} // namespace ast

#endif // !AST_VISITOR_HXX
<|endoftext|>


<commit_before>#include "ConstantBitP_TransferFunctions.h"
#include "ConstantBitP_Utility.h"

namespace simplifier
{
namespace constantBitP
{

namespace BEEV
{
typedef unsigned int * CBV;
}

// Misc (easy) transfer functions.
// Trevor Hansen. BSD License.

// if the result is fixed to true. Then fix a==b.
// if the result is fixed to false, there is a single unspecied value, and all the rest are the same. Fix it to the opposite.

// if a==b then fix the result to true.
// if a!=b then fix the result to false.
Result bvEqualsBothWays(FixedBits& a, FixedBits& b, FixedBits& output)
{
	assert(a.getWidth() == b.getWidth());
	assert(1 == output.getWidth());

	const int childWidth = a.getWidth();

	Result r = NO_CHANGE;

	bool allSame = true;
	bool definatelyFalse = false;

	for (int i = 0; i < childWidth; i++)
	{
		// if both fixed
		if (a.isFixed(i) && b.isFixed(i))
		{
			// And have different values.
			if (a.getValue(i) != b.getValue(i))
			{
				definatelyFalse = true;
			}
			else
			{
				allSame &= true;
				continue;
			}
		}
		allSame &= false;
	}

	if (definatelyFalse)
	{
		if (output.isFixed(0) && output.getValue(0))
		{
			return CONFLICT;
		}
		else if (!output.isFixed(0))
		{
			output.setFixed(0, true);
			output.setValue(0, false);
			r = CHANGED;
		}
	}
	else if (allSame)
	{
		if (output.isFixed(0) && !output.getValue(0))
		{
			return CONFLICT;
		}
		else if (!output.isFixed(0))
		{
			output.setFixed(0, true);
			output.setValue(0, true);
			r = CHANGED;
		}
	}

	if (output.isFixed(0) && output.getValue(0)) // all should be the same.
	{
		for (int i = 0; i < childWidth; i++)
		{
			if (a.isFixed(i) && b.isFixed(i))
			{
				if (a.getValue(i) != b.getValue(i))
				{
					return CONFLICT;
				}
			}
			else if (a.isFixed(i) != b.isFixed(i)) // both same but only one is fixed.
			{
				if (a.isFixed(i))
				{
					b.setFixed(i, true);
					b.setValue(i, a.getValue(i));
					r = CHANGED;
				}
				else
				{
					a.setFixed(i, true);
					a.setValue(i, b.getValue(i));
					r = CHANGED;
				}
			}
		}
	}

	// if the result is fixed to false, there is a single unspecied value, and all the rest are the same. Fix it to the opposite.
	if (output.isFixed(0) && !output.getValue(0))
	{
		int unknown = 0;

		for (int i = 0; i < childWidth; i++)
		{
			if (!a.isFixed(i))
				unknown++;
			if (!b.isFixed(i))
				unknown++;
			else if (a.isFixed(i) && b.isFixed(i) && a.getValue(i) != b.getValue(i))
			{
				unknown = 10; // hack, don't do the next loop.
				break;
			}
		}

		if (1 == unknown)
		{
			for (int i = 0; i < childWidth; i++)
			{
				if (!a.isFixed(i))
				{
					a.setFixed(i, true);
					a.setValue(i, !b.getValue(i));
					r = CHANGED;
				}
				if (!b.isFixed(i))
				{
					b.setFixed(i, true);
					b.setValue(i, !a.getValue(i));
					r = CHANGED;
				}
			}
		}
	}
	return r;
}

Result bvEqualsBothWays(vector<FixedBits*>& children, FixedBits& result)
{
	return bvEqualsBothWays(*(children[0]), *(children[1]), result);
}

Result bvZeroExtendBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	assert(children.size() ==2 );
	// The second argument is a junk size arugment.

	FixedBits& input = *children[0];
	const int inputBitWidth = input.getWidth();
	const int outputBitWidth = output.getWidth();

	Result result = makeEqual(input, output, 0, inputBitWidth);
	if (CONFLICT == result)
		return CONFLICT;

	// Fix all the topmost bits of the output to zero.
	for (int i = inputBitWidth; i < outputBitWidth; i++)
	{
		if (output.isFixed(i) && output.getValue(i))
			return CONFLICT; // set to one. Never right.
		else if (!output.isFixed(i))
		{
			output.setFixed(i, true);
			output.setValue(i, false);
			result = CHANGED;
		}
	}
	return result;
}

Result bvSignExtendBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	assert(children.size() ==2 );
	// The second argument is a junk size arugment.

	FixedBits& input = *children[0];
	const int inputBitWidth = input.getWidth();
	const int outputBitWidth = output.getWidth();
	assert(inputBitWidth <= outputBitWidth);

	Result result = makeEqual(input, output, 0, inputBitWidth);
	if (CONFLICT == result)
		return CONFLICT;

	// If any of the topmost bits of the output are fixed. Then they all should be.
	// They should all be fixed to the same value.
	bool found = false;
	bool setTo;
	for (int i = inputBitWidth - /**/1 /**/; i < outputBitWidth; i++)
	{
		if (output.isFixed(i))
		{
			setTo = output.getValue(i);
			found = true;
			break;
		}
	}

	if (found)
	{
		for (int i = inputBitWidth - 1; i < outputBitWidth; i++)
		{
			if (output.isFixed(i) && (output.getValue(i) != setTo))
				return CONFLICT; // if any are set to the wrong value! bad.
			else if (!output.isFixed(i))
			{
				output.setFixed(i, true);
				output.setValue(i, setTo);
				result = CHANGED;
			}
		}

		Result result2 = makeEqual(input, output, 0, inputBitWidth);
		if (CONFLICT == result2)
			return CONFLICT;

	}
	return result;
}

Result bvExtractBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	const int numberOfChildren = children.size();
	const int outputBitWidth = output.getWidth();

	Result result = NO_CHANGE;

	assert(3 == numberOfChildren);

	int top = children[1]->getUnsignedValue();
	int bottom = children[2]->getUnsignedValue();

	FixedBits& input = *(children[0]);

	assert(top >= bottom);
	assert(bottom >=0);
	assert(top - bottom + 1 == outputBitWidth);
	assert(top < input.getWidth());

	for (int outputPosition = 0; outputPosition < outputBitWidth; outputPosition++)
	{
		int inputPosition = outputPosition + bottom;

		if (input.isFixed(inputPosition) && output.isFixed(outputPosition))
			if (input.getValue(inputPosition) ^ output.getValue(outputPosition))
				return CONFLICT;

		if (input.isFixed(inputPosition) ^ output.isFixed(outputPosition))
		{
			if (input.isFixed(inputPosition))
			{
				output.setFixed(outputPosition, true);
				output.setValue(outputPosition, input.getValue(inputPosition));
				result = CHANGED;
			}
			else
			{
				input.setFixed(inputPosition, true);
				input.setValue(inputPosition, output.getValue(outputPosition));
				result = CHANGED;
			}
		}
	}

	//cerr << "extract[" << top << ":" << bottom << "]" << input << "=" << output<< endl;

	return result;
}

// UMINUS, is NEG followed by +1
Result bvUnaryMinusBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	assert(children.size() == 1);
	const int bitWidth = children[0]->getWidth();

	// If it's only one bit. This will be negative one.
	FixedBits one(bitWidth, false);
	one.fixToZero();
	one.setFixed(0, true);
	one.setValue(0, true);

	FixedBits notted(bitWidth, false);

	vector<FixedBits*> args;
	args.push_back(&notted);
	args.push_back(&one);

	Result result = NO_CHANGE;
	while (true) // until it fixed points
	{
		FixedBits initialNot(notted);
		FixedBits initialIn(*children[0]);
		FixedBits initialOut(output);

		result = bvNotBothWays(*children[0], notted);
		if (CONFLICT == result)
			return CONFLICT;

		result = bvAddBothWays(args, output);
		if (CONFLICT == result)
			return CONFLICT;

		if (FixedBits::equals(initialNot, notted) && FixedBits::equals(initialIn, *children[0]) && FixedBits::equals(initialOut, output))
			break;
	}

	return NOT_IMPLEMENTED; // don't set the status properly yet..
}

Result bvConcatBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	Result r = NO_CHANGE;
	const int numberOfChildren = children.size();
	int current = 0;
	for (int i = numberOfChildren - 1; i >= 0; i--) // least significant is last.

	{
		FixedBits& child = *children[i];
		for (int j = 0; j < child.getWidth(); j++)
		{
			// values are different. Bad.
			if (output.isFixed(current) && child.isFixed(j) && (output.getValue(current) != child.getValue(j)))
				return CONFLICT;

			if (output.isFixed(current) && !child.isFixed(j))
			{
				// only output is fixed.
				child.setFixed(j, true);
				child.setValue(j, output.getValue(current));
				r = CHANGED;
			}
			else if (!output.isFixed(current) && child.isFixed(j))
			{
				// only input is fixed.
				output.setFixed(current, true);
				output.setValue(current, child.getValue(j));
				r = CHANGED;
			}
			current++;
		}
	}
	return r;
}

// If the guard is fixed, make equal the appropriate input and output.
// If one input can not possibly be the output. Then set the guard to make it the other one.
// If both values are the same. Set the output to that value.
Result bvITEBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	Result result = NO_CHANGE;

	assert(3 == children.size());
	const int bitWidth = output.getWidth();
	FixedBits& guard = *children[0];
	FixedBits& c1 = *children[1];
	FixedBits& c2 = *children[2];

	assert(c1.getWidth() == c2.getWidth());
	assert(output.getWidth() == c2.getWidth());

	if (guard.isFixed(0) && guard.getValue(0))
	{ // guard fixed to true. So make (first arg == output)
		result = makeEqual(output, c1, 0, bitWidth);
		if (CONFLICT == result)
			return CONFLICT;

	}
	else if (guard.isFixed(0) && !guard.getValue(0))
	{
		result = makeEqual(output, c2, 0, bitWidth);
		if (CONFLICT == result)
			return CONFLICT;

	}
	else
	{
		for (int i = 0; i < bitWidth; i++)
		{
			if (c1.isFixed(i) && c2.isFixed(i) && (c1.getValue(i) == c2.getValue(i)))
			{

				if (output.isFixed(i) && (output.getValue(i) != c1.getValue(i)))
					return CONFLICT;

				if (!output.isFixed(i))
				{
					output.setFixed(i, true);
					output.setValue(i, c1.getValue(i));
					result = CHANGED;
				}
			}
		}
	}

	bool changed = false;
	if (CHANGED == result)
		changed = true;

	for (int i = 0; i < bitWidth; i++)
	{
		if (output.isFixed(i))
		{
			if (c1.isFixed(i) && (c1.getValue(i) != output.getValue(i)))
			{
				//c1 is fixed to a value that's not the same as the output.
				if (!guard.isFixed(0))
				{
					guard.setFixed(0, true);
					guard.setValue(0, false);
					result = bvITEBothWays(children, output);
					if (CONFLICT == result)
						return CONFLICT;
					changed = true;
				}
				else if (guard.getValue(0))
					return CONFLICT;
			}

			if (c2.isFixed(i) && (c2.getValue(i) != output.getValue(i)))
			{
				//c2 is fixed to a value that's not the same as the output.
				if (!guard.isFixed(0))
				{
					guard.setFixed(0, true);
					guard.setValue(0, true);
					result = bvITEBothWays(children, output);
					if (CONFLICT == result)
						return CONFLICT;
					changed = true;

				}
				else if (!guard.getValue(0))
					return CONFLICT;
			}
		}
	}

	if (result == CONFLICT)
		return CONFLICT;
	if (changed)
		return CHANGED;

	return result;
}

}

}
<commit_msg>Slightly speed up the equals propagator.<commit_after>#include "ConstantBitP_TransferFunctions.h"
#include "ConstantBitP_Utility.h"

namespace simplifier
{
namespace constantBitP
{

namespace BEEV
{
typedef unsigned int * CBV;
}

// Misc (easy) transfer functions.
// Trevor Hansen. BSD License.

// if the result is fixed to true. Then fix a==b.
// if the result is fixed to false, there is a single unspecied value, and all the rest are the same. Fix it to the opposite.

// if a==b then fix the result to true.
// if a!=b then fix the result to false.
Result bvEqualsBothWays(FixedBits& a, FixedBits& b, FixedBits& output)
{
	assert(a.getWidth() == b.getWidth());
	assert(1 == output.getWidth());

	const int childWidth = a.getWidth();

	Result r = NO_CHANGE;

	bool allSame = true;
	bool definatelyFalse = false;

	for (int i = 0; i < childWidth; i++)
	{
		// if both fixed
		if (a.isFixed(i) && b.isFixed(i))
		{
			// And have different values.
			if (a.getValue(i) != b.getValue(i))
			{
				definatelyFalse = true;
				break;
			}
			else
			{
				allSame &= true;
				continue;
			}
		}
		allSame &= false;
	}

	if (definatelyFalse)
	{
		if (output.isFixed(0) && output.getValue(0))
		{
			return CONFLICT;
		}
		else if (!output.isFixed(0))
		{
			output.setFixed(0, true);
			output.setValue(0, false);
			r = CHANGED;
		}
	}
	else if (allSame)
	{
		if (output.isFixed(0) && !output.getValue(0))
		{
			return CONFLICT;
		}
		else if (!output.isFixed(0))
		{
			output.setFixed(0, true);
			output.setValue(0, true);
			r = CHANGED;
		}
	}

	if (output.isFixed(0) && output.getValue(0)) // all should be the same.
	{
		for (int i = 0; i < childWidth; i++)
		{
			if (a.isFixed(i) && b.isFixed(i))
			{
				if (a.getValue(i) != b.getValue(i))
				{
					return CONFLICT;
				}
			}
			else if (a.isFixed(i) != b.isFixed(i)) // both same but only one is fixed.
			{
				if (a.isFixed(i))
				{
					b.setFixed(i, true);
					b.setValue(i, a.getValue(i));
					r = CHANGED;
				}
				else
				{
					a.setFixed(i, true);
					a.setValue(i, b.getValue(i));
					r = CHANGED;
				}
			}
		}
	}

	// if the result is fixed to false, there is a single unspecied value, and all the rest are the same. Fix it to the opposite.
	if (output.isFixed(0) && !output.getValue(0))
	{
		int unknown = 0;

		for (int i = 0; i < childWidth && unknown < 2; i++)
		{
			if (!a.isFixed(i))
				unknown++;
			if (!b.isFixed(i))
				unknown++;
			else if (a.isFixed(i) && b.isFixed(i) && a.getValue(i) != b.getValue(i))
			{
				unknown = 10; // hack, don't do the next loop.
				break;
			}
		}

		if (1 == unknown)
		{
			for (int i = 0; i < childWidth; i++)
			{
				if (!a.isFixed(i))
				{
					a.setFixed(i, true);
					a.setValue(i, !b.getValue(i));
					r = CHANGED;
				}
				if (!b.isFixed(i))
				{
					b.setFixed(i, true);
					b.setValue(i, !a.getValue(i));
					r = CHANGED;
				}
			}
		}
	}
	return r;
}

Result bvEqualsBothWays(vector<FixedBits*>& children, FixedBits& result)
{
	return bvEqualsBothWays(*(children[0]), *(children[1]), result);
}

Result bvZeroExtendBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	assert(children.size() ==2 );
	// The second argument is a junk size arugment.

	FixedBits& input = *children[0];
	const int inputBitWidth = input.getWidth();
	const int outputBitWidth = output.getWidth();

	Result result = makeEqual(input, output, 0, inputBitWidth);
	if (CONFLICT == result)
		return CONFLICT;

	// Fix all the topmost bits of the output to zero.
	for (int i = inputBitWidth; i < outputBitWidth; i++)
	{
		if (output.isFixed(i) && output.getValue(i))
			return CONFLICT; // set to one. Never right.
		else if (!output.isFixed(i))
		{
			output.setFixed(i, true);
			output.setValue(i, false);
			result = CHANGED;
		}
	}
	return result;
}

Result bvSignExtendBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	assert(children.size() ==2 );
	// The second argument is a junk size arugment.

	FixedBits& input = *children[0];
	const int inputBitWidth = input.getWidth();
	const int outputBitWidth = output.getWidth();
	assert(inputBitWidth <= outputBitWidth);

	Result result = makeEqual(input, output, 0, inputBitWidth);
	if (CONFLICT == result)
		return CONFLICT;

	// If any of the topmost bits of the output are fixed. Then they all should be.
	// They should all be fixed to the same value.
	bool found = false;
	bool setTo;
	for (int i = inputBitWidth - /**/1 /**/; i < outputBitWidth; i++)
	{
		if (output.isFixed(i))
		{
			setTo = output.getValue(i);
			found = true;
			break;
		}
	}

	if (found)
	{
		for (int i = inputBitWidth - 1; i < outputBitWidth; i++)
		{
			if (output.isFixed(i) && (output.getValue(i) != setTo))
				return CONFLICT; // if any are set to the wrong value! bad.
			else if (!output.isFixed(i))
			{
				output.setFixed(i, true);
				output.setValue(i, setTo);
				result = CHANGED;
			}
		}

		Result result2 = makeEqual(input, output, 0, inputBitWidth);
		if (CONFLICT == result2)
			return CONFLICT;

	}
	return result;
}

Result bvExtractBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	const int numberOfChildren = children.size();
	const int outputBitWidth = output.getWidth();

	Result result = NO_CHANGE;

	assert(3 == numberOfChildren);

	int top = children[1]->getUnsignedValue();
	int bottom = children[2]->getUnsignedValue();

	FixedBits& input = *(children[0]);

	assert(top >= bottom);
	assert(bottom >=0);
	assert(top - bottom + 1 == outputBitWidth);
	assert(top < input.getWidth());

	for (int outputPosition = 0; outputPosition < outputBitWidth; outputPosition++)
	{
		int inputPosition = outputPosition + bottom;

		if (input.isFixed(inputPosition) && output.isFixed(outputPosition))
			if (input.getValue(inputPosition) ^ output.getValue(outputPosition))
				return CONFLICT;

		if (input.isFixed(inputPosition) ^ output.isFixed(outputPosition))
		{
			if (input.isFixed(inputPosition))
			{
				output.setFixed(outputPosition, true);
				output.setValue(outputPosition, input.getValue(inputPosition));
				result = CHANGED;
			}
			else
			{
				input.setFixed(inputPosition, true);
				input.setValue(inputPosition, output.getValue(outputPosition));
				result = CHANGED;
			}
		}
	}

	//cerr << "extract[" << top << ":" << bottom << "]" << input << "=" << output<< endl;

	return result;
}

// UMINUS, is NEG followed by +1
Result bvUnaryMinusBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	assert(children.size() == 1);
	const int bitWidth = children[0]->getWidth();

	// If it's only one bit. This will be negative one.
	FixedBits one(bitWidth, false);
	one.fixToZero();
	one.setFixed(0, true);
	one.setValue(0, true);

	FixedBits notted(bitWidth, false);

	vector<FixedBits*> args;
	args.push_back(&notted);
	args.push_back(&one);

	Result result = NO_CHANGE;
	while (true) // until it fixed points
	{
		FixedBits initialNot(notted);
		FixedBits initialIn(*children[0]);
		FixedBits initialOut(output);

		result = bvNotBothWays(*children[0], notted);
		if (CONFLICT == result)
			return CONFLICT;

		result = bvAddBothWays(args, output);
		if (CONFLICT == result)
			return CONFLICT;

		if (FixedBits::equals(initialNot, notted) && FixedBits::equals(initialIn, *children[0]) && FixedBits::equals(initialOut, output))
			break;
	}

	return NOT_IMPLEMENTED; // don't set the status properly yet..
}

Result bvConcatBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	Result r = NO_CHANGE;
	const int numberOfChildren = children.size();
	int current = 0;
	for (int i = numberOfChildren - 1; i >= 0; i--) // least significant is last.

	{
		FixedBits& child = *children[i];
		for (int j = 0; j < child.getWidth(); j++)
		{
			// values are different. Bad.
			if (output.isFixed(current) && child.isFixed(j) && (output.getValue(current) != child.getValue(j)))
				return CONFLICT;

			if (output.isFixed(current) && !child.isFixed(j))
			{
				// only output is fixed.
				child.setFixed(j, true);
				child.setValue(j, output.getValue(current));
				r = CHANGED;
			}
			else if (!output.isFixed(current) && child.isFixed(j))
			{
				// only input is fixed.
				output.setFixed(current, true);
				output.setValue(current, child.getValue(j));
				r = CHANGED;
			}
			current++;
		}
	}
	return r;
}

// If the guard is fixed, make equal the appropriate input and output.
// If one input can not possibly be the output. Then set the guard to make it the other one.
// If both values are the same. Set the output to that value.
Result bvITEBothWays(vector<FixedBits*>& children, FixedBits& output)
{
	Result result = NO_CHANGE;

	assert(3 == children.size());
	const int bitWidth = output.getWidth();
	FixedBits& guard = *children[0];
	FixedBits& c1 = *children[1];
	FixedBits& c2 = *children[2];

	assert(c1.getWidth() == c2.getWidth());
	assert(output.getWidth() == c2.getWidth());

	if (guard.isFixed(0) && guard.getValue(0))
	{ // guard fixed to true. So make (first arg == output)
		result = makeEqual(output, c1, 0, bitWidth);
		if (CONFLICT == result)
			return CONFLICT;

	}
	else if (guard.isFixed(0) && !guard.getValue(0))
	{
		result = makeEqual(output, c2, 0, bitWidth);
		if (CONFLICT == result)
			return CONFLICT;

	}
	else
	{
		for (int i = 0; i < bitWidth; i++)
		{
			if (c1.isFixed(i) && c2.isFixed(i) && (c1.getValue(i) == c2.getValue(i)))
			{

				if (output.isFixed(i) && (output.getValue(i) != c1.getValue(i)))
					return CONFLICT;

				if (!output.isFixed(i))
				{
					output.setFixed(i, true);
					output.setValue(i, c1.getValue(i));
					result = CHANGED;
				}
			}
		}
	}

	bool changed = false;
	if (CHANGED == result)
		changed = true;

	for (int i = 0; i < bitWidth; i++)
	{
		if (output.isFixed(i))
		{
			if (c1.isFixed(i) && (c1.getValue(i) != output.getValue(i)))
			{
				//c1 is fixed to a value that's not the same as the output.
				if (!guard.isFixed(0))
				{
					guard.setFixed(0, true);
					guard.setValue(0, false);
					result = bvITEBothWays(children, output);
					if (CONFLICT == result)
						return CONFLICT;
					changed = true;
				}
				else if (guard.getValue(0))
					return CONFLICT;
			}

			if (c2.isFixed(i) && (c2.getValue(i) != output.getValue(i)))
			{
				//c2 is fixed to a value that's not the same as the output.
				if (!guard.isFixed(0))
				{
					guard.setFixed(0, true);
					guard.setValue(0, true);
					result = bvITEBothWays(children, output);
					if (CONFLICT == result)
						return CONFLICT;
					changed = true;

				}
				else if (!guard.getValue(0))
					return CONFLICT;
			}
		}
	}

	if (result == CONFLICT)
		return CONFLICT;
	if (changed)
		return CHANGED;

	return result;
}

}

}
<|endoftext|>