<commit_before>/**
 * A thread synchronization barrier implemented using erl_nif synch facilities
 * /
class Barrier {

private:
	uint N_THREADS;

	uint waiting_threads_counts[2];
	uint current_counter;

	ErlNifMutex* mtx;
	ErlNifCond* cond;

public:
	explicit Barrier(uint n_Threads) {
		N_THREADS = n_Threads;
		waiting_threads_counts[0] = waiting_threads_counts[1] = 0;
		current_counter = 0;

		mtx = enif_mutex_create((char*) "map_load_thread_cond_mtx");
		cond = enif_cond_create((char*) "map_load_thread_cond");

		//std::cerr << "Barrier("<< N_THREADS <<") CREATED"<<endl;
	}
	~Barrier() {
		enif_cond_destroy(cond);
		enif_mutex_destroy(mtx);
	}

	void await(){

		enif_mutex_lock(mtx);

		uint local_counter = current_counter;

		waiting_threads_counts[local_counter]++;
		//std::cerr << "await(): waiting_threads_counts[local_counter]++: "<< waiting_threads_counts[local_counter] <<endl;

		if(waiting_threads_counts[local_counter] < N_THREADS) {
			//std::cerr << "await(): Barrier NOT full" <<endl;

			while(waiting_threads_counts[local_counter] < N_THREADS) {
			//	std::cerr << "await(): cond_wait waiting_threads_counts[local_counter]: "<< waiting_threads_counts[local_counter] <<endl;
				enif_cond_wait(cond, mtx);
			}
		}
		else {
			//std::cerr << "await(): Barrier FULL. waiting_threads:" <<waiting_threads_counts[local_counter] << " broadcast!" <<endl;

			current_counter ^= 1;
			waiting_threads_counts[current_counter] = 0;

			enif_cond_broadcast(cond);
		}

	//	std::cerr << "await(): END" <<endl;
		enif_mutex_unlock(mtx);
	}

};

/*array must be big enough to contain list.length elements*/
uint list_to_double_arrayN(ErlNifEnv *env, ERL_NIF_TERM list, double* array, uint arrayLen, ERL_NIF_TERM* lastListCell) {

	if(array == NULL)
		return 0;

	uint len = 0;

	if(enif_is_list(env, list)) {

		ERL_NIF_TERM curr_cell = list;

		uint i = 0;
		for(i = 0; enif_is_list(env, curr_cell) && i < arrayLen; i++) {

			ERL_NIF_TERM hd, tl;
			if(!enif_get_list_cell(env, curr_cell, &hd, &tl))
				break;//list is empty

			if(!(enif_get_double(env, hd, &(array[i]) ))) {
				std::cerr << "DEBUG: list_to_double_arrayN - Error: attempt to read float from something else!" << std::endl;
			}
			curr_cell = tl;

		}

		if(lastListCell != NULL) //user requested the term denoting the last cell
			*lastListCell = curr_cell;

		return i;

	} else { //term "list" is not a list

		#ifdef DEBUG
		std::cerr << "DEBUG: list_to_double_arrayN - Error: trying to convert a non list as a list"<< std::endl ;
		#endif

		return 0;
	}
}

uint sync_list_to_double_arrayN(ErlNifEnv *env, ErlNifMutex *mtx, ERL_NIF_TERM list, double* array, uint arrayLen, ERL_NIF_TERM* lastListCell) {

	enif_mutex_lock(mtx);

	uint result = list_to_double_arrayN(env, list, array,  arrayLen, lastListCell);

	enif_mutex_unlock(mtx);

	return result;

}

void list_to_double_array(ErlNifEnv *env, ERL_NIF_TERM list, uint listLen, double* array) { //TODO scorre la lista 2 volte

	if(array == NULL)
		return;

	uint len = 0;

	if(enif_is_list(env, list)) {

		list_to_double_arrayN(env, list, array, listLen, NULL);
	}

}

ERL_NIF_TERM double_array_to_list(ErlNifEnv *env, double* array, size_t array_size) {

	if(array == NULL)
		return ATOM(error);

	ERL_NIF_TERM* floatTermArray =
			(ERL_NIF_TERM*) enif_alloc(sizeof(ERL_NIF_TERM) * array_size);

	for(uint i = 0; i < array_size; i++)
		floatTermArray[i] = enif_make_double(env, array[i]);

	ERL_NIF_TERM res = enif_make_list_from_array(env, floatTermArray, array_size);

	enif_free(floatTermArray);

	return res;
}

/*returns a string containing the content of the file at filePath
 * otherwise "NULL".*/
string readFromFileStr(char* filePath) {

	ifstream file(filePath, ios::in);
	if (!file.is_open()) {
		cerr << "Failed to open file for reading: " << filePath << endl;
		return "NULL";
	}

	ostringstream oss;
	oss << file.rdbuf();

	return oss.str();
}

/*returns a dinamically allocated string containing the content of the file at filePath
 * otherwise NULL.
 * The returned sting must be enif_free'd when not needed.
 * */
char* readFromFile(char* filePath) {

	string srcStdStr = readFromFileStr(filePath);

	char* toReturn = (char*) enif_alloc(srcStdStr.length()+1);

	return strcpy(toReturn, srcStdStr.c_str());

}

#define MIN(a, b) ((a < b) ? a : b)

int inline isPow2(unsigned int v) { return v && !(v & (v - 1));}

/*
 * Return a value that is nearest value that is power of 2.
 */
unsigned int nextPow2( unsigned int x )
{
    --x;
    x |= x >> 1;
    x |= x >> 2;
    x |= x >> 4;
    x |= x >> 8;
    x |= x >> 16;
    return x+1;
}

// Round Up Division function
size_t roundUp(uint group_size, uint global_size)
{
    uint r = global_size % group_size;
    if(r == 0)
        return global_size;
    else
        return global_size + group_size - r;
}

/*!
 * Compute the number of threads and blocks to use for the REDUCTION kernel.
 * We set threads / block to the minimum of maxThreads and n/2 where n is
 * problem size. We observe the maximum specified number of blocks, because
 * each kernel thread can process more than 1 elements.
 *
 * \param n Problem size.
 * \param maxBlocks Maximum number of blocks that can be used.
 * \param maxThreads Maximum number of threads that can be used.
 * \param blocks An output parameter passed by reference. Specify number of blocks to be used.
 * \param threads An output parameter passed by reference. Specify number of threads to be used.
 */
void getNumBlocksAndThreads(int n, int maxBlocks, int maxThreads, long unsigned int &blocks, long unsigned int &threads)
{
        threads = (n < maxThreads*2) ? nextPow2((n + 1)/ 2) : maxThreads;
        blocks = (n + (threads * 2 - 1)) / (threads * 2);

        if(maxBlocks > 0)
        	blocks = MIN(maxBlocks, blocks);
}

/*
 *  It finds all instances of a string in another string and replaces it with
 *  a third string.
 *
 */
void replaceTextInString(std::string& text, std::string find, std::string replace)
{
        std::string::size_type pos=0;
        while((pos = text.find(find, pos)) != std::string::npos)
        {
            text.erase(pos, find.length());
            text.insert(pos, replace);
            pos+=replace.length();
        }
}

<commit_msg>Update utils.cpp<commit_after>/**
 * A thread synchronization barrier implemented using erl_nif synch facilities
 */
class Barrier {

private:
	uint N_THREADS;

	uint waiting_threads_counts[2];
	uint current_counter;

	ErlNifMutex* mtx;
	ErlNifCond* cond;

public:
	explicit Barrier(uint n_Threads) {
		N_THREADS = n_Threads;
		waiting_threads_counts[0] = waiting_threads_counts[1] = 0;
		current_counter = 0;

		mtx = enif_mutex_create((char*) "map_load_thread_cond_mtx");
		cond = enif_cond_create((char*) "map_load_thread_cond");

		//std::cerr << "Barrier("<< N_THREADS <<") CREATED"<<endl;
	}
	~Barrier() {
		enif_cond_destroy(cond);
		enif_mutex_destroy(mtx);
	}

	void await(){

		enif_mutex_lock(mtx);

		uint local_counter = current_counter;

		waiting_threads_counts[local_counter]++;
		//std::cerr << "await(): waiting_threads_counts[local_counter]++: "<< waiting_threads_counts[local_counter] <<endl;

		if(waiting_threads_counts[local_counter] < N_THREADS) {
			//std::cerr << "await(): Barrier NOT full" <<endl;

			while(waiting_threads_counts[local_counter] < N_THREADS) {
			//	std::cerr << "await(): cond_wait waiting_threads_counts[local_counter]: "<< waiting_threads_counts[local_counter] <<endl;
				enif_cond_wait(cond, mtx);
			}
		}
		else {
			//std::cerr << "await(): Barrier FULL. waiting_threads:" <<waiting_threads_counts[local_counter] << " broadcast!" <<endl;

			current_counter ^= 1;
			waiting_threads_counts[current_counter] = 0;

			enif_cond_broadcast(cond);
		}

	//	std::cerr << "await(): END" <<endl;
		enif_mutex_unlock(mtx);
	}

};

/*array must be big enough to contain list.length elements*/
uint list_to_double_arrayN(ErlNifEnv *env, ERL_NIF_TERM list, double* array, uint arrayLen, ERL_NIF_TERM* lastListCell) {

	if(array == NULL)
		return 0;

	uint len = 0;

	if(enif_is_list(env, list)) {

		ERL_NIF_TERM curr_cell = list;

		uint i = 0;
		for(i = 0; enif_is_list(env, curr_cell) && i < arrayLen; i++) {

			ERL_NIF_TERM hd, tl;
			if(!enif_get_list_cell(env, curr_cell, &hd, &tl))
				break;//list is empty

			if(!(enif_get_double(env, hd, &(array[i]) ))) {
				std::cerr << "DEBUG: list_to_double_arrayN - Error: attempt to read float from something else!" << std::endl;
			}
			curr_cell = tl;

		}

		if(lastListCell != NULL) //user requested the term denoting the last cell
			*lastListCell = curr_cell;

		return i;

	} else { //term "list" is not a list

		#ifdef DEBUG
		std::cerr << "DEBUG: list_to_double_arrayN - Error: trying to convert a non list as a list"<< std::endl ;
		#endif

		return 0;
	}
}

uint sync_list_to_double_arrayN(ErlNifEnv *env, ErlNifMutex *mtx, ERL_NIF_TERM list, double* array, uint arrayLen, ERL_NIF_TERM* lastListCell) {

	enif_mutex_lock(mtx);

	uint result = list_to_double_arrayN(env, list, array,  arrayLen, lastListCell);

	enif_mutex_unlock(mtx);

	return result;

}

void list_to_double_array(ErlNifEnv *env, ERL_NIF_TERM list, uint listLen, double* array) { //TODO scorre la lista 2 volte

	if(array == NULL)
		return;

	uint len = 0;

	if(enif_is_list(env, list)) {

		list_to_double_arrayN(env, list, array, listLen, NULL);
	}

}

ERL_NIF_TERM double_array_to_list(ErlNifEnv *env, double* array, size_t array_size) {

	if(array == NULL)
		return ATOM(error);

	ERL_NIF_TERM* floatTermArray =
			(ERL_NIF_TERM*) enif_alloc(sizeof(ERL_NIF_TERM) * array_size);

	for(uint i = 0; i < array_size; i++)
		floatTermArray[i] = enif_make_double(env, array[i]);

	ERL_NIF_TERM res = enif_make_list_from_array(env, floatTermArray, array_size);

	enif_free(floatTermArray);

	return res;
}

/*returns a string containing the content of the file at filePath
 * otherwise "NULL".*/
string readFromFileStr(char* filePath) {

	ifstream file(filePath, ios::in);
	if (!file.is_open()) {
		cerr << "Failed to open file for reading: " << filePath << endl;
		return "NULL";
	}

	ostringstream oss;
	oss << file.rdbuf();

	return oss.str();
}

/*returns a dinamically allocated string containing the content of the file at filePath
 * otherwise NULL.
 * The returned sting must be enif_free'd when not needed.
 * */
char* readFromFile(char* filePath) {

	string srcStdStr = readFromFileStr(filePath);

	char* toReturn = (char*) enif_alloc(srcStdStr.length()+1);

	return strcpy(toReturn, srcStdStr.c_str());

}

#define MIN(a, b) ((a < b) ? a : b)

int inline isPow2(unsigned int v) { return v && !(v & (v - 1));}

/*
 * Return a value that is nearest value that is power of 2.
 */
unsigned int nextPow2( unsigned int x )
{
    --x;
    x |= x >> 1;
    x |= x >> 2;
    x |= x >> 4;
    x |= x >> 8;
    x |= x >> 16;
    return x+1;
}

// Round Up Division function
size_t roundUp(uint group_size, uint global_size)
{
    uint r = global_size % group_size;
    if(r == 0)
        return global_size;
    else
        return global_size + group_size - r;
}

/*!
 * Compute the number of threads and blocks to use for the REDUCTION kernel.
 * We set threads / block to the minimum of maxThreads and n/2 where n is
 * problem size. We observe the maximum specified number of blocks, because
 * each kernel thread can process more than 1 elements.
 *
 * \param n Problem size.
 * \param maxBlocks Maximum number of blocks that can be used.
 * \param maxThreads Maximum number of threads that can be used.
 * \param blocks An output parameter passed by reference. Specify number of blocks to be used.
 * \param threads An output parameter passed by reference. Specify number of threads to be used.
 */
void getNumBlocksAndThreads(int n, int maxBlocks, int maxThreads, long unsigned int &blocks, long unsigned int &threads)
{
        threads = (n < maxThreads*2) ? nextPow2((n + 1)/ 2) : maxThreads;
        blocks = (n + (threads * 2 - 1)) / (threads * 2);

        if(maxBlocks > 0)
        	blocks = MIN(maxBlocks, blocks);
}

/*
 *  It finds all instances of a string in another string and replaces it with
 *  a third string.
 *
 */
void replaceTextInString(std::string& text, std::string find, std::string replace)
{
        std::string::size_type pos=0;
        while((pos = text.find(find, pos)) != std::string::npos)
        {
            text.erase(pos, find.length());
            text.insert(pos, replace);
            pos+=replace.length();
        }
}

<|endoftext|>


<commit_before>/*
Copyright (C) 2016-2020 Rodrigo Jose Hernandez Cordoba

Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <QFileDialog>
#include <QMdiSubWindow>
#include <QSurfaceFormat>
#include "aeongames/Renderer.h"
#include "WorldEditor.h"
#include "MainWindow.h"
#include "SceneWindow.h"
#include "EngineWindow.h"
#include "CameraSettings.h"

namespace AeonGames
{
    MainWindow::MainWindow() : QMainWindow(), Ui::MainWindow()
    {
        setupUi ( this );
        QSurfaceFormat surface_format = QSurfaceFormat::defaultFormat();
        surface_format.setDepthBufferSize ( 24 );
        surface_format.setSwapBehavior ( QSurfaceFormat::DoubleBuffer );
        QSurfaceFormat::setDefaultFormat ( surface_format );
        mCameraSettings = new CameraSettings ( this );
        connect ( mCameraSettings, SIGNAL ( fieldOfViewChanged ( double ) ), this, SLOT ( fieldOfViewChanged ( double ) ) );
        connect ( mCameraSettings, SIGNAL ( nearChanged ( double ) ), this, SLOT ( nearChanged ( double ) ) );
        connect ( mCameraSettings, SIGNAL ( farChanged ( double ) ), this, SLOT ( farChanged ( double ) ) );
    }

    MainWindow::~MainWindow()
    {
        disconnect();
        mCameraSettings->disconnect();
        mCameraSettings->deleteLater();
    }

    void MainWindow::on_actionExit_triggered()
    {
        mdiArea->closeAllSubWindows();
        for ( auto* i : mdiArea->subWindowList() )
        {
            delete i;
        }
        close();
    }

    void MainWindow::on_actionNew_triggered()
    {
        SceneWindow* sceneWindow;
        QMdiSubWindow*
        mdiSubWindow = mdiArea->addSubWindow ( sceneWindow = new SceneWindow ( mdiArea ) );
        mdiSubWindow->setAttribute ( Qt::WA_DeleteOnClose );
        mdiSubWindow->setWindowTitle ( tr ( "Untitled Scene" ) );
        mdiSubWindow->showMaximized();
        mdiSubWindow->setMinimumSize ( QSize ( 128, 128 ) );
        actionSave->setEnabled ( true );
    }

    void MainWindow::on_actionOpen_triggered()
    {
        QString filename = QFileDialog::getOpenFileName ( this,
                           tr ( "Open Scene" ),
                           tr ( "" ),
                           tr ( "Scene Files (*.scn *.txt)" ) );

        if ( ! ( filename.isEmpty() || filename.isNull() ) )
        {
            QFileInfo fileinfo ( filename );
            SceneWindow* sceneWindow;
            QMdiSubWindow*
            mdiSubWindow = mdiArea->addSubWindow ( sceneWindow = new SceneWindow ( mdiArea ) );
            mdiSubWindow->setAttribute ( Qt::WA_DeleteOnClose );
            mdiSubWindow->setWindowTitle ( fileinfo.absoluteFilePath() );
            mdiSubWindow->showMaximized();
            mdiSubWindow->setMinimumSize ( QSize ( 128, 128 ) );
            sceneWindow->Open ( fileinfo.absoluteFilePath().toStdString() );
            /** @todo handle open failure. */
            actionSave->setEnabled ( true );
        }
    }

    void MainWindow::on_actionSave_triggered()
    {
        QMdiSubWindow*
        mdiSubWindow = mdiArea->currentSubWindow ();
        if ( !mdiSubWindow )
        {
            return;
        }
        QString filename = QFileDialog::getSaveFileName ( this,
                           tr ( "Save Scene" ),
                           tr ( "" ),
                           tr ( "Scene Files (*.scn *.txt)" ) );
        if ( ! ( filename.isEmpty() || filename.isNull() ) )
        {
            SceneWindow* sceneWindow = reinterpret_cast<SceneWindow*> ( mdiSubWindow->widget() );
            if ( sceneWindow )
            {
                sceneWindow->Save ( filename.toStdString() );
            }
        }
    }

    void MainWindow::on_actionCamera_triggered()
    {
        mCameraSettings->show();
    }

    void MainWindow::fieldOfViewChanged ( double aFieldOfView )
    {
        QMdiSubWindow*
        mdiSubWindow = mdiArea->currentSubWindow ();
        if ( !mdiSubWindow )
        {
            return;
        }
        reinterpret_cast<SceneWindow*> ( mdiSubWindow->widget() )->SetFieldOfView ( static_cast<float> ( aFieldOfView ) );
    }

    void MainWindow::nearChanged ( double aNear )
    {
        QMdiSubWindow*
        mdiSubWindow = mdiArea->currentSubWindow ();
        if ( !mdiSubWindow )
        {
            return;
        }
        reinterpret_cast<SceneWindow*> ( mdiSubWindow->widget() )->SetNear ( static_cast<float> ( aNear ) );
    }

    void MainWindow::farChanged ( double aFar )
    {
        QMdiSubWindow*
        mdiSubWindow = mdiArea->currentSubWindow ();
        if ( !mdiSubWindow )
        {
            return;
        }
        reinterpret_cast<SceneWindow*> ( mdiSubWindow->widget() )->SetFar ( static_cast<float> ( aFar ) );
    }
}
<commit_msg>Added more detailed setup for Qt's surface format.<commit_after>/*
Copyright (C) 2016-2021 Rodrigo Jose Hernandez Cordoba

Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <QFileDialog>
#include <QMdiSubWindow>
#include <QSurfaceFormat>
#include "aeongames/Renderer.h"
#include "WorldEditor.h"
#include "MainWindow.h"
#include "SceneWindow.h"
#include "EngineWindow.h"
#include "CameraSettings.h"

namespace AeonGames
{
    MainWindow::MainWindow() : QMainWindow(), Ui::MainWindow()
    {
        setupUi ( this );
        QSurfaceFormat surface_format = QSurfaceFormat::defaultFormat();

        surface_format.setColorSpace ( QSurfaceFormat::sRGBColorSpace );
        surface_format.setRenderableType ( QSurfaceFormat::OpenGL );
        surface_format.setSwapBehavior ( QSurfaceFormat::DoubleBuffer );
        surface_format.setRedBufferSize ( 8 );
        surface_format.setGreenBufferSize ( 8 );
        surface_format.setBlueBufferSize ( 8 );
        surface_format.setAlphaBufferSize ( 8 );
        surface_format.setStencilBufferSize ( 8 );
        surface_format.setDepthBufferSize ( 24 );
        //surface_format.setSamples ( ? ); ///@< Find out what is a sensible value for multisampling
        QSurfaceFormat::setDefaultFormat ( surface_format );
        mCameraSettings = new CameraSettings ( this );
        connect ( mCameraSettings, SIGNAL ( fieldOfViewChanged ( double ) ), this, SLOT ( fieldOfViewChanged ( double ) ) );
        connect ( mCameraSettings, SIGNAL ( nearChanged ( double ) ), this, SLOT ( nearChanged ( double ) ) );
        connect ( mCameraSettings, SIGNAL ( farChanged ( double ) ), this, SLOT ( farChanged ( double ) ) );
    }

    MainWindow::~MainWindow()
    {
        disconnect();
        mCameraSettings->disconnect();
        mCameraSettings->deleteLater();
    }

    void MainWindow::on_actionExit_triggered()
    {
        mdiArea->closeAllSubWindows();
        for ( auto* i : mdiArea->subWindowList() )
        {
            delete i;
        }
        close();
    }

    void MainWindow::on_actionNew_triggered()
    {
        SceneWindow* sceneWindow;
        QMdiSubWindow*
        mdiSubWindow = mdiArea->addSubWindow ( sceneWindow = new SceneWindow ( mdiArea ) );
        mdiSubWindow->setAttribute ( Qt::WA_DeleteOnClose );
        mdiSubWindow->setWindowTitle ( tr ( "Untitled Scene" ) );
        mdiSubWindow->showMaximized();
        mdiSubWindow->setMinimumSize ( QSize ( 128, 128 ) );
        actionSave->setEnabled ( true );
    }

    void MainWindow::on_actionOpen_triggered()
    {
        QString filename = QFileDialog::getOpenFileName ( this,
                           tr ( "Open Scene" ),
                           tr ( "" ),
                           tr ( "Scene Files (*.scn *.txt)" ) );

        if ( ! ( filename.isEmpty() || filename.isNull() ) )
        {
            QFileInfo fileinfo ( filename );
            SceneWindow* sceneWindow;
            QMdiSubWindow*
            mdiSubWindow = mdiArea->addSubWindow ( sceneWindow = new SceneWindow ( mdiArea ) );
            mdiSubWindow->setAttribute ( Qt::WA_DeleteOnClose );
            mdiSubWindow->setWindowTitle ( fileinfo.absoluteFilePath() );
            mdiSubWindow->showMaximized();
            mdiSubWindow->setMinimumSize ( QSize ( 128, 128 ) );
            sceneWindow->Open ( fileinfo.absoluteFilePath().toStdString() );
            /** @todo handle open failure. */
            actionSave->setEnabled ( true );
        }
    }

    void MainWindow::on_actionSave_triggered()
    {
        QMdiSubWindow*
        mdiSubWindow = mdiArea->currentSubWindow ();
        if ( !mdiSubWindow )
        {
            return;
        }
        QString filename = QFileDialog::getSaveFileName ( this,
                           tr ( "Save Scene" ),
                           tr ( "" ),
                           tr ( "Scene Files (*.scn *.txt)" ) );
        if ( ! ( filename.isEmpty() || filename.isNull() ) )
        {
            SceneWindow* sceneWindow = reinterpret_cast<SceneWindow*> ( mdiSubWindow->widget() );
            if ( sceneWindow )
            {
                sceneWindow->Save ( filename.toStdString() );
            }
        }
    }

    void MainWindow::on_actionCamera_triggered()
    {
        mCameraSettings->show();
    }

    void MainWindow::fieldOfViewChanged ( double aFieldOfView )
    {
        QMdiSubWindow*
        mdiSubWindow = mdiArea->currentSubWindow ();
        if ( !mdiSubWindow )
        {
            return;
        }
        reinterpret_cast<SceneWindow*> ( mdiSubWindow->widget() )->SetFieldOfView ( static_cast<float> ( aFieldOfView ) );
    }

    void MainWindow::nearChanged ( double aNear )
    {
        QMdiSubWindow*
        mdiSubWindow = mdiArea->currentSubWindow ();
        if ( !mdiSubWindow )
        {
            return;
        }
        reinterpret_cast<SceneWindow*> ( mdiSubWindow->widget() )->SetNear ( static_cast<float> ( aNear ) );
    }

    void MainWindow::farChanged ( double aFar )
    {
        QMdiSubWindow*
        mdiSubWindow = mdiArea->currentSubWindow ();
        if ( !mdiSubWindow )
        {
            return;
        }
        reinterpret_cast<SceneWindow*> ( mdiSubWindow->widget() )->SetFar ( static_cast<float> ( aFar ) );
    }
}
<|endoftext|>


<commit_before><commit_msg>phastaIO: use high resolution timers<commit_after><|endoftext|>


<commit_before>//functor_overload header
//Copyright (c) 2014 mmYYmmdd

#if !defined MMYYMMDD_FUNCTOR_OVERLOAD_INCLUDED
#define MMYYMMDD_FUNCTOR_OVERLOAD_INCLUDED

#include <type_traits>

namespace mymd {

	namespace detail_fo	{

		template <typename>
		struct noCondition	{
			static constexpr bool value = true;
		};

		template <template <typename> class C = noCondition, bool B = true>
		struct cond	{ };
		//-----------------------------------------------------
		template <typename...>
		struct types  { };
		//-----------------------------------------------------
		template <typename T, typename>
		struct arg  {
			using apply = std::enable_if<true, T>;
		};

		template <template <typename> class C, bool B, typename V>
		struct arg<cond<C, B>, V>  {
			using apply = std::enable_if<B == C<V>::value, V>;
		};
		//-----------------------------------------------------
		struct no_action	{
			constexpr no_action() { }
			template <typename... V>
			void operator ()(V&&...) const {}
		};
		//-----------------------------------------------------
		template <typename F, typename... A>
		class bolt  {
			F fn;
			template <typename T, typename U>	//workaround for VC
			using apply = typename arg<T, U>::apply;
		protected:
			template <typename... V>
			auto invoke(types<V...>, typename arg<A, V>::apply::type&&... a) const
				->decltype(fn(std::declval<typename apply<A, V>::type>()...))
				{  return fn(std::forward<typename apply<A, V>::type>(a) ...);  }
			template <typename... V>
			auto invoke(types<V...>, typename arg<A, V>::apply::type&&... a)
				->decltype(fn(std::declval<typename apply<A, V>::type>()...))
				{  return fn(std::forward<typename apply<A, V>::type>(a) ...);  }
		public:
			constexpr bolt(const F& f) : fn(f)  {  }
		};
		//-----------------------------------------------------
		template <typename T1, typename T2>
		struct bolts : private T1, private T2  {
			using T1::operator ();
			using T2::operator ();
			constexpr bolts(const T1& t1, const T2& t2) : T1(t1), T2(t2) { }
		};

		template <typename F, typename... A>
		class bolts<bolt<F, A...>, void> : private bolt<F, A...>  {
			using bolt<F, A...>::invoke;
		public:
			constexpr bolts(const F& t) : bolt<F, A...>(t) { }
			template <typename... V>
			auto operator()(V&&... v) const->decltype(invoke(types<V...>{}, std::declval<V>()...))
				{  return invoke(types<V...>{}, std::forward<V>(v)...);  }
			template <typename... V>
			auto operator()(V&&... v) ->decltype(invoke(types<V...>{}, std::declval<V>()...))
				{  return invoke(types<V...>{}, std::forward<V>(v)...);  }
		};

		template <typename T1, typename T2, typename U1, typename U2>
		auto operator +(bolts<T1, T2> const& b, bolts<U1, U2> const& c) ->bolts<bolts<T1, T2>, bolts<U1, U2>>
		{
			return bolts<bolts<T1, T2>, bolts<U1, U2>>(b, c);
		}
		//-----------------------------------------------------
		template <typename F, typename... A>
		using gen_t = bolts<bolt<typename std::conditional<std::is_same<F, void>::value, no_action, F>::type, A...>, void>;

	}	//namespace detail_fo
	//********************************************************************
	//  user interfaces are ,
	//  mymd::gen<A, B, C...>(Fn)  ,  mymd::cond<P>  ,  operator +
	//********************************************************************
	using detail_fo::cond;		//  condition for type
	using detail_fo::bolts;		//  functor type
	using detail_fo::gen_t;		//  functor type generated by 'gen'

	template <typename... A, typename F>
	auto gen(const F& f) ->gen_t<F, A...>
	{	return gen_t<F, A...>(f);	}

	//no action
	template <typename... A>
	auto gen() ->gen_t<void, A...>
	{	return gen_t<void, A...>(detail_fo::no_action{});	}

}	//namespace mymd

namespace mymd {
	//----------------------------------
	//template <typename T>
	//using is_xxx = mymd::is_some_rr<std::is_yyyy, std::is_zzzz>::apply<T>;
	//using is_xxx = mymd::is_every_rr<std::is_yyyy, std::is_zzzz>::apply<T>;

	template <template <typename> class first, template <typename> class... tail>
	struct is_some_rr	{
		template <typename T>
		struct apply	{
			using T2 = typename std::remove_reference<T>::type;
			static constexpr bool value = first<T2>::value || is_some_rr<tail...>::template apply<T>::value;
		};
	};

	template <template <typename> class first>
	struct is_some_rr<first>	{
		template <typename T>
		struct apply	{
			using T2 = typename std::remove_reference<T>::type;
			static constexpr bool value = first<T2>::value;
		};
	};

	template <template <typename> class first, template <typename> class... tail>
	struct is_every_rr	{
		template <typename T>
		struct apply	{
			using T2 = typename std::remove_reference<T>::type;
			static constexpr bool value = first<T2>::value && is_every_rr<tail...>::template apply<T>::value;
		};
	};

	template <template <typename> class first>
	struct is_every_rr<first>	{
		template <typename T>
		struct apply	{
			using T2 = typename std::remove_reference<T>::type;
			static constexpr bool value = first<T2>::value;
		};
	};
}	//namespace mymd

#endif
<commit_msg>is_some_rr と is_every_rr を削除<commit_after>//functor_overload header
//Copyright (c) 2014 mmYYmmdd

#if !defined MMYYMMDD_FUNCTOR_OVERLOAD_INCLUDED
#define MMYYMMDD_FUNCTOR_OVERLOAD_INCLUDED

#include <type_traits>

namespace mymd {

	namespace detail_fol	{

		template <typename>
		struct noCondition	{
			static constexpr bool value = true;
		};

		template <template <typename> class C = noCondition, bool B = true>
		struct cond	{ };
		//-----------------------------------------------------
		template <typename...>
		struct types  { };
		//-----------------------------------------------------
		template <typename T, typename>
		struct arg  {
			using apply = std::enable_if<true, T>;
		};

		template <template <typename> class C, bool B, typename V>
		struct arg<cond<C, B>, V>  {
			using apply = std::enable_if<B == C<V>::value, V>;
		};
		//-----------------------------------------------------
		struct no_action	{
			constexpr no_action() { }
			template <typename... V>
			void operator ()(V&&...) const {}
		};
		//-----------------------------------------------------
		template <typename F, typename... A>
		class bolt  {
			F fn;
			template <typename T, typename U>	//workaround for VC
			using apply = typename arg<T, U>::apply;
		protected:
			template <typename... V>
			auto invoke(types<V...>, typename arg<A, V>::apply::type&&... a) const
				->decltype(fn(std::declval<typename apply<A, V>::type>()...))
				{  return fn(std::forward<typename apply<A, V>::type>(a) ...);  }
			template <typename... V>
			auto invoke(types<V...>, typename arg<A, V>::apply::type&&... a)
				->decltype(fn(std::declval<typename apply<A, V>::type>()...))
				{  return fn(std::forward<typename apply<A, V>::type>(a) ...);  }
		public:
			constexpr bolt(const F& f) : fn(f)  {  }
		};
		//-----------------------------------------------------
		template <typename T1, typename T2>
		struct bolts : private T1, private T2  {
			using T1::operator ();
			using T2::operator ();
			constexpr bolts(const T1& t1, const T2& t2) : T1(t1), T2(t2) { }
		};

		template <typename F, typename... A>
		class bolts<bolt<F, A...>, void> : private bolt<F, A...>  {
			using bolt<F, A...>::invoke;
		public:
			constexpr bolts(const F& t) : bolt<F, A...>(t) { }
			template <typename... V>
			auto operator()(V&&... v) const->decltype(invoke(types<V...>{}, std::declval<V>()...))
				{  return invoke(types<V...>{}, std::forward<V>(v)...);  }
			template <typename... V>
			auto operator()(V&&... v) ->decltype(invoke(types<V...>{}, std::declval<V>()...))
				{  return invoke(types<V...>{}, std::forward<V>(v)...);  }
		};

		template <typename T1, typename T2, typename U1, typename U2>
		auto operator +(bolts<T1, T2> const& b, bolts<U1, U2> const& c) ->bolts<bolts<T1, T2>, bolts<U1, U2>>
		{
			return bolts<bolts<T1, T2>, bolts<U1, U2>>(b, c);
		}
		//-----------------------------------------------------
		template <typename F, typename... A>
		using gen_t = bolts<bolt<typename std::conditional<std::is_same<F, void>::value, no_action, F>::type, A...>, void>;

	}	//namespace detail_fol
	//********************************************************************
	//  user interfaces are ,
	//  mymd::gen<A, B, C...>(Fn)  ,  mymd::cond<P>  ,  operator +
	//********************************************************************
	using detail_fol::cond;		//  condition for type
	using detail_fol::bolts;		//  functor type
	using detail_fol::gen_t;		//  functor type generated by 'gen'

	template <typename... A, typename F>
	auto gen(const F& f) ->gen_t<F, A...>
	{	return gen_t<F, A...>(f);	}

	//no action
	template <typename... A>
	auto gen() ->gen_t<void, A...>
	{	return gen_t<void, A...>(detail_fol::no_action{});	}

}	//namespace mymd

#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: composerdialogs.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: obo $ $Date: 2006-01-19 15:45:45 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef DBACCESS_SOURCE_UI_UNO_COMPOSERDIALOGS_HXX
#include "composerdialogs.hxx"
#endif

/** === begin UNO includes === **/
#ifndef _DBU_REGHELPER_HXX_
#include "dbu_reghelper.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#endif
/** === end UNO includes === **/
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef DBAUI_QUERYFILTER_HXX
#include "queryfilter.hxx"
#endif
#ifndef DBAUI_QUERYORDER_HXX
#include "queryorder.hxx"
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif

extern "C" void SAL_CALL createRegistryInfo_ComposerDialogs()
{
    static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::RowsetOrderDialog > aOrderDialogRegistration;
    static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::RowsetFilterDialog > aFilterDialogRegistration;
}

//.........................................................................
namespace dbaui
{
//.........................................................................

#define PROPERTY_ID_QUERYCOMPOSER       100
#define PROPERTY_ID_ROWSET              101

    IMPLEMENT_CONSTASCII_USTRING( PROPERTY_QUERYCOMPOSER,   "QueryComposer" );
    IMPLEMENT_CONSTASCII_USTRING( PROPERTY_ROWSET,          "RowSet" );

    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;
    using namespace ::com::sun::star::container;
    using namespace ::com::sun::star::sdbcx;
    using namespace ::com::sun::star::sdbc;
    using namespace ::com::sun::star::sdb;

    //=====================================================================
    //= ComposerDialog
    //=====================================================================
DBG_NAME(ComposerDialog)
//---------------------------------------------------------------------
    ComposerDialog::ComposerDialog(const Reference< XMultiServiceFactory >& _rxORB)
        :ComposerDialog_BASE( _rxORB )
    {
        DBG_CTOR(ComposerDialog,NULL);

        registerProperty( PROPERTY_QUERYCOMPOSER, PROPERTY_ID_QUERYCOMPOSER, PropertyAttribute::TRANSIENT,
            &m_xComposer, ::getCppuType( &m_xComposer ) );
        registerProperty( PROPERTY_ROWSET, PROPERTY_ID_ROWSET, PropertyAttribute::TRANSIENT,
            &m_xRowSet, ::getCppuType( &m_xRowSet ) );
    }

    //---------------------------------------------------------------------
    ComposerDialog::~ComposerDialog()
    {

        DBG_DTOR(ComposerDialog,NULL);
    }

    //---------------------------------------------------------------------
    IMPLEMENT_IMPLEMENTATION_ID( ComposerDialog )

    //---------------------------------------------------------------------
    IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ComposerDialog )

    //---------------------------------------------------------------------
    Dialog* ComposerDialog::createDialog(Window* _pParent)
    {
        // obtain all the objects needed for the dialog
        Reference< XConnection > xConnection;
        Reference< XNameAccess > xColumns;
        try
        {
            // the connection the row set is working with
            if ( !::dbtools::isEmbeddedInDatabase( m_xRowSet, xConnection ) )
            {
                Reference< XPropertySet > xRowsetProps( m_xRowSet, UNO_QUERY );
                if ( xRowsetProps.is() )
                    xRowsetProps->getPropertyValue( PROPERTY_ACTIVECONNECTION ) >>= xConnection;
            }

            // fallback: if there is a connection and thus a row set, but no composer, create one
            if ( xConnection.is() && !m_xComposer.is() )
                m_xComposer = ::dbtools::getCurrentSettingsComposer( Reference< XPropertySet >( m_xRowSet, UNO_QUERY ), m_xORB );

            // the columns of the row set
            Reference< XColumnsSupplier > xSuppColumns( m_xRowSet, UNO_QUERY );
            if ( xSuppColumns.is() )
                xColumns = xSuppColumns->getColumns();

            if ( !xColumns.is() || !xColumns->hasElements() )
            {   // perhaps the composer can supply us with columns? This is necessary for cases
                // where the dialog is invoked for a rowset which is not yet loaded
                // #i22878# - 2003-12-16 - fs@openoffice.org
                xSuppColumns = xSuppColumns.query( m_xComposer );
                if ( xSuppColumns.is() )
                    xColumns = xSuppColumns->getColumns();
            }

            DBG_ASSERT( xColumns.is() && xColumns->hasElements(), "ComposerDialog::createDialog: not much fun without any columns!" );
        }
        catch( const Exception& )
        {
            OSL_ENSURE( sal_False, "ComposerDialog::createDialog: caught an exception!" );
        }

        if ( !xConnection.is() || !xColumns.is() || !m_xComposer.is() )
            // can't create the dialog if I have improper settings
            return NULL;

        return createComposerDialog( _pParent, xConnection, xColumns );
    }

    //=====================================================================
    //= RowsetFilterDialog
    //=====================================================================
    //---------------------------------------------------------------------
    RowsetFilterDialog::RowsetFilterDialog( const Reference< XMultiServiceFactory >& _rxORB )
        :ComposerDialog( _rxORB )
    {
    }

    //---------------------------------------------------------------------
    IMPLEMENT_SERVICE_INFO1_STATIC( RowsetFilterDialog, "com.sun.star.uno.comp.sdb.RowsetFilterDialog", "com.sun.star.sdb.FilterDialog" )

    //---------------------------------------------------------------------
    Dialog* RowsetFilterDialog::createComposerDialog( Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
    {
        return new DlgFilterCrit( _pParent, m_xORB, _rxConnection, m_xComposer, _rxColumns );
    }

    //---------------------------------------------------------------------
    void RowsetFilterDialog::executedDialog( sal_Int16 _nExecutionResult )
    {
        ComposerDialog::executedDialog( _nExecutionResult );

        if ( _nExecutionResult && m_pDialog )
            static_cast< DlgFilterCrit* >( m_pDialog )->BuildWherePart();
    }

    //=====================================================================
    //= RowsetOrderDialog
    //=====================================================================
    //---------------------------------------------------------------------
    RowsetOrderDialog::RowsetOrderDialog( const Reference< XMultiServiceFactory >& _rxORB )
        :ComposerDialog( _rxORB )
    {
    }

    //---------------------------------------------------------------------
    IMPLEMENT_SERVICE_INFO1_STATIC( RowsetOrderDialog, "com.sun.star.uno.comp.sdb.RowsetOrderDialog", "com.sun.star.sdb.OrderDialog" )

    //---------------------------------------------------------------------
    Dialog* RowsetOrderDialog::createComposerDialog( Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
    {
        return new DlgOrderCrit( _pParent, _rxConnection, m_xComposer, _rxColumns );
    }

    //---------------------------------------------------------------------
    void RowsetOrderDialog::executedDialog( sal_Int16 _nExecutionResult )
    {
        ComposerDialog::executedDialog( _nExecutionResult );

        if ( !m_pDialog )
            return;

        if ( _nExecutionResult )
            static_cast< DlgOrderCrit* >( m_pDialog )->BuildOrderPart();
        else if ( m_xComposer.is() )
            m_xComposer->setOrder( static_cast< DlgOrderCrit* >( m_pDialog )->GetOrignalOrder() );
    }

//.........................................................................
}   // namespace dbaui
//.........................................................................

<commit_msg>INTEGRATION: CWS dba203b (1.6.44); FILE MERGED 2006/03/27 14:11:35 fs 1.6.44.1: #i63439# correct parsing of existing sort order<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: composerdialogs.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: vg $ $Date: 2006-03-31 12:16:16 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef DBACCESS_SOURCE_UI_UNO_COMPOSERDIALOGS_HXX
#include "composerdialogs.hxx"
#endif

/** === begin UNO includes === **/
#ifndef _DBU_REGHELPER_HXX_
#include "dbu_reghelper.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#endif
/** === end UNO includes === **/
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef DBAUI_QUERYFILTER_HXX
#include "queryfilter.hxx"
#endif
#ifndef DBAUI_QUERYORDER_HXX
#include "queryorder.hxx"
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif

extern "C" void SAL_CALL createRegistryInfo_ComposerDialogs()
{
    static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::RowsetOrderDialog > aOrderDialogRegistration;
    static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::RowsetFilterDialog > aFilterDialogRegistration;
}

//.........................................................................
namespace dbaui
{
//.........................................................................

#define PROPERTY_ID_QUERYCOMPOSER       100
#define PROPERTY_ID_ROWSET              101

    IMPLEMENT_CONSTASCII_USTRING( PROPERTY_QUERYCOMPOSER,   "QueryComposer" );
    IMPLEMENT_CONSTASCII_USTRING( PROPERTY_ROWSET,          "RowSet" );

    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;
    using namespace ::com::sun::star::container;
    using namespace ::com::sun::star::sdbcx;
    using namespace ::com::sun::star::sdbc;
    using namespace ::com::sun::star::sdb;

    //=====================================================================
    //= ComposerDialog
    //=====================================================================
    DBG_NAME(ComposerDialog)
    //---------------------------------------------------------------------
    ComposerDialog::ComposerDialog(const Reference< XMultiServiceFactory >& _rxORB)
        :ComposerDialog_BASE( _rxORB )
    {
        DBG_CTOR(ComposerDialog,NULL);

        registerProperty( PROPERTY_QUERYCOMPOSER, PROPERTY_ID_QUERYCOMPOSER, PropertyAttribute::TRANSIENT,
            &m_xComposer, ::getCppuType( &m_xComposer ) );
        registerProperty( PROPERTY_ROWSET, PROPERTY_ID_ROWSET, PropertyAttribute::TRANSIENT,
            &m_xRowSet, ::getCppuType( &m_xRowSet ) );
    }

    //---------------------------------------------------------------------
    ComposerDialog::~ComposerDialog()
    {

        DBG_DTOR(ComposerDialog,NULL);
    }

    //---------------------------------------------------------------------
    IMPLEMENT_IMPLEMENTATION_ID( ComposerDialog )

    //---------------------------------------------------------------------
    IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ComposerDialog )

    //---------------------------------------------------------------------
    Dialog* ComposerDialog::createDialog(Window* _pParent)
    {
        // obtain all the objects needed for the dialog
        Reference< XConnection > xConnection;
        Reference< XNameAccess > xColumns;
        try
        {
            // the connection the row set is working with
            if ( !::dbtools::isEmbeddedInDatabase( m_xRowSet, xConnection ) )
            {
                Reference< XPropertySet > xRowsetProps( m_xRowSet, UNO_QUERY );
                if ( xRowsetProps.is() )
                    xRowsetProps->getPropertyValue( PROPERTY_ACTIVECONNECTION ) >>= xConnection;
            }

            // fallback: if there is a connection and thus a row set, but no composer, create one
            if ( xConnection.is() && !m_xComposer.is() )
                m_xComposer = ::dbtools::getCurrentSettingsComposer( Reference< XPropertySet >( m_xRowSet, UNO_QUERY ), m_xORB );

            // the columns of the row set
            Reference< XColumnsSupplier > xSuppColumns( m_xRowSet, UNO_QUERY );
            if ( xSuppColumns.is() )
                xColumns = xSuppColumns->getColumns();

            if ( !xColumns.is() || !xColumns->hasElements() )
            {   // perhaps the composer can supply us with columns? This is necessary for cases
                // where the dialog is invoked for a rowset which is not yet loaded
                // #i22878# - 2003-12-16 - fs@openoffice.org
                xSuppColumns = xSuppColumns.query( m_xComposer );
                if ( xSuppColumns.is() )
                    xColumns = xSuppColumns->getColumns();
            }

            DBG_ASSERT( xColumns.is() && xColumns->hasElements(), "ComposerDialog::createDialog: not much fun without any columns!" );
        }
        catch( const Exception& )
        {
            OSL_ENSURE( sal_False, "ComposerDialog::createDialog: caught an exception!" );
        }

        if ( !xConnection.is() || !xColumns.is() || !m_xComposer.is() )
            // can't create the dialog if I have improper settings
            return NULL;

        return createComposerDialog( _pParent, xConnection, xColumns );
    }

    //=====================================================================
    //= RowsetFilterDialog
    //=====================================================================
    //---------------------------------------------------------------------
    RowsetFilterDialog::RowsetFilterDialog( const Reference< XMultiServiceFactory >& _rxORB )
        :ComposerDialog( _rxORB )
    {
    }

    //---------------------------------------------------------------------
    IMPLEMENT_SERVICE_INFO1_STATIC( RowsetFilterDialog, "com.sun.star.uno.comp.sdb.RowsetFilterDialog", "com.sun.star.sdb.FilterDialog" )

    //---------------------------------------------------------------------
    Dialog* RowsetFilterDialog::createComposerDialog( Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
    {
        return new DlgFilterCrit( _pParent, m_xORB, _rxConnection, m_xComposer, _rxColumns );
    }

    //---------------------------------------------------------------------
    void RowsetFilterDialog::executedDialog( sal_Int16 _nExecutionResult )
    {
        ComposerDialog::executedDialog( _nExecutionResult );

        if ( _nExecutionResult && m_pDialog )
            static_cast< DlgFilterCrit* >( m_pDialog )->BuildWherePart();
    }

    //=====================================================================
    //= RowsetOrderDialog
    //=====================================================================
    //---------------------------------------------------------------------
    RowsetOrderDialog::RowsetOrderDialog( const Reference< XMultiServiceFactory >& _rxORB )
        :ComposerDialog( _rxORB )
    {
    }

    //---------------------------------------------------------------------
    IMPLEMENT_SERVICE_INFO1_STATIC( RowsetOrderDialog, "com.sun.star.uno.comp.sdb.RowsetOrderDialog", "com.sun.star.sdb.OrderDialog" )

    //---------------------------------------------------------------------
    Dialog* RowsetOrderDialog::createComposerDialog( Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
    {
        return new DlgOrderCrit( _pParent, _rxConnection, m_xComposer, _rxColumns );
    }

    //---------------------------------------------------------------------
    void RowsetOrderDialog::executedDialog( sal_Int16 _nExecutionResult )
    {
        ComposerDialog::executedDialog( _nExecutionResult );

        if ( !m_pDialog )
            return;

        if ( _nExecutionResult )
            static_cast< DlgOrderCrit* >( m_pDialog )->BuildOrderPart();
        else if ( m_xComposer.is() )
            m_xComposer->setOrder( static_cast< DlgOrderCrit* >( m_pDialog )->GetOrignalOrder() );
    }

//.........................................................................
}   // namespace dbaui
//.........................................................................

<|endoftext|>


<commit_before>//----------------------------------------------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 2001, 2002 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//----------------------------------------------------------------

// only compile this file if in 2d
#if deal_II_dimension == 2

#include <fe/fe_nedelec.h>

// Transfer matrices for finite elements: have one matrix for each of
// the four child cells which tells us how the degrees of freedom on
// the child cell are obtained from the degrees of freedom on the
// mother cell
//
// TODO: [Anna] check whether the following paragraph is correct. if so, then please multiply the values in the four following matrices by two

// note the following: since the shape functions themselves and not
// only the gradients are transformed using the mapping object from
// the unit cell to the real cell, the actual values of the function
// on the real cell is degree of freedom times value of the shape
// function on the unit cell times Jacobian. Thus, what has the DoF
// value 1 on the mother cell must have the DoF value 2 on the child
// cell since the latter is smaller by a (linear scaling) factor of
// two.
namespace FE_Nedelec_2d
{
  static const double q1_into_q1_refined_0[] =
  {
	1.,  0,  0,  0,
	0,   0.5,0,  0.5,
	0.5, 0,  0.5,0,
	0,   0,  0,  1
  };

  static const double q1_into_q1_refined_1[] =
  {
  	1., 0., 0., 0.,
  	0., 1., 0., 0.,
  	0.5, 0., 0.5, 0.,
	0., 0.5, 0., 0.5,
  };

  static const double q1_into_q1_refined_2[] =
  {
  	0.5, 0., 0.5, 0.,
 	0., 1., 0., 0.,
	0., 0., 1., 0.,
  	0., 0.5, 0., 0.5,
  };

  static const double q1_into_q1_refined_3[] =
  {
  	0.5, 0., 0.5, 0.,
  	0., 0.5, 0., 0.5,
	0., 0., 1., 0.,
  	0., 0., 0., 1.,
  };
};  // namespace FE_Nedelec_2d

// embedding matrices

template <>
const double * const
FE_Nedelec<2>::Matrices::embedding[][GeometryInfo<2>::children_per_cell] =
{
      { FE_Nedelec_2d::q1_into_q1_refined_0, FE_Nedelec_2d::q1_into_q1_refined_1,
	FE_Nedelec_2d::q1_into_q1_refined_2, FE_Nedelec_2d::q1_into_q1_refined_3 }
};

template <>
const unsigned int
FE_Nedelec<2>::Matrices::n_embedding_matrices
= sizeof(FE_Nedelec<2>::Matrices::embedding) /
sizeof(FE_Nedelec<2>::Matrices::embedding[0]);

// Constraint matrices: how do the new value on child faces depend on
// the values on the mother face if that face has a hanging node
//
// Here, the same applies as for the embedding matrices: since the DoF
// values are not only multiplied by the values of the shape function
// on the unit cell, but also by the transformation, we have to
// multiply the value on the large face by 1/2 to get the same value
// back on the small face.  in other words, if a DoF has weight 1 on
// the big cell, then it has to have weight 1/2 on the small ones, in
// order to give the same value of the shape function in real space
namespace FE_Nedelec_2d
{
  static const double constraint_q1[] =
  {
					 // the function is constant
					 // along each edge, so each
					 // degree of freedom on the
					 // refined edge has the same
					 // value as that on the
					 // coarse edge, modulo the
					 // issue with the
					 // transformation described
					 // above
  	1./2., 1./2.
  };

};

template <>
const double * const
FE_Nedelec<2>::Matrices::constraint_matrices[] =
{
      FE_Nedelec_2d::constraint_q1
};

template <>
const unsigned int
FE_Nedelec<2>::Matrices::n_constraint_matrices
= sizeof(FE_Nedelec<2>::Matrices::constraint_matrices) /
sizeof(FE_Nedelec<2>::Matrices::constraint_matrices[0]);

#else // #if deal_II_dimension
// On gcc2.95 on Alpha OSF1, the native assembler does not like empty
// files, so provide some dummy code
namespace { void dummy () {}; };
#endif // #if deal_II_dimension == 2
<commit_msg>Fix embedding matrices for 2d.<commit_after>//----------------------------------------------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 2001, 2002 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//----------------------------------------------------------------

// only compile this file if in 2d
#if deal_II_dimension == 2

#include <fe/fe_nedelec.h>

// Transfer matrices for finite elements: have one matrix for each of
// the four child cells which tells us how the degrees of freedom on
// the child cell are obtained from the degrees of freedom on the
// mother cell
//
// note the following: since the shape functions themselves and not
// only the gradients are transformed using the mapping object from
// the unit cell to the real cell, the actual values of the function
// on the real cell is degree of freedom times value of the shape
// function on the unit cell times inverse Jacobian. Thus, what has
// the DoF value 1 on the mother cell must have the DoF value 1/2 on
// the child cell since the latter is smaller by a (linear scaling)
// factor of two.
namespace FE_Nedelec_2d
{
  static const double q1_into_q1_refined_0[] =
  {
	.5,   0,   0 ,  0,
	0,    0.25,0,   0.25,
	0.25, 0,   0.25,0,
	0,    0,   0,   .5
  };

  static const double q1_into_q1_refined_1[] =
  {
  	.5,   0.,   0.,   0.,
  	0.,   .5,   0.,   0.,
  	0.25, 0.,   0.25, 0.,
	0.,   0.25, 0.,   0.25,
  };

  static const double q1_into_q1_refined_2[] =
  {
  	0.25, 0.,   0.25, 0.,
 	0.,   .5,   0.,   0.,
	0.,   0.,   .5,   0.,
  	0.,   0.25, 0.,   0.25,
  };

  static const double q1_into_q1_refined_3[] =
  {
  	0.25, 0.,   0.25, 0.,
  	0.,   0.25, 0.,   0.25,
	0.,   0.,   .5,   0.,
  	0.,   0.,   0.,   .5,
  };
};  // namespace FE_Nedelec_2d

// embedding matrices

template <>
const double * const
FE_Nedelec<2>::Matrices::embedding[][GeometryInfo<2>::children_per_cell] =
{
      { FE_Nedelec_2d::q1_into_q1_refined_0, FE_Nedelec_2d::q1_into_q1_refined_1,
	FE_Nedelec_2d::q1_into_q1_refined_2, FE_Nedelec_2d::q1_into_q1_refined_3 }
};

template <>
const unsigned int
FE_Nedelec<2>::Matrices::n_embedding_matrices
= sizeof(FE_Nedelec<2>::Matrices::embedding) /
sizeof(FE_Nedelec<2>::Matrices::embedding[0]);

// Constraint matrices: how do the new value on child faces depend on
// the values on the mother face if that face has a hanging node
//
// Here, the same applies as for the embedding matrices: since the DoF
// values are not only multiplied by the values of the shape function
// on the unit cell, but also by the transformation, we have to
// multiply the value on the large face by 1/2 to get the same value
// back on the small face.  in other words, if a DoF has weight 1 on
// the big cell, then it has to have weight 1/2 on the small ones, in
// order to give the same value of the shape function in real space
namespace FE_Nedelec_2d
{
  static const double constraint_q1[] =
  {
					 // the function is constant
					 // along each edge, so each
					 // degree of freedom on the
					 // refined edge has the same
					 // value as that on the
					 // coarse edge, modulo the
					 // issue with the
					 // transformation described
					 // above
  	1./2., 1./2.
  };

};

template <>
const double * const
FE_Nedelec<2>::Matrices::constraint_matrices[] =
{
      FE_Nedelec_2d::constraint_q1
};

template <>
const unsigned int
FE_Nedelec<2>::Matrices::n_constraint_matrices
= sizeof(FE_Nedelec<2>::Matrices::constraint_matrices) /
sizeof(FE_Nedelec<2>::Matrices::constraint_matrices[0]);

#else // #if deal_II_dimension
// On gcc2.95 on Alpha OSF1, the native assembler does not like empty
// files, so provide some dummy code
namespace { void dummy () {}; };
#endif // #if deal_II_dimension == 2
<|endoftext|>


<commit_before>//---------------------------------------------------------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//---------------------------------------------------------------------------

#include <dofs/dof_handler.h>
#include <dofs/hp_dof_handler.h>

namespace
{
  // Functions for the DoFHandler
  template <int dim>
  unsigned int
  max_dofs_per_cell (const DoFHandler<dim> &dh)
  {
    return dh.get_fe().dofs_per_cell;
  }

  template <int dim>
  unsigned int
  max_dofs_per_face (const DoFHandler<dim> &dh)
  {
    return dh.get_fe().dofs_per_face;
  }

  template <int dim>
  unsigned int
  get_n_components (const DoFHandler<dim> &dh)
  {
    return dh.get_fe().n_components();
  }

  // Functions for the hp::DoFHandler
  template <int dim>
  unsigned int
  max_dofs_per_cell (const hp::DoFHandler<dim> &dh)
  {
    return dh.get_fe().max_dofs_per_cell ();
  }

  template <int dim>
  unsigned int
  max_dofs_per_face (const hp::DoFHandler<dim> &dh)
  {
    return dh.get_fe().max_dofs_per_face ();
  }

  template <int dim>
  unsigned int
  get_n_components (const hp::DoFHandler<dim> &dh)
  {
    return dh.get_fe().n_components();
  }
}

#include<numerics/vectors.templates.h>

// explicit instantiations

#define VEC Vector<double>
#include "vectors.instance.h"
#undef VEC

#define VEC Vector<float>
#include "vectors.instance.h"
#undef VEC

#define VEC BlockVector<double>
#include "vectors.instance.h"
#undef VEC

#define VEC BlockVector<float>
#include "vectors.instance.h"
#undef VEC

template
void VectorTools::create_right_hand_side<deal_II_dimension>
(const Mapping<deal_II_dimension>    &,
 const DoFHandler<deal_II_dimension> &,
 const Quadrature<deal_II_dimension> &,
 const Function<deal_II_dimension>   &,
 Vector<double>                      &);
template
void VectorTools::create_right_hand_side<deal_II_dimension>
(const DoFHandler<deal_II_dimension> &,
 const Quadrature<deal_II_dimension> &,
 const Function<deal_II_dimension>   &,
 Vector<double>                      &);

#if deal_II_dimension != 1
template
void
VectorTools::create_boundary_right_hand_side<deal_II_dimension>
(const Mapping<deal_II_dimension>    &,
 const DoFHandler<deal_II_dimension> &,
 const Quadrature<deal_II_dimension-1> &,
 const Function<deal_II_dimension>   &,
 Vector<double>                      &,
 const std::set<unsigned char> &);
#endif

template
void
VectorTools::create_boundary_right_hand_side<deal_II_dimension>
(const DoFHandler<deal_II_dimension> &,
 const Quadrature<deal_II_dimension-1> &,
 const Function<deal_II_dimension>   &,
 Vector<double>                      &,
 const std::set<unsigned char> &);
template
void VectorTools::interpolate_boundary_values<deal_II_dimension> (
  const DoFHandler<deal_II_dimension> &,
  const unsigned char,
  const Function<deal_II_dimension>   &,
  std::map<unsigned int,double>       &,
  const std::vector<bool>    &);

#if deal_II_dimension != 1
template
void VectorTools::project_boundary_values<deal_II_dimension>
(const Mapping<deal_II_dimension>     &,
 const DoFHandler<deal_II_dimension>  &,
 const FunctionMap<deal_II_dimension>::type &,
 const Quadrature<deal_II_dimension-1>&,
 std::map<unsigned int,double>        &);
#endif

template
void VectorTools::project_boundary_values<deal_II_dimension>
(const DoFHandler<deal_II_dimension>  &,
 const FunctionMap<deal_II_dimension>::type &,
 const Quadrature<deal_II_dimension-1>&,
 std::map<unsigned int,double>        &);

// Due to introducing the DoFHandler as a template parameter,
// the following instantiations are required in 1d
#if deal_II_dimension == 1
template
void VectorTools::interpolate_boundary_values<deal_II_dimension>
(const Mapping<1>         &,
 const DoFHandler<1>      &,
 const unsigned char,
 const Function<1>        &,
 std::map<unsigned int,double> &,
 const std::vector<bool>       &);
#endif

// the following two functions are not derived from a template in 1d
// and thus need no explicit instantiation
#if deal_II_dimension > 1
template
void VectorTools::interpolate_boundary_values<deal_II_dimension>
(const Mapping<deal_II_dimension>    &,
 const DoFHandler<deal_II_dimension> &,
 const FunctionMap<deal_II_dimension>::type &,
 std::map<unsigned int,double>       &,
 const std::vector<bool>    &);

template
void VectorTools::interpolate_boundary_values<deal_II_dimension>
(const Mapping<deal_II_dimension>    &,
 const DoFHandler<deal_II_dimension> &,
 const unsigned char,
 const Function<deal_II_dimension>   &,
 std::map<unsigned int,double>       &,
 const std::vector<bool>    &);

#endif

template
void
VectorTools::interpolate_boundary_values<deal_II_dimension>
(const DoFHandler<deal_II_dimension>         &,
 const FunctionMap<deal_II_dimension>::type &,
 std::map<unsigned int,double> &,
 const std::vector<bool>       &);

<commit_msg>Instantiate interpolate_boundary_values for hp.<commit_after>//---------------------------------------------------------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//---------------------------------------------------------------------------

#include <dofs/dof_handler.h>
#include <dofs/hp_dof_handler.h>

namespace
{
  // Functions for the DoFHandler
  template <int dim>
  unsigned int
  max_dofs_per_cell (const DoFHandler<dim> &dh)
  {
    return dh.get_fe().dofs_per_cell;
  }

  template <int dim>
  unsigned int
  max_dofs_per_face (const DoFHandler<dim> &dh)
  {
    return dh.get_fe().dofs_per_face;
  }

  template <int dim>
  unsigned int
  get_n_components (const DoFHandler<dim> &dh)
  {
    return dh.get_fe().n_components();
  }

  // Functions for the hp::DoFHandler
  template <int dim>
  unsigned int
  max_dofs_per_cell (const hp::DoFHandler<dim> &dh)
  {
    return dh.get_fe().max_dofs_per_cell ();
  }

  template <int dim>
  unsigned int
  max_dofs_per_face (const hp::DoFHandler<dim> &dh)
  {
    return dh.get_fe().max_dofs_per_face ();
  }

  template <int dim>
  unsigned int
  get_n_components (const hp::DoFHandler<dim> &dh)
  {
    return dh.get_fe().n_components();
  }
}

#include<numerics/vectors.templates.h>

// explicit instantiations

#define VEC Vector<double>
#include "vectors.instance.h"
#undef VEC

#define VEC Vector<float>
#include "vectors.instance.h"
#undef VEC

#define VEC BlockVector<double>
#include "vectors.instance.h"
#undef VEC

#define VEC BlockVector<float>
#include "vectors.instance.h"
#undef VEC

template
void VectorTools::create_right_hand_side<deal_II_dimension>
(const Mapping<deal_II_dimension>    &,
 const DoFHandler<deal_II_dimension> &,
 const Quadrature<deal_II_dimension> &,
 const Function<deal_II_dimension>   &,
 Vector<double>                      &);
template
void VectorTools::create_right_hand_side<deal_II_dimension>
(const DoFHandler<deal_II_dimension> &,
 const Quadrature<deal_II_dimension> &,
 const Function<deal_II_dimension>   &,
 Vector<double>                      &);

#if deal_II_dimension != 1
template
void
VectorTools::create_boundary_right_hand_side<deal_II_dimension>
(const Mapping<deal_II_dimension>    &,
 const DoFHandler<deal_II_dimension> &,
 const Quadrature<deal_II_dimension-1> &,
 const Function<deal_II_dimension>   &,
 Vector<double>                      &,
 const std::set<unsigned char> &);
#endif

template
void
VectorTools::create_boundary_right_hand_side<deal_II_dimension>
(const DoFHandler<deal_II_dimension> &,
 const Quadrature<deal_II_dimension-1> &,
 const Function<deal_II_dimension>   &,
 Vector<double>                      &,
 const std::set<unsigned char> &);

template
void VectorTools::interpolate_boundary_values<deal_II_dimension> (
  const DoFHandler<deal_II_dimension> &,
  const unsigned char,
  const Function<deal_II_dimension>   &,
  std::map<unsigned int,double>       &,
  const std::vector<bool>    &);

template
void VectorTools::interpolate_boundary_values<deal_II_dimension> (
  const hp::DoFHandler<deal_II_dimension> &,
  const unsigned char,
  const Function<deal_II_dimension>   &,
  std::map<unsigned int,double>       &,
  const std::vector<bool>    &);

#if deal_II_dimension != 1
template
void VectorTools::project_boundary_values<deal_II_dimension>
(const Mapping<deal_II_dimension>     &,
 const DoFHandler<deal_II_dimension>  &,
 const FunctionMap<deal_II_dimension>::type &,
 const Quadrature<deal_II_dimension-1>&,
 std::map<unsigned int,double>        &);
#endif

template
void VectorTools::project_boundary_values<deal_II_dimension>
(const DoFHandler<deal_II_dimension>  &,
 const FunctionMap<deal_II_dimension>::type &,
 const Quadrature<deal_II_dimension-1>&,
 std::map<unsigned int,double>        &);

// Due to introducing the DoFHandler as a template parameter,
// the following instantiations are required in 1d
#if deal_II_dimension == 1
template
void VectorTools::interpolate_boundary_values<deal_II_dimension>
(const Mapping<1>         &,
 const DoFHandler<1>      &,
 const unsigned char,
 const Function<1>        &,
 std::map<unsigned int,double> &,
 const std::vector<bool>       &);
#endif

// the following two functions are not derived from a template in 1d
// and thus need no explicit instantiation
#if deal_II_dimension > 1
template
void VectorTools::interpolate_boundary_values<deal_II_dimension>
(const Mapping<deal_II_dimension>    &,
 const DoFHandler<deal_II_dimension> &,
 const FunctionMap<deal_II_dimension>::type &,
 std::map<unsigned int,double>       &,
 const std::vector<bool>    &);

template
void VectorTools::interpolate_boundary_values<deal_II_dimension>
(const Mapping<deal_II_dimension>    &,
 const DoFHandler<deal_II_dimension> &,
 const unsigned char,
 const Function<deal_II_dimension>   &,
 std::map<unsigned int,double>       &,
 const std::vector<bool>    &);

#endif

template
void
VectorTools::interpolate_boundary_values<deal_II_dimension>
(const DoFHandler<deal_II_dimension>         &,
 const FunctionMap<deal_II_dimension>::type &,
 std::map<unsigned int,double> &,
 const std::vector<bool>       &);

<|endoftext|>


<commit_before>#ifndef CARTESIAN_HPP_40UV2UQE
#define CARTESIAN_HPP_40UV2UQE

#include "types.hpp"

#include <boost/python.hpp>
using namespace boost::python;

class PointCartesian2D {
	/**
	 * Pointer to the low-level ViennaGrid point type.
	**/
	PointCartesian2D_t *point;

	int id;
public:
	/**
	 * Initialize point in the 2D cartesian space with coordinates (0, 0).
	 *
	 * This constructor is meant to be used when the programmer creates an instance of the high-level Python point,
	 * and allocates memory in the heap for storing the point. As one would normally think, this should be paired
	 * with a destructor that frees the allocated memory. However, when we free the memory in the destructor, the
	 * program aborts and states that the program tried to perform a double-free.
	**/
	PointCartesian2D();

	/**
	 * Initialize point in the 2D cartesian space with coordinates (x, y) as specified by the parameters.
	 *
	 * This constructor is meant to be used when the programmer creates an instance of the high-level Python point,
	 * and allocates memory in the heap for storing the point. As one would normally think, this should be paired
	 * with a destructor that frees the allocated memory. However, when we free the memory in the destructor, the
	 * program aborts and states that the program tried to perform a double-free.
	**/
	PointCartesian2D(double x, double y);

	/**
	 * Initialize point in the DIM cartesian space from a ViennaGrid point.
	 *
	 * What this makes is to set the pointer to point to the ViennaGrid point and thus solves the issue caused by
	 * the fact that the ViennaGrid point was being copied, thus not being able to get references to the points
	 * stored in the domain and thus not being able to modify them.
	 *
	 * This constructor is meant to be used by the wrapper code when the programmer tries to get a reference to
	 * a point stored in a domain (not when they want to define a point on their own!), and *does not* allocate
	 * memory in the heap, thus elliminating the need for the constructor to free that memory when this constructor
	 * has been used. At first, one would think that it should be distinguished in some way when the object has been
	 * instantiated using this constructor or any other constructor in order for the destructor to only free when
	 * another constructor has been called, not this one. However, we have shown that no freeing action is need at all.
	**/
	PointCartesian2D(PointCartesian2D_t &initial_point, unsigned int initial_id=0);
	size_t get_dimension();
	const char * get_coord_system();
	PointCartesian2D_t & get_point();
	bool operator==(const PointCartesian2D &other);
	unsigned int get_id();
	void set_id(unsigned int new_id);
	double get_coord(unsigned int index);
	void set_coord(unsigned int index, double new_value);
	list get_coord_list();
	PointCartesian2D & operator=(const PointCartesian2D &other);
	PointCartesian2D operator+(const PointCartesian2D &other);
	PointCartesian2D operator-(const PointCartesian2D &other);
	PointCartesian2D operator*(const double factor);
	PointCartesian2D operator/(const double factor);
};

class PointCartesian3D {
	/**
	 * Pointer to the low-level ViennaGrid point type.
	**/
	PointCartesian3D_t *point;

	int id;
public:
	/**
	 * Initialize point in the 3D cartesian space with coordinates (0, 0, 0).
	 *
	 * This constructor is meant to be used when the programmer creates an instance of the high-level Python point,
	 * and allocates memory in the heap for storing the point. As one would normally think, this should be paired
	 * with a destructor that frees the allocated memory. However, when we free the memory in the destructor, the
	 * program aborts and states that the program tried to perform a double-free.
	**/
	PointCartesian3D();

	/**
	 * Initialize point in the 3D cartesian space with coordinates (x, y, z) as specified by the parameters.
	 *
	 * This constructor is meant to be used when the programmer creates an instance of the high-level Python point,
	 * and allocates memory in the heap for storing the point. As one would normally think, this should be paired
	 * with a destructor that frees the allocated memory. However, when we free the memory in the destructor, the
	 * program aborts and states that the program tried to perform a double-free.
	**/
	PointCartesian3D(double x, double y, double z);

	/**
	 * Initialize point in the DIM cartesian space from a ViennaGrid point.
	 *
	 * What this makes is to set the pointer to point to the ViennaGrid point and thus solves the issue caused by
	 * the fact that the ViennaGrid point was being copied, thus not being able to get references to the points
	 * stored in the domain and thus not being able to modify them.
	 *
	 * This constructor is meant to be used by the wrapper code when the programmer tries to get a reference to
	 * a point stored in a domain (not when they want to define a point on their own!), and *does not* allocate
	 * memory in the heap, thus elliminating the need for the constructor to free that memory when this constructor
	 * has been used. At first, one would think that it should be distinguished in some way when the object has been
	 * instantiated using this constructor or any other constructor in order for the destructor to only free when
	 * another constructor has been called, not this one. However, we have shown that no freeing action is need at all.
	**/
	PointCartesian3D(PointCartesian3D_t &initial_point, unsigned int initial_id=0);
	size_t get_dimension();
	const char * get_coord_system();
	PointCartesian3D_t & get_point();
	bool operator==(const PointCartesian3D &other);
	unsigned int get_id();
	void set_id(unsigned int new_id);
};

#endif /* end of include guard: CARTESIAN_HPP_40UV2UQE */
<commit_msg>Reorder methods in the interface of cartesian 2D points and add comments.<commit_after>#ifndef CARTESIAN_HPP_40UV2UQE
#define CARTESIAN_HPP_40UV2UQE

#include "types.hpp"

#include <boost/python.hpp>
using namespace boost::python;

class PointCartesian2D {
	/**
	 * Pointer to the low-level ViennaGrid point type that actually stores the information about the point.
	**/
	PointCartesian2D_t *point;

	/**
	 * ID of the point within the domain it is assigned to (if applicable).
	 * If the point is not assigned to any domain as a vertex, its value is -1.
	 * Otherwise, its value will be the ID of the point within the domain, i.e. its index
	 * in the vector of vertices.
	**/
	int id;
public:
	/**
	 * Initialize point in the 2D cartesian space with coordinates (0, 0).
	 *
	 * This constructor is meant to be used when the programmer creates an instance of the high-level Python point,
	 * and allocates memory in the heap for storing the point. As one would normally think, this should be paired
	 * with a destructor that frees the allocated memory. However, when we free the memory in the destructor, the
	 * program aborts and states that the program tried to perform a double-free.
	**/
	PointCartesian2D();

	/**
	 * Initialize point in the 2D cartesian space with coordinates (x, y) as specified by the parameters.
	 *
	 * This constructor is meant to be used when the programmer creates an instance of the high-level Python point,
	 * and allocates memory in the heap for storing the point. As one would normally think, this should be paired
	 * with a destructor that frees the allocated memory. However, when we free the memory in the destructor, the
	 * program aborts and states that the program tried to perform a double-free.
	**/
	PointCartesian2D(double x, double y);

	/**
	 * Initialize point in the DIM cartesian space from a ViennaGrid point.
	 *
	 * What this makes is to set the pointer to point to the ViennaGrid point and thus solves the issue caused by
	 * the fact that the ViennaGrid point was being copied, thus not being able to get references to the points
	 * stored in the domain and thus not being able to modify them.
	 *
	 * This constructor is meant to be used by the wrapper code when the programmer tries to get a reference to
	 * a point stored in a domain (not when they want to define a point on their own!), and *does not* allocate
	 * memory in the heap, thus elliminating the need for the constructor to free that memory when this constructor
	 * has been used. At first, one would think that it should be distinguished in some way when the object has been
	 * instantiated using this constructor or any other constructor in order for the destructor to only free when
	 * another constructor has been called, not this one. However, we have shown that no freeing action is need at all.
	**/
	PointCartesian2D(PointCartesian2D_t &initial_point, unsigned int initial_id=0);

	/**
	 * Get the dimension of the point. For 2D points, this always returns 2.
	**/
	size_t get_dimension();

	/**
	 * Get the name of the coordinate system. For cartesian points, this always returns 'cartesian'.
	**/
	const char * get_coord_system();

	/**
	 * Get the coordinate at given index (0 for x, 1 for y).
	**/
	double get_coord(unsigned int index);

	/**
	 * Set the coordinate at given index (0 for x, 1 for y).
	**/
	void set_coord(unsigned int index, double new_value);

	/**
	 * Get coordinates as a Python list.
	**/
	list get_coord_list();

	bool operator==(const PointCartesian2D &other);

	/**
	 * Assignment operator that copies the coordinates of the right operand to the left operand.
	 * This operator cannot be wrapped to Python explicitly.
	**/
	PointCartesian2D & operator=(const PointCartesian2D &other);

	/**
	 * Addition operator which adds two points coordinate by coordinate.
	**/
	PointCartesian2D operator+(const PointCartesian2D &other);

	/**
	 * Subtraction operator which subtracts two points coordinate by coordinate.
	**/
	PointCartesian2D operator-(const PointCartesian2D &other);

	/**
	 * Multiplication operator which multiplies a point and a scalar (real) number, coordinate by coordinate.
	**/
	PointCartesian2D operator*(const double factor);

	/**
	 * Divisioon operator which divides a point and a scalar (real) number, coordinate by coordinate.
	**/
	PointCartesian2D operator/(const double factor);

	/**
	 * Get ViennaGrid point.
	**/
	PointCartesian2D_t & get_point();

	/**
	 * Get ID of the point within the domain it is assigned to (if applicable).
	**/
	unsigned int get_id();

	/**
	 * Set ID of the point within the domain it is assigned to.
	**/
	void set_id(unsigned int new_id);
};

class PointCartesian3D {
	/**
	 * Pointer to the low-level ViennaGrid point type.
	**/
	PointCartesian3D_t *point;

	int id;
public:
	/**
	 * Initialize point in the 3D cartesian space with coordinates (0, 0, 0).
	 *
	 * This constructor is meant to be used when the programmer creates an instance of the high-level Python point,
	 * and allocates memory in the heap for storing the point. As one would normally think, this should be paired
	 * with a destructor that frees the allocated memory. However, when we free the memory in the destructor, the
	 * program aborts and states that the program tried to perform a double-free.
	**/
	PointCartesian3D();

	/**
	 * Initialize point in the 3D cartesian space with coordinates (x, y, z) as specified by the parameters.
	 *
	 * This constructor is meant to be used when the programmer creates an instance of the high-level Python point,
	 * and allocates memory in the heap for storing the point. As one would normally think, this should be paired
	 * with a destructor that frees the allocated memory. However, when we free the memory in the destructor, the
	 * program aborts and states that the program tried to perform a double-free.
	**/
	PointCartesian3D(double x, double y, double z);

	/**
	 * Initialize point in the DIM cartesian space from a ViennaGrid point.
	 *
	 * What this makes is to set the pointer to point to the ViennaGrid point and thus solves the issue caused by
	 * the fact that the ViennaGrid point was being copied, thus not being able to get references to the points
	 * stored in the domain and thus not being able to modify them.
	 *
	 * This constructor is meant to be used by the wrapper code when the programmer tries to get a reference to
	 * a point stored in a domain (not when they want to define a point on their own!), and *does not* allocate
	 * memory in the heap, thus elliminating the need for the constructor to free that memory when this constructor
	 * has been used. At first, one would think that it should be distinguished in some way when the object has been
	 * instantiated using this constructor or any other constructor in order for the destructor to only free when
	 * another constructor has been called, not this one. However, we have shown that no freeing action is need at all.
	**/
	PointCartesian3D(PointCartesian3D_t &initial_point, unsigned int initial_id=0);
	size_t get_dimension();
	const char * get_coord_system();
	PointCartesian3D_t & get_point();
	bool operator==(const PointCartesian3D &other);
	unsigned int get_id();
	void set_id(unsigned int new_id);
};

#endif /* end of include guard: CARTESIAN_HPP_40UV2UQE */
<|endoftext|>