Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Question: Simple plugin implementation
Question: Simple plugin implementation [message #30804] Sun, 23 January 2011 22:20 Go to previous message
koldo is currently offline  koldo
Messages: 3360
Registered: August 2008
Senior Veteran
Hello all

I will ask you the question with an example based in OfficeAutomation:

There is an API of functions to handle spreadsheets. As they can be handled using OpenOffice, LibreOffice, Excel or other programs, the same API can be set for all programs. In run time it is possible to choose which program to use.

To do it, I have prepared something similar to the enclosed code. However, I think it is ugly and something much better could be done in U++ using C++.

Do you have any idea?

#include <Core/Core.h>

using namespace Upp;


class SpreadsheetPlugin {
public:
	virtual bool Open(char *filename) 			{return false;};
	virtual bool SetData(int row, int col, Value val) 	{return false;};
};


class OpenSpreadsheet : public SpreadsheetPlugin {
	virtual bool Open(char *filename);
	virtual bool SetData(int row, int col, Value val); 	
};

bool OpenSpreadsheet::Open(char *filename) {
	// Do stuff
}

bool OpenSpreadsheet::SetData(int row, int col, Value val) {
	// Do stuff
}

class ExcelSpreadsheet : public SpreadsheetPlugin {
	virtual bool Open(char *filename);
	virtual bool SetData(int row, int col, Value val);
};

bool ExcelSpreadsheet::Open(char *filename) {
	// Do stuff
}

bool ExcelSpreadsheet::SetData(int row, int col, Value val) {
	// Do stuff
}


class Spreadsheet : public SpreadsheetPlugin {
private:
	SpreadsheetPlugin *data;
	
public:
	Spreadsheet() {data = 0;};
	~Spreadsheet() {
		if (data)
			delete data;
	}
	void Init(String type) {
		if (type == "Open" || type == "Libre")
			data = new OpenSpreadsheet();
		else
			data = new ExcelSpreadsheet();
	}
	
	virtual bool Open(char *filename) 			{return data->Open(filename);}
	virtual bool SetData(int row, int col, Value val)	{return data->SetData(row, col, val);}
};


CONSOLE_APP_MAIN
{
	Spreadsheet spreadsheet;
	
	spreadsheet.Init("Libre");
	spreadsheet.Open("c:\\myfile.xls");
	spreadsheet.SetData(4, 6, "Hello world");
}


Best regards
IƱaki
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Q: howto incorporate a native console window in GUI
Next Topic: BackgroundTask
Goto Forum:
  


Current Time: Mon May 06 09:09:05 CEST 2024

Total time taken to generate the page: 0.02983 seconds