<commit_before>//
//
//    The Laxkit, a windowing toolkit
//    Please consult http://laxkit.sourceforge.net about where to send any
//    correspondence about this software.
//
//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Library General Public
//    License as published by the Free Software Foundation; either
//    version 2 of the License, or (at your option) any later version.
//
//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Library General Public License for more details.
//
//    You should have received a copy of the GNU Library General Public
//    License along with this library; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//    Copyright (C) 2012 by Tom Lechner
//

#include <lax/fontmanager-xlib.h>
#include <lax/anxapp.h>
#include <cstdio>

#include <lax/lists.cc> // this is necessary to instantiate templates
#include <lax/refptrstack.cc>

static const char hexdigits[17]="0123456789ABCDEF";

#include <iostream>
#define DBG
using namespace std;

namespace Laxkit {

//--------------------------- FontManagerCairo ------------------------------------------
FontManager *newFontManager_xlib()
{ return new FontManagerXlib(); }

//---------------------------- LaxFontXlib -------------------------------

/*! \class LaxFontXlib
 * \brief A LaxFont using Xft.
 *
 * In addition to an XftFont holding the font, LaxFont also contains easy to
 * get to info about the range of characters defined in the font (one continuous range
 * is allowed per LaxFont), the text height, ascent, and descent, and the widths of the
 * characters. The width is actually separated into 2 width arrays. One has the real
 * character width, which could be 0, and one has the charwidths based on converted the
 * 0 width characters into a hex representation. For instance, the character '\\n' has
 * ascii value 10, and it might be converted to "\0a". This is to aid text editors such
 * as LineEdit.
 *
 * These objects are reference counted via dec_count() and inc_count(). If a dec_count()
 * results in a count of 0, then <tt>delete this</tt> is called.
 *
 * \todo read up on Xft, have ability to maintain charwidths[] for multiple ranges,
 *   not just the basic Latin1/small [firstcharinfont + numcharsinfont]. Must be able to
 *   facilitate font subsetting
 */
LaxFontXlib::LaxFontXlib()
{
	charwidths=realcharwidths=NULL;
	textstyle=0;
	numcharsinfont=firstchar=0;
	font=NULL;
}

//! Constructor. Uses an X Logical Font Description.
LaxFontXlib::LaxFontXlib(Display *dpy,const char *xlfd,int nid)
{
	id=nid;
	if (!id) id=getUniqueNumber();
	charwidths=realcharwidths=NULL;
	textstyle=0;
	cntlchar=0;
	font=NULL;

	font=XftFontOpenName(dpy,0,xlfd);
	//font=XftFontOpenXlfd(dpy,0,xlfd);
	SetupMetrics();
}

/*! Takes over xfs. Calling code must not free it.
 */
LaxFontXlib::LaxFontXlib(XftFont *f,int nid)
{
	font=f;
	id=nid;
	if (!id) id=getUniqueNumber();
	charwidths=realcharwidths=NULL;
	textstyle=0;
	cntlchar=0;
	SetupMetrics();
}

LaxFontXlib::~LaxFontXlib()
{
	if (font) XftFontClose(anXApp::app->dpy, font);

	if (charwidths)     delete[] charwidths;
	if (realcharwidths) delete[] realcharwidths;
}

double LaxFontXlib::textheight()
{
	if (font) return font->height;
	return 0;
}

double LaxFontXlib::ascent()
{
	if (font) return font->ascent;
	else return 0;
}

double LaxFontXlib::descent()
{
	if (font) return font->descent;
	else return 0;
}

double LaxFontXlib::Resize(double newsize)
{
	cerr << " *** WARNING!! FontManagerXlib::Resize() not implemented!!!"<<endl;
	return textheight();
}

//! Return the character width of ch.
/*! This assumes the charwidth array exists already.
 * If the real character width is 0, and r==0, this returns width of "\9f"
 * or some such. Of course, this function is for latin-1 only.
 *
 * \todo *** this is broken
 */
double LaxFontXlib::charwidth(unsigned long chr,int real,double *width,double *height)
{
	if (!charwidths || !realcharwidths) return 0;

	unsigned char ch=(unsigned char)chr;//***

	if (ch<firstchar || ch>=firstchar+numcharsinfont) {
		if (real) return 0;
		 // return the hexified val of ch (just the number)
		return charwidth(cntlchar,1)+charwidth(hexdigits[ch&15],1)+charwidth(hexdigits[ch>>4&15],1);
	}
	if (real && realcharwidths) return realcharwidths[ch-firstchar];
	return charwidths[ch-firstchar];
}

//! Return 0 success else nonzero error
/*! This fills up charwidths and realcharwidths with appropriate values.
 *
 * \todo *** this is old and basically broken. is all core xlib
 */
int LaxFontXlib::SetupMetrics()
{
	return 1;
//*********this stuff is all old. Is it in any way useful????
//
//	if (charwidths) { delete[] charwidths; charwidths=NULL; }
//	if (realcharwidths) { delete[] realcharwidths; realcharwidths=NULL; }
//
//	*** //is this stuff used anymore??
//
//	 // ***assumes linear character index, starting close to 0
//	firstchar= fontstruct->min_char_or_byte2;
//	numcharsinfont= fontstruct->max_char_or_byte2 - fontstruct->min_char_or_byte2 + 1;
//	if (fontstruct->min_byte1!=0 || fontstruct->max_byte1!=0) {
//		 // byte1/byte2 setup.. what the fuck?
//		DBG cerr <<"Only Ascii or Latin1 fonts supported.\n";
//		exit(1); //***kind of drastic! just return 1 if fail?
//	}
//
//	//*** should have separate width array for hex chars??
//	charwidths=new int[numcharsinfont];
//	realcharwidths=new int[numcharsinfont];
//	if ((unsigned char)cntlchar<firstchar || (unsigned char) cntlchar>=firstchar+numcharsinfont) cntlchar=firstchar;
//
//	int c;
//	for (c=0; c<numcharsinfont; c++) {
//		charwidths[c]=realcharwidths[c]=0;
//		if (fontstruct->per_char) {
//			//realcharwidths[c]=fontstruct->per_char[c].rbearing-fontstruct->per_char[c].lbearing;
//			realcharwidths[c]=fontstruct->per_char[c].width;
//			if (realcharwidths[c]==0)
//				realcharwidths[c]= //***check:is this right?
//					fontstruct->per_char[fontstruct->default_char-firstchar].rbearing -
//					fontstruct->per_char[fontstruct->default_char-firstchar].lbearing;
//		} else { // monospaced
//			realcharwidths[c]=fontstruct->max_bounds.rbearing-fontstruct->max_bounds.lbearing;
//		}
//		charwidths[c]=realcharwidths[c];
//	}
//	if (textstyle&TEXT_CNTL_BANG) {
//		for (c=0; c<numcharsinfont; c++) {
//			if (realcharwidths[c]==0) charwidths[c]=charwidths[(unsigned char)cntlchar-firstchar];
//		}
//	} else if (textstyle&TEXT_CNTL_HEX) {
//		for (c=0; c<numcharsinfont; c++) {
//			if (realcharwidths[c]==0) {
//				charwidths[c]= realcharwidths[(unsigned char)cntlchar-firstchar] +
//								realcharwidths[(unsigned char)hexdigits[(c&15)]-firstchar] +
//								realcharwidths[(unsigned char)hexdigits[((c>>4)&15)]-firstchar];
//			}
//		}
//	}
//
//	return 0;
}

/*! Some languages change the character based on where letter is in word.
 * \todo This function as it stands is totally worthless and meaningless.
 */
double LaxFontXlib::contextcharwidth(char *start,char *pos,int real,double *width,double *height)
{
	return charwidth((unsigned long)(*pos),real, width,height);
}

//--------------------------- FontManagerXlib ------------------------------------------

/*! \class FontManagerXlib
 * \brief The font manager used by anXApp to simplify keeping track of what fonts are loaded.
 */

FontManagerXlib::FontManagerXlib()
	: RefPtrStack<LaxFont>()
{}

//! Add a font to the fontmananger for which an XftFont is already made.
/*! The manager takes possession of xfs, it should not be deleted by anything else.
 *
 * If nid<0 then the id is from getUniqueNumber().
 *
 * Returns the new font object, or NULL on failure.
 */
LaxFont *FontManagerXlib::Add(XftFont *xftfont,int nid)
{
	if (nid<0) nid=getUniqueNumber();
	LaxFont *f=new LaxFontXlib(xftfont,nid);
	push(f);//incs count of f to 2
	f->dec_count();//remove creation count
	return e[n-1];
}

//! Create and return a font based on fcstr, a fontconfig string.
/*! If nid<0 then the id is from getUniqueNumber().
 */
LaxFont *FontManagerXlib::MakeFontFromStr(const char *fcstr, int nid)
{
	if (nid<0) nid=getUniqueNumber();
	LaxFont *f=new LaxFontXlib(anXApp::app->dpy,fcstr,nid);
	return f;
}

//! Add an already created LaxFont to the manager.
/*! If nid<0 then the id is from getUniqueNumber().
 *
 *
 * If the font is already on the stack, nothing is done.
 *
 * The font's count is incremented.
 * Returns the font object or NULL on error.
 */
LaxFont *FontManagerXlib::Add(LaxFont *font,int nid)
{
	if (!font) return NULL;
	if (nid<0) nid=getUniqueNumber();
	pushnodup(font); //incs count if not already on stack
	return font;
}

//! Add a count of 1 to the LaxFont with the given id, and return the corresponding font object.
/*! Returns the LaxFont object, or NULL if object not found.
 *
 * Please remember that when you are all done with the font, you must decrement its count.
 */
LaxFont *FontManagerXlib::CheckOut(int id)
{
	int c;
	for (c=0; c<n; c++) {
		if (e[c]->id==id) {
			e[c]->inc_count();
			return e[c];
		}
	}
	return NULL;
}

//! Create and return a LaxFont, but do not store it within the fontmanager.
/*! This file and size are passed along to fontconfig.
 * If fontconfig cannot do anything with it, NULL is returned.
 */
LaxFont *FontManagerXlib::MakeFontFromFile(const char *file, double size, int nid)
{
	int screen=0;
	if (size<=0) size=anXApp::app->defaultlaxfont->textheight();
	XftFont *xfont=XftFontOpen(anXApp::app->dpy, screen,
								XFT_FILE, XftTypeString, file,
								XFT_PIXEL_SIZE, XftTypeDouble, size,
								NULL);
	if (!xfont) return NULL;
	LaxFont *laxfont=new LaxFontXlib(xfont,nid);

	return laxfont;
}

//! Create and return a LaxFont, but do not store it within the fontmanager.
/*! This family, style, and size are passed along to fontconfig.
 * If fontconfig cannot do anything with it, NULL is returned.
 */
LaxFont *FontManagerXlib::MakeFont(const char *family, const char *style, double size, int nid)
{
	if (!family) return NULL;
	int screen=0;
	if (size<=0) size=anXApp::app->defaultlaxfont->textheight();
	XftFont *xfont;
	if (style) {
		xfont=XftFontOpen(anXApp::app->dpy, screen,
								XFT_FAMILY, XftTypeString, family,
								XFT_STYLE,  XftTypeString, style,
								XFT_PIXEL_SIZE,   XftTypeDouble, size,
								NULL);
	} else {
		xfont=XftFontOpen(anXApp::app->dpy, screen,
								XFT_FAMILY, XftTypeString, family,
								XFT_PIXEL_SIZE,   XftTypeDouble, size,
								NULL);
	}
	if (!xfont) return NULL;
	LaxFont *laxfont=new LaxFontXlib(xfont,nid);

	return laxfont;
}

} // namespace Laxkit
<commit_msg>protecting against faulty XftFontClose<commit_after>//
//
//    The Laxkit, a windowing toolkit
//    Please consult http://laxkit.sourceforge.net about where to send any
//    correspondence about this software.
//
//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Library General Public
//    License as published by the Free Software Foundation; either
//    version 2 of the License, or (at your option) any later version.
//
//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Library General Public License for more details.
//
//    You should have received a copy of the GNU Library General Public
//    License along with this library; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//    Copyright (C) 2012 by Tom Lechner
//

#include <lax/fontmanager-xlib.h>
#include <lax/anxapp.h>
#include <cstdio>

#include <lax/lists.cc> // this is necessary to instantiate templates
#include <lax/refptrstack.cc>

static const char hexdigits[17]="0123456789ABCDEF";

#include <iostream>
#define DBG
using namespace std;

namespace Laxkit {

//--------------------------- FontManagerCairo ------------------------------------------
FontManager *newFontManager_xlib()
{ return new FontManagerXlib(); }

//---------------------------- LaxFontXlib -------------------------------

/*! \class LaxFontXlib
 * \brief A LaxFont using Xft.
 *
 * In addition to an XftFont holding the font, LaxFont also contains easy to
 * get to info about the range of characters defined in the font (one continuous range
 * is allowed per LaxFont), the text height, ascent, and descent, and the widths of the
 * characters. The width is actually separated into 2 width arrays. One has the real
 * character width, which could be 0, and one has the charwidths based on converted the
 * 0 width characters into a hex representation. For instance, the character '\\n' has
 * ascii value 10, and it might be converted to "\0a". This is to aid text editors such
 * as LineEdit.
 *
 * These objects are reference counted via dec_count() and inc_count(). If a dec_count()
 * results in a count of 0, then <tt>delete this</tt> is called.
 *
 * \todo read up on Xft, have ability to maintain charwidths[] for multiple ranges,
 *   not just the basic Latin1/small [firstcharinfont + numcharsinfont]. Must be able to
 *   facilitate font subsetting
 */
LaxFontXlib::LaxFontXlib()
{
	charwidths=realcharwidths=NULL;
	textstyle=0;
	numcharsinfont=firstchar=0;
	font=NULL;
}

//! Constructor. Uses an X Logical Font Description.
LaxFontXlib::LaxFontXlib(Display *dpy,const char *xlfd,int nid)
{
	id=nid;
	if (!id) id=getUniqueNumber();
	charwidths=realcharwidths=NULL;
	textstyle=0;
	cntlchar=0;
	font=NULL;

	font=XftFontOpenName(dpy,0,xlfd);
	//font=XftFontOpenXlfd(dpy,0,xlfd);
	SetupMetrics();
}

/*! Takes over xfs. Calling code must not free it.
 */
LaxFontXlib::LaxFontXlib(XftFont *f,int nid)
{
	font=f;
	id=nid;
	if (!id) id=getUniqueNumber();
	charwidths=realcharwidths=NULL;
	textstyle=0;
	cntlchar=0;
	SetupMetrics();
}

LaxFontXlib::~LaxFontXlib()
{
	if (font && anXApp::app->dpy) XftFontClose(anXApp::app->dpy, font);

	if (charwidths)     delete[] charwidths;
	if (realcharwidths) delete[] realcharwidths;
}

double LaxFontXlib::textheight()
{
	if (font) return font->height;
	return 0;
}

double LaxFontXlib::ascent()
{
	if (font) return font->ascent;
	else return 0;
}

double LaxFontXlib::descent()
{
	if (font) return font->descent;
	else return 0;
}

double LaxFontXlib::Resize(double newsize)
{
	cerr << " *** WARNING!! FontManagerXlib::Resize() not implemented!!!"<<endl;
	return textheight();
}

//! Return the character width of ch.
/*! This assumes the charwidth array exists already.
 * If the real character width is 0, and r==0, this returns width of "\9f"
 * or some such. Of course, this function is for latin-1 only.
 *
 * \todo *** this is broken
 */
double LaxFontXlib::charwidth(unsigned long chr,int real,double *width,double *height)
{
	if (!charwidths || !realcharwidths) return 0;

	unsigned char ch=(unsigned char)chr;//***

	if (ch<firstchar || ch>=firstchar+numcharsinfont) {
		if (real) return 0;
		 // return the hexified val of ch (just the number)
		return charwidth(cntlchar,1)+charwidth(hexdigits[ch&15],1)+charwidth(hexdigits[ch>>4&15],1);
	}
	if (real && realcharwidths) return realcharwidths[ch-firstchar];
	return charwidths[ch-firstchar];
}

//! Return 0 success else nonzero error
/*! This fills up charwidths and realcharwidths with appropriate values.
 *
 * \todo *** this is old and basically broken. is all core xlib
 */
int LaxFontXlib::SetupMetrics()
{
	return 1;
//*********this stuff is all old. Is it in any way useful????
//
//	if (charwidths) { delete[] charwidths; charwidths=NULL; }
//	if (realcharwidths) { delete[] realcharwidths; realcharwidths=NULL; }
//
//	*** //is this stuff used anymore??
//
//	 // ***assumes linear character index, starting close to 0
//	firstchar= fontstruct->min_char_or_byte2;
//	numcharsinfont= fontstruct->max_char_or_byte2 - fontstruct->min_char_or_byte2 + 1;
//	if (fontstruct->min_byte1!=0 || fontstruct->max_byte1!=0) {
//		 // byte1/byte2 setup.. what the fuck?
//		DBG cerr <<"Only Ascii or Latin1 fonts supported.\n";
//		exit(1); //***kind of drastic! just return 1 if fail?
//	}
//
//	//*** should have separate width array for hex chars??
//	charwidths=new int[numcharsinfont];
//	realcharwidths=new int[numcharsinfont];
//	if ((unsigned char)cntlchar<firstchar || (unsigned char) cntlchar>=firstchar+numcharsinfont) cntlchar=firstchar;
//
//	int c;
//	for (c=0; c<numcharsinfont; c++) {
//		charwidths[c]=realcharwidths[c]=0;
//		if (fontstruct->per_char) {
//			//realcharwidths[c]=fontstruct->per_char[c].rbearing-fontstruct->per_char[c].lbearing;
//			realcharwidths[c]=fontstruct->per_char[c].width;
//			if (realcharwidths[c]==0)
//				realcharwidths[c]= //***check:is this right?
//					fontstruct->per_char[fontstruct->default_char-firstchar].rbearing -
//					fontstruct->per_char[fontstruct->default_char-firstchar].lbearing;
//		} else { // monospaced
//			realcharwidths[c]=fontstruct->max_bounds.rbearing-fontstruct->max_bounds.lbearing;
//		}
//		charwidths[c]=realcharwidths[c];
//	}
//	if (textstyle&TEXT_CNTL_BANG) {
//		for (c=0; c<numcharsinfont; c++) {
//			if (realcharwidths[c]==0) charwidths[c]=charwidths[(unsigned char)cntlchar-firstchar];
//		}
//	} else if (textstyle&TEXT_CNTL_HEX) {
//		for (c=0; c<numcharsinfont; c++) {
//			if (realcharwidths[c]==0) {
//				charwidths[c]= realcharwidths[(unsigned char)cntlchar-firstchar] +
//								realcharwidths[(unsigned char)hexdigits[(c&15)]-firstchar] +
//								realcharwidths[(unsigned char)hexdigits[((c>>4)&15)]-firstchar];
//			}
//		}
//	}
//
//	return 0;
}

/*! Some languages change the character based on where letter is in word.
 * \todo This function as it stands is totally worthless and meaningless.
 */
double LaxFontXlib::contextcharwidth(char *start,char *pos,int real,double *width,double *height)
{
	return charwidth((unsigned long)(*pos),real, width,height);
}

//--------------------------- FontManagerXlib ------------------------------------------

/*! \class FontManagerXlib
 * \brief The font manager used by anXApp to simplify keeping track of what fonts are loaded.
 */

FontManagerXlib::FontManagerXlib()
	: RefPtrStack<LaxFont>()
{}

//! Add a font to the fontmananger for which an XftFont is already made.
/*! The manager takes possession of xfs, it should not be deleted by anything else.
 *
 * If nid<0 then the id is from getUniqueNumber().
 *
 * Returns the new font object, or NULL on failure.
 */
LaxFont *FontManagerXlib::Add(XftFont *xftfont,int nid)
{
	if (nid<0) nid=getUniqueNumber();
	LaxFont *f=new LaxFontXlib(xftfont,nid);
	push(f);//incs count of f to 2
	f->dec_count();//remove creation count
	return e[n-1];
}

//! Create and return a font based on fcstr, a fontconfig string.
/*! If nid<0 then the id is from getUniqueNumber().
 */
LaxFont *FontManagerXlib::MakeFontFromStr(const char *fcstr, int nid)
{
	if (nid<0) nid=getUniqueNumber();
	LaxFont *f=new LaxFontXlib(anXApp::app->dpy,fcstr,nid);
	return f;
}

//! Add an already created LaxFont to the manager.
/*! If nid<0 then the id is from getUniqueNumber().
 *
 *
 * If the font is already on the stack, nothing is done.
 *
 * The font's count is incremented.
 * Returns the font object or NULL on error.
 */
LaxFont *FontManagerXlib::Add(LaxFont *font,int nid)
{
	if (!font) return NULL;
	if (nid<0) nid=getUniqueNumber();
	pushnodup(font); //incs count if not already on stack
	return font;
}

//! Add a count of 1 to the LaxFont with the given id, and return the corresponding font object.
/*! Returns the LaxFont object, or NULL if object not found.
 *
 * Please remember that when you are all done with the font, you must decrement its count.
 */
LaxFont *FontManagerXlib::CheckOut(int id)
{
	int c;
	for (c=0; c<n; c++) {
		if (e[c]->id==id) {
			e[c]->inc_count();
			return e[c];
		}
	}
	return NULL;
}

//! Create and return a LaxFont, but do not store it within the fontmanager.
/*! This file and size are passed along to fontconfig.
 * If fontconfig cannot do anything with it, NULL is returned.
 */
LaxFont *FontManagerXlib::MakeFontFromFile(const char *file, double size, int nid)
{
	int screen=0;
	if (size<=0) size=anXApp::app->defaultlaxfont->textheight();
	XftFont *xfont=XftFontOpen(anXApp::app->dpy, screen,
								XFT_FILE, XftTypeString, file,
								XFT_PIXEL_SIZE, XftTypeDouble, size,
								NULL);
	if (!xfont) return NULL;
	LaxFont *laxfont=new LaxFontXlib(xfont,nid);

	return laxfont;
}

//! Create and return a LaxFont, but do not store it within the fontmanager.
/*! This family, style, and size are passed along to fontconfig.
 * If fontconfig cannot do anything with it, NULL is returned.
 */
LaxFont *FontManagerXlib::MakeFont(const char *family, const char *style, double size, int nid)
{
	if (!family) return NULL;
	int screen=0;
	if (size<=0) size=anXApp::app->defaultlaxfont->textheight();
	XftFont *xfont;
	if (style) {
		xfont=XftFontOpen(anXApp::app->dpy, screen,
								XFT_FAMILY, XftTypeString, family,
								XFT_STYLE,  XftTypeString, style,
								XFT_PIXEL_SIZE,   XftTypeDouble, size,
								NULL);
	} else {
		xfont=XftFontOpen(anXApp::app->dpy, screen,
								XFT_FAMILY, XftTypeString, family,
								XFT_PIXEL_SIZE,   XftTypeDouble, size,
								NULL);
	}
	if (!xfont) return NULL;
	LaxFont *laxfont=new LaxFontXlib(xfont,nid);

	return laxfont;
}

} // namespace Laxkit
<|endoftext|>


<commit_before><commit_msg>testing<commit_after><|endoftext|>


<commit_before>#include <iostream> //cout
#include <cstdlib>	//rand, sran
#include <string>
#include "complex_matrices.h"
#include <gmc.h> 	//LaGenMatComplex
#include <laslv.h>  //LUFactorizeIP, LaLUInverseIP, etc.
#include <blas3pp.h>
//#include <random>   //random_device, mt19937

using namespace std;

/* Total [13/20] */

int ran(int a, int b){
//    random_device rd;
//    mt19937 gen(rd());
//    uniform_int_distribution<> dist(a, b);
//    return dist(gen);
    return rand() % b;
}

/* Printing [6/9] */
void print_scalar(const COMPLEX scalar){
    cout << scalar << endl;
}                                                 //working
void print_scalar(const COMPLEX scalar, const string name){
    cout << name << ":" << scalar << endl;
}                              //working
void print_array(const COMPLEX array[], int len){
    for(int i = 0; i < len; i++){
        cout << array[i] << endl;
    }
}                                        //working
void print_array(const COMPLEX array[], int len, const string name){
	cout << name << ":" << endl;
    for(int i = 0; i < len; i++){
        cout << array[i] << endl;
    }
}                     //working
void print_matrix(const LaGenMatComplex& matrix){
	cout << matrix << endl;
}                                        //working
void print_matrix(const LaGenMatComplex& matrix, const string name){
	cout << name << ":" << endl << matrix << endl;
}			          //working

/* Number generation [2/2] */
void generate_scalar(COMPLEX& A, const int x){
    A.r = ran(1, x);	//1 to x
    A.i = ran(1, x);
}               //working
void generate_scalar(int number, const int x){
    number = ran(1, x);	//1 to x
}                                                //working
void generate_array(COMPLEX array[], const int len, const int x){
    for(int i = 0; i < len; i++){
        array[i].r = ran(1, x);	//1 to x
        array[i].i = ran(1, x);
	}
}                        //working

/* Matrix conversion [3/3] */
void vec_to_array(const LaVectorComplex& vector, const int len, COMPLEX array[ ]){
    for(int i = 0; i < len; i++){
        array[i] = vector(i);
    }
}       //working
void array_to_diag(COMPLEX array[], const int len, LaGenMatComplex& diag){
    diag = 0;
    for(int i = 0; i < len; i++){
        diag(i, i) = array[i];
    }
}               //working
void vec_to_diag(const LaVectorComplex& vector, const int len, LaGenMatComplex& diag){
    COMPLEX array[len];
    vec_to_array(vector, len, array);
    array_to_diag(array, len, diag);
}   //working

/* Scalar manipulation [5/8] */
int factorial(int x){
	if(x <= 1){
        return 1;
	}else{
        return x * factorial(x - 1);
	}
}                                                                    //working
void scalar_addition(const COMPLEX& A, const COMPLEX& B , COMPLEX& result){
    result.r = A.r + B.r;
    result.i = A.i + B.i;
}              //working
void scalar_addition(COMPLEX& result, const COMPLEX addition){
    result.r += addition.r;
    result.i += addition.i;
}
void scalar_multiplication(const COMPLEX& A, const int B, COMPLEX& result){
    result.r = A.r * B;
    result.i = A.i * B;
}              //to test
void scalar_multiplication(const COMPLEX& A, const COMPLEX& B, COMPLEX& result){
    la::complex<double> laA = la::complex<double>(A); //convert to la::complex<double>
    la::complex<double> laB = la::complex<double>(B);
    la::complex<double> laResult = la::complex<double>(result);
    laResult = laA * laB;
    result = laResult.toCOMPLEX();
}         //to test
void scalar_product(COMPLEX& total, const COMPLEX& number){
    COMPLEX part;
    part.r = (total.r * number.r) - (total.i * number.i);
    part.i = (total.r * number.i) + (total.i * number.r);
    total = part;
}
void scalar_division(const COMPLEX& A, const int B, COMPLEX& result){
    result.r = A.r / B;
    result.i = A.i / B;
}                    //to test
void scalar_division(const COMPLEX& A, const COMPLEX& B, COMPLEX& result){
    la::complex<double> laA = la::complex<double>(A); //convert to la::complex<double>
    la::complex<double> laB = la::complex<double>(B);
    la::complex<double> laResult = la::complex<double>(result);
    laResult = laA / laB;
    result = laResult.toCOMPLEX();
}               //to test
void scalar_powers(const COMPLEX& number, const int power, COMPLEX& result){
    la::complex<double> laResult = la::complex<double>(number);
    la::complex<double> laNumber = la::complex<double>(number);
    for(int i = 1; i < power; i++){
        laResult *= laNumber;
    }
    result = laResult.toCOMPLEX();
}             //to test
void scalar_exponential_main(const COMPLEX& number, const int iterations, COMPLEX& result){
    COMPLEX division, total_division;
    result.r = 1;
    result.i = 0 ;
    for(int step = 1; step <= iterations; step++){   //sum (from 1 to n)
        total_division.r = 1;
        total_division.i = 0;
        for(int i = 1; i <= step; i++){        //    ( num^n / n!)
            scalar_division(number, i, division);
            scalar_product(total_division, division);
        }
        scalar_addition(result, total_division);
    }
}
void scalar_exponential(const COMPLEX& number, const int iter, COMPLEX& result){
    //COMPLEX power;
    //COMPLEX division;
    //result.r = 0;
    //result.i = 0;
    //for(int i = 0; i < iter; i++){
    //    scalar_powers(number, i, power);
    //    scalar_division(power, factorial(i), division);
    //    scalar_addition(result, division, result);
    //}
}         //empty
//COMPLEX rec_scalar_exp_step(const COMPLEX& number, const int step){
//    COMPLEX result, division, multiplication;
//	if(step <= 1){
//        result.r = 1;
//        return result;
//	}else{
//        scalar_division(number,step,division);
//        scalar_multiplication(division, rec_scalar_exp_step(step-1),  multiplication);
//        return multiplication;
//	}
//}
void recursive_scalar_exponential(const COMPLEX& number, const int iter, COMPLEX& result){
    //COMPLEX power;
    //COMPLEX division;
    //result.r = 0;
    //result.i = 0;
    //for(int i = 0; i < iter; i++){
    //    scalar_powers(number, i, power);
    //    scalar_division(power, factorial(i), division);
    //    scalar_addition(result, division, result);
    //}
} //empty

/* array manipulation [0/1] */
void array_powers(COMPLEX array[], const int len, const int power){/**/
    /*
    for(int i = 0; i < len; i++){
        array[i] = complex_power(array[i], power, result);
    }
    */
}                       //empty

/* Matrix manipulation [2/4] */
void diagonal_matrix_powers(){      //empty
  //...
}
void matrix_multiplication(){

}
void matrix_eigenvstuff(const LaGenMatComplex& matrix, LaVectorComplex& eigenvalues, LaGenMatComplex& eigenvectors){ //working
    //LaEigSolve: http://lapackpp.sourceforge.net/html/laslv_8h.html#086357d17e9cdcaec69ab7db76998769
    LaEigSolve(matrix, eigenvalues, eigenvectors);
}
void matrix_inverse(LaGenMatComplex& matrix, int len){                                                               //working
    // LaLUInverseIP: http://lapackpp.sourceforge.net/html/laslv_8h.html#a042c82c5b818f54e7f000d068f14189
    LaVectorLongInt PIV = LaVectorLongInt(len);
    LUFactorizeIP(matrix, PIV);
    LaLUInverseIP(matrix, PIV);
}
void matrix_exp_step(){                                 //empty
    //
}
void matrix_exponential(const LaGenMatComplex& eigenvectors, const LaGenMatComplex& eigenvalues){
    //LaGenMatComplex step = LaGenMatComplex

} //empty

/* Testing [3/3] */
void test_scalar_manipulation(const int max_rand){
    COMPLEX compA;
    generate_scalar(compA, max_rand);
    COMPLEX compB;
    generate_scalar(compB, max_rand);
    int realB;
    generate_scalar(realB, max_rand);
    COMPLEX result;

    cout << "compA = " << compA << endl;
    cout << "compB = " << compB << endl;
    cout << "realB = " << realB << endl;
    cout << endl;

    for(int i = 1; i < 5; i++){                                                 //factorials
        cout << "factorial(" << i << "): " << factorial(i) << endl;
    }

    scalar_addition(compA, compB, result);                                      //addition/subtraction
    cout << "scalar addition: " << result << endl << endl;

    scalar_multiplication(compA, realB, result);                                //multiplication
    cout << "scalar multiplication by scalar: " << result << endl << endl;

    scalar_multiplication(compA, compB, result);
    cout << "scalar multiplication by complex: " << result << endl << endl;

    scalar_division(compA, realB, result);         //division
    cout << "scalar division by scalar: " << result << endl << endl;

    scalar_division(compA, compB, result);
    cout << "scalar division by complex: " << result << endl << endl;

    for(int i = 1; i < 5; i++){
        scalar_powers(compA, i, result);
        cout << "scalar powers - A^" << i << " = " << result << endl;
    }
    cout << endl;

    COMPLEX sum;
    sum.r = 0;
    sum.i = 0;
    for(int i = 0; i < 5; i++){
        cout << "sum(" << i << ") = " << sum << endl;
        scalar_addition(sum, compA);
    }
    cout << "sum = " << sum << endl;

}                                       //to test
void test_eigenvalues(const LaGenMatComplex& initialMatrix, const int size){
    LaVectorComplex eigenvalueVec = LaVectorComplex(size);             //initialise eigenstuff
    LaGenMatComplex eigenvalues = LaGenMatComplex::zeros(size, size);
    LaGenMatComplex eigenvectors = LaGenMatComplex::zeros(size, size);
    matrix_eigenvstuff(initialMatrix, eigenvalueVec, eigenvectors); //calculate eigenstuff
    print_matrix(eigenvalueVec, "eigenvalue vector");               //print eigenstuff
    vec_to_diag(eigenvalueVec, size, eigenvalues);
    print_matrix(eigenvalues, "eigenvalue matrix");
    print_matrix(eigenvectors, "eigenvector matrix");
}             //to test
void test_inverse(const LaGenMatComplex& initialMatrix, const int size){
    LaGenMatComplex inverseMatrix;
    inverseMatrix = initialMatrix.copy();
    matrix_inverse(inverseMatrix, size);
    print_matrix(inverseMatrix, "inverse matrix");
}                 //to test
void test_scalar_sum(const int max_rand, const int iterations){
    COMPLEX number, step;
    generate_scalar(number, max_rand);
    step = number;
    for(int i = 0; i < iterations; i++){
        cout << step << endl;
        scalar_addition(number, step);
    }
    cout << number << endl;
}
void test_scalar_product(const int max_rand, const int iterations){
    //...
}
void test_scalar_exponential(const int iterations, const int max_rand){
    COMPLEX number, result;
    generate_scalar(number, max_rand);
    cout << endl << "scalar exponential test no.: " << number << endl << endl;
    scalar_exponential_main(number, iterations, result);
    cout << "e^" << number << " = " << result << endl;
}
void test_scalar_exponential(COMPLEX& number, const int iterations, COMPLEX& result){
    scalar_exponential_main(number, iterations, result);
    cout << "e^" << number << " = " << result << endl;
}
void test_matrix_exponential(const LaGenMatComplex& initialMatrix, const int size){
    //initialise eigenstuff
    LaVectorComplex eigenvalueVec = LaVectorComplex(size);
    LaGenMatComplex diagonaleigenexp = LaGenMatComplex::zeros(size, size);
    LaGenMatComplex eigenvectors = LaGenMatComplex::zeros(size, size);
    //calculate eigenstuff
    matrix_eigenvstuff(initialMatrix, eigenvalueVec, eigenvectors);
    print_matrix(eigenvalueVec, "eigenvalue vector");
    //calculate exponentials
    COMPLEX eigenexp[size];
    for(int i = 0; i < size; i++){
        test_scalar_exponential(eigenvalueVec(i), 5000, eigenexp[i]);
    }
    cout << endl;
    // save to diagonal
    array_to_diag(eigenexp, size, diagonaleigenexp);
    print_matrix(diagonaleigenexp, "exponential matrix");
    print_matrix(eigenvectors, "eigenvector matrix");}
void test_matrix_multiplication(matrix_size){

}
void test_idenpotent_exponential(){

    // Generate the matrix
    int elements [] = {2, -2, -4, -1, 3, 4, 1, -2, -3};
    COMPLEX comp[9];
    for(int i = 0; i < 9; i++){
        comp[i].r = elements[i];
        comp[i].i = 0;
    }
    LaGenMatComplex initialMatrix = LaGenMatComplex(comp, 3, 3, false );
    cout << "initialMatrix = " << endl << initialMatrix << endl;

    //calculate the exponential
}

/* Main Program */
int main(){
	int matrix_size = 3, max_rand = 9;
    int matrix_volume = matrix_size * matrix_size;

	/* generate the matrix */
    COMPLEX elements[matrix_volume];
    generate_array(elements, matrix_volume, max_rand);
	LaGenMatComplex initialMatrix = LaGenMatComplex(elements, matrix_size, matrix_size, false );

    print_matrix(initialMatrix, "initial matrix");

    /* test eigenvalues */
//    test_eigenvalues(initialMatrix, matrix_size);

    /* test scalar manipulation */
//    test_scalar_manipulation(4);

    /* test scalar exponentials */
//    test_scalar_exponential(5000,40);
    test_idenpotent_exponential();

    /* test matrix exponentials */
    //test_matrix_exponential(initialMatrix, matrix_size);

    /* test inversion */
//    test_inverse(initialMatrix, matrix_size);
}
<commit_msg>testing<commit_after>#include <iostream> //cout
#include <cstdlib>	//rand, sran
#include <string>
#include "complex_matrices.h"
#include <gmc.h> 	//LaGenMatComplex
#include <laslv.h>  //LUFactorizeIP, LaLUInverseIP, etc.
#include <blas3pp.h>
//#include <random>   //random_device, mt19937

using namespace std;

/* Total [13/20] */

int ran(int a, int b){
//    random_device rd;
//    mt19937 gen(rd());
//    uniform_int_distribution<> dist(a, b);
//    return dist(gen);
    return rand() % b;
}

/* Printing [6/9] */
void print_scalar(const COMPLEX scalar){
    cout << scalar << endl;
}                                                 //working
void print_scalar(const COMPLEX scalar, const string name){
    cout << name << ":" << scalar << endl;
}                              //working
void print_array(const COMPLEX array[], int len){
    for(int i = 0; i < len; i++){
        cout << array[i] << endl;
    }
}                                        //working
void print_array(const COMPLEX array[], int len, const string name){
	cout << name << ":" << endl;
    for(int i = 0; i < len; i++){
        cout << array[i] << endl;
    }
}                     //working
void print_matrix(const LaGenMatComplex& matrix){
	cout << matrix << endl;
}                                        //working
void print_matrix(const LaGenMatComplex& matrix, const string name){
	cout << name << ":" << endl << matrix << endl;
}			          //working

/* Number generation [2/2] */
void generate_scalar(COMPLEX& A, const int x){
    A.r = ran(1, x);	//1 to x
    A.i = ran(1, x);
}               //working
void generate_scalar(int number, const int x){
    number = ran(1, x);	//1 to x
}                                                //working
void generate_array(COMPLEX array[], const int len, const int x){
    for(int i = 0; i < len; i++){
        array[i].r = ran(1, x);	//1 to x
        array[i].i = ran(1, x);
	}
}                        //working

/* Matrix conversion [3/3] */
void vec_to_array(const LaVectorComplex& vector, const int len, COMPLEX array[ ]){
    for(int i = 0; i < len; i++){
        array[i] = vector(i);
    }
}       //working
void array_to_diag(COMPLEX array[], const int len, LaGenMatComplex& diag){
    diag = 0;
    for(int i = 0; i < len; i++){
        diag(i, i) = array[i];
    }
}               //working
void vec_to_diag(const LaVectorComplex& vector, const int len, LaGenMatComplex& diag){
    COMPLEX array[len];
    vec_to_array(vector, len, array);
    array_to_diag(array, len, diag);
}   //working

/* Scalar manipulation [5/8] */
int factorial(int x){
	if(x <= 1){
        return 1;
	}else{
        return x * factorial(x - 1);
	}
}                                                                    //working
void scalar_addition(const COMPLEX& A, const COMPLEX& B , COMPLEX& result){
    result.r = A.r + B.r;
    result.i = A.i + B.i;
}              //working
void scalar_addition(COMPLEX& result, const COMPLEX addition){
    result.r += addition.r;
    result.i += addition.i;
}
void scalar_multiplication(const COMPLEX& A, const int B, COMPLEX& result){
    result.r = A.r * B;
    result.i = A.i * B;
}              //to test
void scalar_multiplication(const COMPLEX& A, const COMPLEX& B, COMPLEX& result){
    la::complex<double> laA = la::complex<double>(A); //convert to la::complex<double>
    la::complex<double> laB = la::complex<double>(B);
    la::complex<double> laResult = la::complex<double>(result);
    laResult = laA * laB;
    result = laResult.toCOMPLEX();
}         //to test
void scalar_product(COMPLEX& total, const COMPLEX& number){
    COMPLEX part;
    part.r = (total.r * number.r) - (total.i * number.i);
    part.i = (total.r * number.i) + (total.i * number.r);
    total = part;
}
void scalar_division(const COMPLEX& A, const int B, COMPLEX& result){
    result.r = A.r / B;
    result.i = A.i / B;
}                    //to test
void scalar_division(const COMPLEX& A, const COMPLEX& B, COMPLEX& result){
    la::complex<double> laA = la::complex<double>(A); //convert to la::complex<double>
    la::complex<double> laB = la::complex<double>(B);
    la::complex<double> laResult = la::complex<double>(result);
    laResult = laA / laB;
    result = laResult.toCOMPLEX();
}               //to test
void scalar_powers(const COMPLEX& number, const int power, COMPLEX& result){
    la::complex<double> laResult = la::complex<double>(number);
    la::complex<double> laNumber = la::complex<double>(number);
    for(int i = 1; i < power; i++){
        laResult *= laNumber;
    }
    result = laResult.toCOMPLEX();
}             //to test
void scalar_exponential_main(const COMPLEX& number, const int iterations, COMPLEX& result){
    COMPLEX division, total_division;
    result.r = 1;
    result.i = 0 ;
    for(int step = 1; step <= iterations; step++){   //sum (from 1 to n)
        total_division.r = 1;
        total_division.i = 0;
        for(int i = 1; i <= step; i++){        //    ( num^n / n!)
            scalar_division(number, i, division);
            scalar_product(total_division, division);
        }
        scalar_addition(result, total_division);
    }
}
void scalar_exponential(const COMPLEX& number, const int iter, COMPLEX& result){
    //COMPLEX power;
    //COMPLEX division;
    //result.r = 0;
    //result.i = 0;
    //for(int i = 0; i < iter; i++){
    //    scalar_powers(number, i, power);
    //    scalar_division(power, factorial(i), division);
    //    scalar_addition(result, division, result);
    //}
}         //empty
//COMPLEX rec_scalar_exp_step(const COMPLEX& number, const int step){
//    COMPLEX result, division, multiplication;
//	if(step <= 1){
//        result.r = 1;
//        return result;
//	}else{
//        scalar_division(number,step,division);
//        scalar_multiplication(division, rec_scalar_exp_step(step-1),  multiplication);
//        return multiplication;
//	}
//}
void recursive_scalar_exponential(const COMPLEX& number, const int iter, COMPLEX& result){
    //COMPLEX power;
    //COMPLEX division;
    //result.r = 0;
    //result.i = 0;
    //for(int i = 0; i < iter; i++){
    //    scalar_powers(number, i, power);
    //    scalar_division(power, factorial(i), division);
    //    scalar_addition(result, division, result);
    //}
} //empty

/* array manipulation [0/1] */
void array_powers(COMPLEX array[], const int len, const int power){/**/
    /*
    for(int i = 0; i < len; i++){
        array[i] = complex_power(array[i], power, result);
    }
    */
}                       //empty

/* Matrix manipulation [2/4] */
void diagonal_matrix_powers(){      //empty
  //...
}
void matrix_multiplication(){

}
void matrix_eigenvstuff(const LaGenMatComplex& matrix, LaVectorComplex& eigenvalues, LaGenMatComplex& eigenvectors){ //working
    //LaEigSolve: http://lapackpp.sourceforge.net/html/laslv_8h.html#086357d17e9cdcaec69ab7db76998769
    LaEigSolve(matrix, eigenvalues, eigenvectors);
}
void matrix_inverse(LaGenMatComplex& matrix, int len){                                                               //working
    // LaLUInverseIP: http://lapackpp.sourceforge.net/html/laslv_8h.html#a042c82c5b818f54e7f000d068f14189
    LaVectorLongInt PIV = LaVectorLongInt(len);
    LUFactorizeIP(matrix, PIV);
    LaLUInverseIP(matrix, PIV);
}
void matrix_exp_step(){                                 //empty
    //
}
void matrix_exponential(const LaGenMatComplex& eigenvectors, const LaGenMatComplex& eigenvalues){
    //LaGenMatComplex step = LaGenMatComplex

} //empty

/* Testing [3/3] */
void test_scalar_manipulation(const int max_rand){
    COMPLEX compA;
    generate_scalar(compA, max_rand);
    COMPLEX compB;
    generate_scalar(compB, max_rand);
    int realB;
    generate_scalar(realB, max_rand);
    COMPLEX result;

    cout << "compA = " << compA << endl;
    cout << "compB = " << compB << endl;
    cout << "realB = " << realB << endl;
    cout << endl;

    for(int i = 1; i < 5; i++){                                                 //factorials
        cout << "factorial(" << i << "): " << factorial(i) << endl;
    }

    scalar_addition(compA, compB, result);                                      //addition/subtraction
    cout << "scalar addition: " << result << endl << endl;

    scalar_multiplication(compA, realB, result);                                //multiplication
    cout << "scalar multiplication by scalar: " << result << endl << endl;

    scalar_multiplication(compA, compB, result);
    cout << "scalar multiplication by complex: " << result << endl << endl;

    scalar_division(compA, realB, result);         //division
    cout << "scalar division by scalar: " << result << endl << endl;

    scalar_division(compA, compB, result);
    cout << "scalar division by complex: " << result << endl << endl;

    for(int i = 1; i < 5; i++){
        scalar_powers(compA, i, result);
        cout << "scalar powers - A^" << i << " = " << result << endl;
    }
    cout << endl;

    COMPLEX sum;
    sum.r = 0;
    sum.i = 0;
    for(int i = 0; i < 5; i++){
        cout << "sum(" << i << ") = " << sum << endl;
        scalar_addition(sum, compA);
    }
    cout << "sum = " << sum << endl;

}                                       //to test
void test_eigenvalues(const LaGenMatComplex& initialMatrix, const int size){
    LaVectorComplex eigenvalueVec = LaVectorComplex(size);             //initialise eigenstuff
    LaGenMatComplex eigenvalues = LaGenMatComplex::zeros(size, size);
    LaGenMatComplex eigenvectors = LaGenMatComplex::zeros(size, size);
    matrix_eigenvstuff(initialMatrix, eigenvalueVec, eigenvectors); //calculate eigenstuff
    print_matrix(eigenvalueVec, "eigenvalue vector");               //print eigenstuff
    vec_to_diag(eigenvalueVec, size, eigenvalues);
    print_matrix(eigenvalues, "eigenvalue matrix");
    print_matrix(eigenvectors, "eigenvector matrix");
}             //to test
void test_inverse(const LaGenMatComplex& initialMatrix, const int size){
    LaGenMatComplex inverseMatrix;
    inverseMatrix = initialMatrix.copy();
    matrix_inverse(inverseMatrix, size);
    print_matrix(inverseMatrix, "inverse matrix");
}                 //to test
void test_scalar_sum(const int max_rand, const int iterations){
    COMPLEX number, step;
    generate_scalar(number, max_rand);
    step = number;
    for(int i = 0; i < iterations; i++){
        cout << step << endl;
        scalar_addition(number, step);
    }
    cout << number << endl;
}
void test_scalar_product(const int max_rand, const int iterations){
    //...
}
void test_scalar_exponential(const int iterations, const int max_rand){
    COMPLEX number, result;
    generate_scalar(number, max_rand);
    cout << endl << "scalar exponential test no.: " << number << endl << endl;
    scalar_exponential_main(number, iterations, result);
    cout << "e^" << number << " = " << result << endl;
}
void test_scalar_exponential(COMPLEX& number, const int iterations, COMPLEX& result){
    scalar_exponential_main(number, iterations, result);
    cout << "e^" << number << " = " << result << endl;
}
void test_matrix_exponential(const LaGenMatComplex& initialMatrix, const int size){
    //initialise eigenstuff
    LaVectorComplex eigenvalueVec = LaVectorComplex(size);
    LaGenMatComplex diagonaleigenexp = LaGenMatComplex::zeros(size, size);
    LaGenMatComplex eigenvectors = LaGenMatComplex::zeros(size, size);
    //calculate eigenstuff
    matrix_eigenvstuff(initialMatrix, eigenvalueVec, eigenvectors);
    print_matrix(eigenvalueVec, "eigenvalue vector");
    //calculate exponentials
    COMPLEX eigenexp[size];
    for(int i = 0; i < size; i++){
        test_scalar_exponential(eigenvalueVec(i), 5000, eigenexp[i]);
    }
    cout << endl;
    // save to diagonal
    array_to_diag(eigenexp, size, diagonaleigenexp);
    print_matrix(diagonaleigenexp, "exponential matrix");
    print_matrix(eigenvectors, "eigenvector matrix");}
void test_matrix_multiplication(matrix_size){

}
void test_idenpotent_exponential(){

    // Generate the matrix
    int elements [] = {2, -2, -4, -1, 3, 4, 1, -2, -3};
    COMPLEX comp[9];
    for(int i = 0; i < 9; i++){
        comp[i].r = elements[i];
        comp[i].i = 0;
    }
    LaGenMatComplex initialMatrix = LaGenMatComplex(comp, 3, 3, false );
    cout << "initialMatrix = " << endl << initialMatrix << endl;

    //calculate the exponential
}

/* Main Program */
int main(){
//	int matrix_size = 3, max_rand = 9;
//    int matrix_volume = matrix_size * matrix_size;

	/* generate the matrix */
//    COMPLEX elements[matrix_volume];
//    generate_array(elements, matrix_volume, max_rand);
//	LaGenMatComplex initialMatrix = LaGenMatComplex(elements, matrix_size, matrix_size, false );

//    print_matrix(initialMatrix, "initial matrix");

    /* test eigenvalues */
//    test_eigenvalues(initialMatrix, matrix_size);

    /* test scalar manipulation */
//    test_scalar_manipulation(4);

    /* test scalar exponentials */
//    test_scalar_exponential(5000,40);
    test_idenpotent_exponential();

    /* test matrix exponentials */
    //test_matrix_exponential(initialMatrix, matrix_size);

    /* test inversion */
//    test_inverse(initialMatrix, matrix_size);
}
<|endoftext|>


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

#include <stdio.h>

#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
#include "connectivity/CommonTools.hxx"
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include "connectivity/dbtools.hxx"
#endif
#ifndef _COM_SUN_STAR_UTIL_DATE_HPP_
#include <com/sun/star/util/Date.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_TIME_HPP_
#include <com/sun/star/util/Time.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_
#include <com/sun/star/util/DateTime.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
#include <com/sun/star/lang/XComponent.hpp>
#endif
#ifndef _COMPHELPER_EXTRACT_HXX_
#include <comphelper/extract.hxx>
#endif
#ifndef _CPPUHELPER_INTERFACECONTAINER_H_
#include <cppuhelper/interfacecontainer.h>
#endif
#ifndef CONNECTIVITY_CONNECTION_HXX
#include "TConnection.hxx"
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif

using namespace ::comphelper;
inline sal_Unicode rtl_ascii_toUpperCase( sal_Unicode ch )
{
    return ch >= 0x0061 && ch <= 0x007a ? ch + 0x20 : ch;
}

namespace connectivity
{
    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;
    using namespace dbtools;
    //------------------------------------------------------------------------------
    const sal_Unicode CHAR_PLACE = '_';
    const sal_Unicode CHAR_WILD  = '%';
    // -------------------------------------------------------------------------
    sal_Bool match(const sal_Unicode* pWild, const sal_Unicode* pStr, const sal_Unicode cEscape)
    {
        int    pos=0;
        int    flag=0;

        while ( *pWild || flag )
        {
            switch (*pWild)
            {
                case CHAR_PLACE:
                    if ( *pStr == 0 )
                        return sal_False;
                    break;
                default:
                    if (*pWild && (*pWild == cEscape) && ((*(pWild+1)== CHAR_PLACE) || (*(pWild+1) == CHAR_WILD)) )
                        pWild++;
                    if ( rtl_ascii_toUpperCase(*pWild) != rtl_ascii_toUpperCase(*pStr) )
                        if ( !pos )
                            return sal_False;
                        else
                            pWild += pos;
                    else
                        break;          // ACHTUNG laeuft unter bestimmten
                                        // Umstaenden in den nachsten case rein!!
                case CHAR_WILD:
                    while ( *pWild == CHAR_WILD )
                        pWild++;
                    if ( *pWild == 0 )
                        return sal_True;
                    flag = 1;
                    pos  = 0;
                    if ( *pStr == 0 )
                        return ( *pWild == 0 );
                    while ( *pStr && *pStr != *pWild )
                    {
                        if ( *pWild == CHAR_PLACE ) {
                            pWild++;
                            while ( *pWild == CHAR_WILD )
                                pWild++;
                        }
                        pStr++;
                        if ( *pStr == 0 )
                            return ( *pWild == 0 );
                    }
                    break;
            }
            if ( *pWild != 0 )
                pWild++;
            if ( *pStr != 0 )
                pStr++;
            else
                flag = 0;
            if ( flag )
                pos--;
        }
        return ( *pStr == 0 ) && ( *pWild == 0 );
    }
    //------------------------------------------------------------------
    rtl::OUString toDateString(const ::com::sun::star::util::Date& rDate)
    {
        sal_Char s[11];
        snprintf(s,
                sizeof(s),
                "%04d-%02d-%02d",
                (int)rDate.Year,
                (int)rDate.Month,
                (int)rDate.Day);
        s[10] = 0;
        return rtl::OUString::createFromAscii(s);
    }

    //------------------------------------------------------------------
    rtl::OUString toTimeString(const ::com::sun::star::util::Time& rTime)
    {
        sal_Char s[9];
        snprintf(s,
                sizeof(s),
                "%02d:%02d:%02d",
                (int)rTime.Hours,
                (int)rTime.Minutes,
                (int)rTime.Seconds);
        s[8] = 0;
        return rtl::OUString::createFromAscii(s);
    }

    //------------------------------------------------------------------
    rtl::OUString toDateTimeString(const ::com::sun::star::util::DateTime& rDateTime)
    {
        sal_Char s[21];
        snprintf(s,
                sizeof(s),
                "%04d-%02d-%02d %02d:%02d:%02d",
                (int)rDateTime.Year,
                (int)rDateTime.Month,
                (int)rDateTime.Day,
                (int)rDateTime.Hours,
                (int)rDateTime.Minutes,
                (int)rDateTime.Seconds);
        s[20] = 0;
        return rtl::OUString::createFromAscii(s);
    }

    //--------------------------------------------------------------------------------------------------
    rtl::OUString toString(const Any& rValue)
    {
        rtl::OUString aRes;
        TypeClass aDestinationClass = rValue.getValueType().getTypeClass();

        switch (aDestinationClass)
        {
            case TypeClass_CHAR:
                aRes = ::rtl::OUString::valueOf(*(sal_Unicode*)rValue.getValue());
                break;
            case TypeClass_FLOAT:
                aRes = ::rtl::OUString::valueOf(*(float*)rValue.getValue());
                break;
            case TypeClass_DOUBLE:
                aRes = ::rtl::OUString::valueOf(*(double*)rValue.getValue());
                break;
            case TypeClass_BOOLEAN:
                aRes = ::rtl::OUString::valueOf((sal_Int32)*(sal_Bool*)rValue.getValue());
                break;
            case TypeClass_BYTE:
            case TypeClass_SHORT:
            case TypeClass_LONG:
                aRes = ::rtl::OUString::valueOf(*(sal_Int32*)rValue.getValue());
                break;
            case TypeClass_STRING:
                rValue >>= aRes;
                break;
            case TypeClass_STRUCT:
                if (rValue.getValueType() == ::getCppuType((const ::com::sun::star::util::Date*)0))
                {
                    ::com::sun::star::util::Date aDate;
                    rValue >>= aDate;
                    aRes = toDateString(aDate);
                }
                else if (rValue.getValueType() == ::getCppuType((const ::com::sun::star::util::DateTime*)0))
                {
                    ::com::sun::star::util::DateTime aDT;
                    rValue >>= aDT;
                    aRes = toDateTimeString(aDT);
                }
                else if (rValue.getValueType() == ::getCppuType((const ::com::sun::star::util::Time*)0))
                {
                    ::com::sun::star::util::Time aTime;
                    rValue >>= aTime;
                    aRes = toTimeString(aTime);
                }

                break;
            default:
                ;
//              throw( CannotConvertException( ::rtl::OUString::createFromAscii("TYPE is not supported!"), Reference< XInterface > (),
//                                         aDestinationClass, FailReason::TYPE_NOT_SUPPORTED, 0 ) );

        }
        return aRes;
    }

}

#include <ctype.h>      //isdigit
namespace dbtools
{
sal_Bool isCharOk(char c,const ::rtl::OUString& _rSpecials);

//------------------------------------------------------------------------------
sal_Bool isValidSQLName(const ::rtl::OUString& rName,const ::rtl::OUString& _rSpecials)
{
    // berprfung auf korrekte Namensgebung im SQL Sinne
    // Dieses ist wichtig fr Tabellennamen beispielsweise
    ::rtl::OString aName(rName,rName.getLength(),RTL_TEXTENCODING_ASCII_US);
    const char* pStr = aName.getStr();
    if (isdigit(*pStr))
        return sal_False;

    for (; *pStr; ++pStr )
        if(!isCharOk(*pStr,_rSpecials))
            return sal_False;

    if  (   rName.getLength()
        &&  (   (rName.toChar() == '_')
            ||  (   (rName.toChar() >= '0')
                &&  (rName.toChar() <= '9')
                )
            )
        )
        return sal_False;
    // the SQL-Standard requires the first character to be an alphabetic character, which
    // isn't easy to decide in UniCode ...
    // So we just prohibit the characters which already lead to problems ....
    // 11.04.00 - 74902 - FS

    return sal_True;
}
//------------------------------------------------------------------
sal_Bool isCharOk(char c,const ::rtl::OUString& _rSpecials)
{

    return ( ((c >= 97) && (c <= 122)) || ((c >= 65) && (c <=  90)) || ((c >= 48) && (c <=  57)) ||
          c == '_' || _rSpecials.indexOf(c) != -1);
}
//------------------------------------------------------------------
// Erzeugt einen neuen Namen falls noetig
::rtl::OUString convertName2SQLName(const ::rtl::OUString& rName,const ::rtl::OUString& _rSpecials)
{
    if(isValidSQLName(rName,_rSpecials))
        return rName;
    ::rtl::OUString aNewName(rName);
    const sal_Unicode* pStr = rName.getStr();
    sal_Int32 nLength = rName.getLength();
    sal_Bool bValid(!isdigit(*pStr));
    for (sal_Int32 i=0; bValid && i < nLength; ++pStr,++i )
        if(!isCharOk(*pStr,_rSpecials))
        {
            aNewName = aNewName.replace(*pStr,'_');
            pStr = aNewName.getStr() + i;
        }

    if ( !bValid )
        aNewName = ::rtl::OUString();

    return aNewName;
}
//------------------------------------------------------------------------------
::rtl::OUString quoteName(const ::rtl::OUString& _rQuote, const ::rtl::OUString& _rName)
{
    ::rtl::OUString sName = _rName;
    if(_rQuote.getLength() && _rQuote.toChar() != ' ')
        sName = _rQuote + _rName + _rQuote;
    return sName;
}
// -----------------------------------------------------------------------------

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

#include <stdio.h>

#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
#include "connectivity/CommonTools.hxx"
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include "connectivity/dbtools.hxx"
#endif
#ifndef _COM_SUN_STAR_UTIL_DATE_HPP_
#include <com/sun/star/util/Date.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_TIME_HPP_
#include <com/sun/star/util/Time.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_
#include <com/sun/star/util/DateTime.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
#include <com/sun/star/lang/XComponent.hpp>
#endif
#ifndef _COMPHELPER_EXTRACT_HXX_
#include <comphelper/extract.hxx>
#endif
#ifndef _CPPUHELPER_INTERFACECONTAINER_H_
#include <cppuhelper/interfacecontainer.h>
#endif
#ifndef CONNECTIVITY_CONNECTION_HXX
#include "TConnection.hxx"
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif

using namespace ::comphelper;
inline sal_Unicode rtl_ascii_toUpperCase( sal_Unicode ch )
{
    return ch >= 0x0061 && ch <= 0x007a ? ch + 0x20 : ch;
}

namespace connectivity
{
    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;
    using namespace dbtools;
    //------------------------------------------------------------------------------
    const sal_Unicode CHAR_PLACE = '_';
    const sal_Unicode CHAR_WILD  = '%';
    // -------------------------------------------------------------------------
    sal_Bool match(const sal_Unicode* pWild, const sal_Unicode* pStr, const sal_Unicode cEscape)
    {
        int    pos=0;
        int    flag=0;

        while ( *pWild || flag )
        {
            switch (*pWild)
            {
                case CHAR_PLACE:
                    if ( *pStr == 0 )
                        return sal_False;
                    break;
                default:
                    if (*pWild && (*pWild == cEscape) && ((*(pWild+1)== CHAR_PLACE) || (*(pWild+1) == CHAR_WILD)) )
                        pWild++;
                    if ( rtl_ascii_toUpperCase(*pWild) != rtl_ascii_toUpperCase(*pStr) )
                        if ( !pos )
                            return sal_False;
                        else
                            pWild += pos;
                    else
                        break;          // ACHTUNG laeuft unter bestimmten
                                        // Umstaenden in den nachsten case rein!!
                case CHAR_WILD:
                    while ( *pWild == CHAR_WILD )
                        pWild++;
                    if ( *pWild == 0 )
                        return sal_True;
                    flag = 1;
                    pos  = 0;
                    if ( *pStr == 0 )
                        return ( *pWild == 0 );
                    while ( *pStr && *pStr != *pWild )
                    {
                        if ( *pWild == CHAR_PLACE ) {
                            pWild++;
                            while ( *pWild == CHAR_WILD )
                                pWild++;
                        }
                        pStr++;
                        if ( *pStr == 0 )
                            return ( *pWild == 0 );
                    }
                    break;
            }
            if ( *pWild != 0 )
                pWild++;
            if ( *pStr != 0 )
                pStr++;
            else
                flag = 0;
            if ( flag )
                pos--;
        }
        return ( *pStr == 0 ) && ( *pWild == 0 );
    }
    //------------------------------------------------------------------
    rtl::OUString toDateString(const ::com::sun::star::util::Date& rDate)
    {
        sal_Char s[11];
        snprintf(s,
                sizeof(s),
                "%04d-%02d-%02d",
                (int)rDate.Year,
                (int)rDate.Month,
                (int)rDate.Day);
        s[10] = 0;
        return rtl::OUString::createFromAscii(s);
    }

    //------------------------------------------------------------------
    rtl::OUString toTimeString(const ::com::sun::star::util::Time& rTime)
    {
        sal_Char s[9];
        snprintf(s,
                sizeof(s),
                "%02d:%02d:%02d",
                (int)rTime.Hours,
                (int)rTime.Minutes,
                (int)rTime.Seconds);
        s[8] = 0;
        return rtl::OUString::createFromAscii(s);
    }

    //------------------------------------------------------------------
    rtl::OUString toDateTimeString(const ::com::sun::star::util::DateTime& rDateTime)
    {
        sal_Char s[21];
        snprintf(s,
                sizeof(s),
                "%04d-%02d-%02d %02d:%02d:%02d",
                (int)rDateTime.Year,
                (int)rDateTime.Month,
                (int)rDateTime.Day,
                (int)rDateTime.Hours,
                (int)rDateTime.Minutes,
                (int)rDateTime.Seconds);
        s[20] = 0;
        return rtl::OUString::createFromAscii(s);
    }

    //--------------------------------------------------------------------------------------------------
    rtl::OUString toString(const Any& rValue)
    {
        rtl::OUString aRes;
        TypeClass aDestinationClass = rValue.getValueType().getTypeClass();

        switch (aDestinationClass)
        {
            case TypeClass_CHAR:
                aRes = ::rtl::OUString::valueOf(*(sal_Unicode*)rValue.getValue());
                break;
            case TypeClass_FLOAT:
                aRes = ::rtl::OUString::valueOf(*(float*)rValue.getValue());
                break;
            case TypeClass_DOUBLE:
                aRes = ::rtl::OUString::valueOf(*(double*)rValue.getValue());
                break;
            case TypeClass_BOOLEAN:
                aRes = ::rtl::OUString::valueOf((sal_Int32)*(sal_Bool*)rValue.getValue());
                break;
            case TypeClass_BYTE:
            case TypeClass_SHORT:
            case TypeClass_LONG:
                aRes = ::rtl::OUString::valueOf(*(sal_Int32*)rValue.getValue());
                break;
            case TypeClass_STRING:
                rValue >>= aRes;
                break;
            case TypeClass_STRUCT:
                if (rValue.getValueType() == ::getCppuType((const ::com::sun::star::util::Date*)0))
                {
                    ::com::sun::star::util::Date aDate;
                    rValue >>= aDate;
                    aRes = toDateString(aDate);
                }
                else if (rValue.getValueType() == ::getCppuType((const ::com::sun::star::util::DateTime*)0))
                {
                    ::com::sun::star::util::DateTime aDT;
                    rValue >>= aDT;
                    aRes = toDateTimeString(aDT);
                }
                else if (rValue.getValueType() == ::getCppuType((const ::com::sun::star::util::Time*)0))
                {
                    ::com::sun::star::util::Time aTime;
                    rValue >>= aTime;
                    aRes = toTimeString(aTime);
                }

                break;
            default:
                ;
//              throw( CannotConvertException( ::rtl::OUString::createFromAscii("TYPE is not supported!"), Reference< XInterface > (),
//                                         aDestinationClass, FailReason::TYPE_NOT_SUPPORTED, 0 ) );

        }
        return aRes;
    }

}

#include <ctype.h>      //isdigit
namespace dbtools
{
sal_Bool isCharOk(char c,const ::rtl::OUString& _rSpecials);

//------------------------------------------------------------------------------
sal_Bool isValidSQLName(const ::rtl::OUString& rName,const ::rtl::OUString& _rSpecials)
{
    // berprfung auf korrekte Namensgebung im SQL Sinne
    // Dieses ist wichtig fr Tabellennamen beispielsweise
    ::rtl::OString aName(rName,rName.getLength(),RTL_TEXTENCODING_ASCII_US);
    const char* pStr = aName.getStr();
    if (isdigit(*pStr))
        return sal_False;

    for (; *pStr; ++pStr )
        if(!isCharOk(*pStr,_rSpecials))
            return sal_False;

    if  (   rName.getLength()
        &&  (   (rName.toChar() == '_')
            ||  (   (rName.toChar() >= '0')
                &&  (rName.toChar() <= '9')
                )
            )
        )
        return sal_False;
    // the SQL-Standard requires the first character to be an alphabetic character, which
    // isn't easy to decide in UniCode ...
    // So we just prohibit the characters which already lead to problems ....
    // 11.04.00 - 74902 - FS

    return sal_True;
}
//------------------------------------------------------------------
sal_Bool isCharOk(char c,const ::rtl::OUString& _rSpecials)
{

    return ( ((c >= 97) && (c <= 122)) || ((c >= 65) && (c <=  90)) || ((c >= 48) && (c <=  57)) ||
          c == '_' || _rSpecials.indexOf(c) != -1);
}
//------------------------------------------------------------------
// Erzeugt einen neuen Namen falls noetig
::rtl::OUString convertName2SQLName(const ::rtl::OUString& rName,const ::rtl::OUString& _rSpecials)
{
    if(isValidSQLName(rName,_rSpecials))
        return rName;
    ::rtl::OUString aNewName(rName);
    const sal_Unicode* pStr = rName.getStr();
    sal_Int32 nLength = rName.getLength();
    sal_Bool bValid(!isdigit(*pStr));
    for (sal_Int32 i=0; bValid && i < nLength; ++pStr,++i )
        if(!isCharOk(*pStr,_rSpecials))
        {
            aNewName = aNewName.replace(*pStr,'_');
            pStr = aNewName.getStr() + i;
        }

    if ( !bValid )
        aNewName = ::rtl::OUString();

    return aNewName;
}
//------------------------------------------------------------------------------
::rtl::OUString quoteName(const ::rtl::OUString& _rQuote, const ::rtl::OUString& _rName)
{
    ::rtl::OUString sName = _rName;
    if(_rQuote.getLength() && _rQuote.toChar() != ' ')
        sName = _rQuote + _rName + _rQuote;
    return sName;
}
// -----------------------------------------------------------------------------

}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: KConnection.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: obo $ $Date: 2005-12-19 16:49:11 $
 *
 *  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 _CONNECTIVITY_KAB_CONNECTION_HXX_
#define _CONNECTIVITY_KAB_CONNECTION_HXX_

#include <map>
#include <kabc/stdaddressbook.h>

#ifndef _CONNECTIVITY_OSUBCOMPONENT_HXX_
#include "OSubComponent.hxx"
#endif
#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
#include "connectivity/CommonTools.hxx"
#endif
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_SQLWARNING_HPP_
#include <com/sun/star/sdbc/SQLWarning.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XWARNINGSSUPPLIER_HPP_
#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
#include <com/sun/star/sdbc/XConnection.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#endif
#ifndef _COMPHELPER_BROADCASTHELPER_HXX_
#include <comphelper/broadcasthelper.hxx>
#endif
#ifndef _CPPUHELPER_COMPBASE3_HXX_
#include <cppuhelper/compbase3.hxx>
#endif

namespace connectivity
{
    namespace kab
    {

        typedef ::cppu::WeakComponentImplHelper3<   ::com::sun::star::sdbc::XConnection,
                                                ::com::sun::star::sdbc::XWarningsSupplier,
                                                ::com::sun::star::lang::XServiceInfo
                                            > OMetaConnection_BASE;

        class KabStatement_Base;
        class KabDriver;
        class KabDatabaseMetaData;

        typedef OMetaConnection_BASE                KabConnection_BASE; // implements basics and text encoding
        typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;

        class KabConnection : public comphelper::OBaseMutex,
                            public KabConnection_BASE,
                            public OSubComponent<KabConnection, KabConnection_BASE>
        {
            friend class OSubComponent<KabConnection, KabConnection_BASE>;

        protected:
            //====================================================================
            // Data attributes
            //====================================================================
            ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData;

            OWeakRefArray                           m_aStatements;  // vector containing a list of all the Statement objects
                                                                    // for this Connection

            ::KABC::StdAddressBook*                 m_pAddressBook; // the address book
            KabDriver*                              m_pDriver;      // pointer to the owning driver object
            ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier>
                                                    m_xCatalog;     // needed for the SQL interpreter

        public:
            virtual void construct( const ::rtl::OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info) throw(::com::sun::star::sdbc::SQLException);

            KabConnection(KabDriver* _pDriver);
            virtual ~KabConnection();

            void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException);

            // OComponentHelper
            virtual void SAL_CALL disposing(void);

            // XInterface
            virtual void SAL_CALL release() throw();

            // XServiceInfo
            DECLARE_SERVICE_INFO();

            // XConnection
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL getAutoCommit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL commit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL rollback(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL isClosed(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL isReadOnly(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::rtl::OUString SAL_CALL getCatalog(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Int32 SAL_CALL getTransactionIsolation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTypeMap(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL setTypeMap( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

            // XCloseable
            virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

            // XWarningsSupplier
            virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

            // needed for the SQL interpreter
            ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > SAL_CALL createCatalog();

            // accessors
            inline KabDriver*           getDriver()         const { return m_pDriver;}
            inline ::KABC::AddressBook* getAddressBook()    const { return m_pAddressBook; }
        };
    }
}

#endif // _CONNECTIVITY_KAB_CONNECTION_HXX_
<commit_msg>INTEGRATION: CWS dba202e (1.2.14); FILE MERGED 2006/01/10 14:23:17 fs 1.2.14.1: copying fixes for #i59673# and #i60062# to this (earlier) CWS<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: KConnection.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: obo $ $Date: 2006-01-19 15:30:40 $
 *
 *  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 _CONNECTIVITY_KAB_CONNECTION_HXX_
#define _CONNECTIVITY_KAB_CONNECTION_HXX_

#include <map>

#ifndef _CONNECTIVITY_OSUBCOMPONENT_HXX_
#include "OSubComponent.hxx"
#endif
#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
#include "connectivity/CommonTools.hxx"
#endif
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_SQLWARNING_HPP_
#include <com/sun/star/sdbc/SQLWarning.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XWARNINGSSUPPLIER_HPP_
#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
#include <com/sun/star/sdbc/XConnection.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#endif
#ifndef _COMPHELPER_BROADCASTHELPER_HXX_
#include <comphelper/broadcasthelper.hxx>
#endif
#ifndef _CPPUHELPER_COMPBASE3_HXX_
#include <cppuhelper/compbase3.hxx>
#endif

namespace KABC
{
    class StdAddressBook;
    class AddressBook;
}

namespace connectivity
{
    namespace kab
    {

        typedef ::cppu::WeakComponentImplHelper3<   ::com::sun::star::sdbc::XConnection,
                                                ::com::sun::star::sdbc::XWarningsSupplier,
                                                ::com::sun::star::lang::XServiceInfo
                                            > OMetaConnection_BASE;

        class KabStatement_Base;
        class KabDriver;
        class KabDatabaseMetaData;

        typedef OMetaConnection_BASE                KabConnection_BASE; // implements basics and text encoding
        typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;

        class KabConnection : public comphelper::OBaseMutex,
                            public KabConnection_BASE,
                            public OSubComponent<KabConnection, KabConnection_BASE>
        {
            friend class OSubComponent<KabConnection, KabConnection_BASE>;

        protected:
            //====================================================================
            // Data attributes
            //====================================================================
            ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData;

            OWeakRefArray                           m_aStatements;  // vector containing a list of all the Statement objects
                                                                    // for this Connection

            ::KABC::StdAddressBook*                 m_pAddressBook; // the address book
            KabDriver*                              m_pDriver;      // pointer to the owning driver object
            ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier>
                                                    m_xCatalog;     // needed for the SQL interpreter

        public:
            virtual void construct( const ::rtl::OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info) throw(::com::sun::star::sdbc::SQLException);

            KabConnection(KabDriver* _pDriver);
            virtual ~KabConnection();

            void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException);

            // OComponentHelper
            virtual void SAL_CALL disposing(void);

            // XInterface
            virtual void SAL_CALL release() throw();

            // XServiceInfo
            DECLARE_SERVICE_INFO();

            // XConnection
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL getAutoCommit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL commit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL rollback(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL isClosed(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL isReadOnly(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::rtl::OUString SAL_CALL getCatalog(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Int32 SAL_CALL getTransactionIsolation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTypeMap(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL setTypeMap( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

            // XCloseable
            virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

            // XWarningsSupplier
            virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

            // needed for the SQL interpreter
            ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > SAL_CALL createCatalog();

            // accessors
            inline KabDriver*           getDriver()         const { return m_pDriver;}
                   ::KABC::AddressBook* getAddressBook()    const;
        };
    }
}

#endif // _CONNECTIVITY_KAB_CONNECTION_HXX_
<|endoftext|>


<commit_before><commit_msg>Fix: create TArrayI directly instead of calloc/adopt<commit_after><|endoftext|>


<commit_before>/*
This header should be the first header in each source file,
and should only be included once
*/

#define __STDC_LIMIT_MACROS // necessary for INTPTR_MAX and INTPTR_MIN

#include<boost/scoped_ptr.hpp>
#include<boost/shared_ptr.hpp>

#ifndef DEFINE_GLOBALS

class SymbolsTable;
class Symbol;
class AllWorkers;
class IOPort;

extern boost::scoped_ptr<SymbolsTable> symbols;
extern Symbol* symbol_sym;
extern Symbol* symbol_int;
extern Symbol* symbol_char;
extern Symbol* symbol_cons;
extern Symbol* symbol_pid;
extern Symbol* symbol_fn;
extern Symbol* symbol_string;
extern Symbol* symbol_unspecified;
extern Symbol* symbol_float;
extern Symbol* symbol_array;
extern Symbol* symbol_table;
extern Symbol* symbol_container;
extern Symbol* symbol_bytecode;
extern Symbol* symbol_ioport;
extern Symbol* symbol_event;
extern Symbol* symbol_binobj;
extern Symbol* symbol_io;
extern Symbol* symbol_call_star;
extern boost::scoped_ptr<AllWorkers> workers;

extern boost::shared_ptr<IOPort> port_stdin;
extern boost::shared_ptr<IOPort> port_stdout;
extern boost::shared_ptr<IOPort> port_stderr;

#ifndef single_threaded
	extern bool single_threaded;
#endif

void initialize_globals(void);

#endif

<commit_msg>inc/all_defines.hpp: Removed declaration of workers global<commit_after>/*
This header should be the first header in each source file,
and should only be included once
*/

#define __STDC_LIMIT_MACROS // necessary for INTPTR_MAX and INTPTR_MIN

#include<boost/scoped_ptr.hpp>
#include<boost/shared_ptr.hpp>

#ifndef DEFINE_GLOBALS

class SymbolsTable;
class Symbol;
class IOPort;

extern boost::scoped_ptr<SymbolsTable> symbols;
extern Symbol* symbol_sym;
extern Symbol* symbol_int;
extern Symbol* symbol_char;
extern Symbol* symbol_cons;
extern Symbol* symbol_pid;
extern Symbol* symbol_fn;
extern Symbol* symbol_string;
extern Symbol* symbol_unspecified;
extern Symbol* symbol_float;
extern Symbol* symbol_array;
extern Symbol* symbol_table;
extern Symbol* symbol_container;
extern Symbol* symbol_bytecode;
extern Symbol* symbol_ioport;
extern Symbol* symbol_event;
extern Symbol* symbol_binobj;
extern Symbol* symbol_io;
extern Symbol* symbol_call_star;

extern boost::shared_ptr<IOPort> port_stdin;
extern boost::shared_ptr<IOPort> port_stdout;
extern boost::shared_ptr<IOPort> port_stderr;

#ifndef single_threaded
	extern bool single_threaded;
#endif

void initialize_globals(void);

#endif

<|endoftext|>


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

  Program:   Visualization Toolkit
  Module:    OglrRenW.hh
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

This file is part of the Visualization Toolkit. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994

=========================================================================*/
// .NAME vtkOglrRenderWindow - SGI OpenGL rendering window
// .SECTION Description
// vtkOglrRenderWindow is a concrete implementation of the abstract class
// vtkRenderWindow. vtkOglrRenderer interfaces to the Silicon Graphics
// OpenGL graphics library.

#ifndef __vtkOglrRenderWindow_hh
#define __vtkOglrRenderWindow_hh

#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "XRenWin.hh"
#include "GL/glx.h"

class vtkOglrRenderWindow : public vtkXRenderWindow
{
protected:
  GLXContext ContextId;
  int MultiSamples;
  long OldMonitorSetting;

public:
  vtkOglrRenderWindow();
  char *GetClassName() {return "vtkOglrRenderWindow";};
  void PrintSelf(ostream& os, vtkIndent indent);

  vtkRenderer  *MakeRenderer();
  vtkLightDevice     *MakeLight();
  vtkCameraDevice    *MakeCamera();
  vtkTextureDevice   *MakeTexture();
  vtkPropertyDevice  *MakeProperty();

  void Start(void);
  void Frame(void);
  void Connect(void);
  void WindowConfigure(void);
  void WindowInitialize(void);
  void Initialize(void);
  virtual void SetFullScreen(int);
  void WindowRemap(void);
  void PrefFullScreen(void);
  void SetSize(int,int);

  virtual int      GetDesiredDepth();
  virtual Colormap GetDesiredColormap();
  virtual Visual  *GetDesiredVisual();
  XVisualInfo     *GetDesiredVisualInfo();

  vtkSetMacro(MultiSamples,int);
  vtkGetMacro(MultiSamples,int);

  // stereo rendering stuff
  virtual void StereoUpdate();

  // Description:
  // Set/Get the pixel data of an image, transmitted as RGBRGB...
  virtual unsigned char *GetPixelData(int x,int y,int x2,int y2,int front);
  virtual void SetPixelData(int x,int y,int x2,int y2,unsigned char *,int front);
};

#endif
<commit_msg>added a make current method<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    OglrRenW.hh
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

This file is part of the Visualization Toolkit. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994

=========================================================================*/
// .NAME vtkOglrRenderWindow - SGI OpenGL rendering window
// .SECTION Description
// vtkOglrRenderWindow is a concrete implementation of the abstract class
// vtkRenderWindow. vtkOglrRenderer interfaces to the Silicon Graphics
// OpenGL graphics library.

#ifndef __vtkOglrRenderWindow_hh
#define __vtkOglrRenderWindow_hh

#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "XRenWin.hh"
#include "GL/glx.h"

class vtkOglrRenderWindow : public vtkXRenderWindow
{
protected:
  GLXContext ContextId;
  int MultiSamples;
  long OldMonitorSetting;

public:
  vtkOglrRenderWindow();
  char *GetClassName() {return "vtkOglrRenderWindow";};
  void PrintSelf(ostream& os, vtkIndent indent);

  vtkRenderer  *MakeRenderer();
  vtkLightDevice     *MakeLight();
  vtkCameraDevice    *MakeCamera();
  vtkTextureDevice   *MakeTexture();
  vtkPropertyDevice  *MakeProperty();

  void Start(void);
  void Frame(void);
  void Connect(void);
  void WindowConfigure(void);
  void WindowInitialize(void);
  void Initialize(void);
  virtual void SetFullScreen(int);
  void WindowRemap(void);
  void PrefFullScreen(void);
  void SetSize(int,int);

  virtual int      GetDesiredDepth();
  virtual Colormap GetDesiredColormap();
  virtual Visual  *GetDesiredVisual();
  XVisualInfo     *GetDesiredVisualInfo();

  vtkSetMacro(MultiSamples,int);
  vtkGetMacro(MultiSamples,int);

  // stereo rendering stuff
  virtual void StereoUpdate();

  // Description:
  // Set/Get the pixel data of an image, transmitted as RGBRGB...
  virtual unsigned char *GetPixelData(int x,int y,int x2,int y2,int front);
  virtual void SetPixelData(int x,int y,int x2,int y2,unsigned char *,int front);
  void MakeCurrent();
};

#endif
<|endoftext|>