Home » Developing U++ » U++ Developers corner » Question: Simple plugin implementation
Question: Simple plugin implementation [message #30804] |
Sun, 23 January 2011 22:20  |
 |
koldo
Messages: 3432 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
|
|
|
 |
|
Question: Simple plugin implementation
By: koldo on Sun, 23 January 2011 22:20
|
 |
|
Re: Question: Simple plugin implementation
By: mirek on Sun, 23 January 2011 23:53
|
 |
|
Re: Question: Simple plugin implementation
By: koldo on Mon, 24 January 2011 09:44
|
 |
|
Re: Question: Simple plugin implementation
By: koldo on Tue, 25 January 2011 14:50
|
 |
|
Re: Question: Simple plugin implementation
By: mirek on Tue, 25 January 2011 15:34
|
 |
|
Re: Question: Simple plugin implementation
By: koldo on Thu, 27 January 2011 10:34
|
 |
|
Re: Question: Simple plugin implementation
By: koldo on Thu, 27 January 2011 13:58
|
 |
|
Re: Question: Simple plugin implementation
By: fudadmin on Thu, 27 January 2011 17:34
|
 |
|
Re: Question: Simple plugin implementation
By: mirek on Thu, 27 January 2011 20:54
|
 |
|
Re: Question: Simple plugin implementation
By: mirek on Thu, 27 January 2011 20:53
|
 |
|
Re: Question: Simple plugin implementation
By: koldo on Thu, 27 January 2011 21:47
|
 |
|
Re: Question: Simple plugin implementation
By: mirek on Fri, 28 January 2011 10:33
|
 |
|
Re: Question: Simple plugin implementation
By: mirek on Fri, 28 January 2011 10:34
|
 |
|
Re: Question: Simple plugin implementation
By: koldo on Sat, 29 January 2011 01:08
|
 |
|
Re: Question: Simple plugin implementation
By: koldo on Mon, 07 February 2011 11:16
|
 |
|
Re: Question: Simple plugin implementation
By: mirek on Fri, 11 February 2011 16:50
|
 |
|
Re: Question: Simple plugin implementation
By: koldo on Fri, 11 February 2011 22:47
|
Goto Forum:
Current Time: Sun Apr 27 19:49:18 CEST 2025
Total time taken to generate the page: 0.00900 seconds
|