mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Functions4U_Demo: New demo package
git-svn-id: svn://ultimatepp.org/upp/trunk@3248 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
cf8f23841a
commit
232c1f044b
7 changed files with 251 additions and 0 deletions
35
bazaar/Functions4U_Demo/Excel.cpp
Normal file
35
bazaar/Functions4U_Demo/Excel.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#include "Spreadsheet.h"
|
||||
|
||||
class ExcelSpreadsheet : public SpreadsheetPlugin {
|
||||
private:
|
||||
String filename;
|
||||
|
||||
public:
|
||||
Spreadsheet_METHOD_LIST
|
||||
ExcelSpreadsheet() {
|
||||
puts("ExcelSpreadsheet new");
|
||||
}
|
||||
~ExcelSpreadsheet() {
|
||||
puts("ExcelSpreadsheet closing " + filename);
|
||||
puts("ExcelSpreadsheet delete");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
INITBLOCK {
|
||||
PluginRegister(Spreadsheet, ExcelSpreadsheet, "Excel");
|
||||
}
|
||||
|
||||
bool ExcelSpreadsheet::Open(const char *_filename) {
|
||||
filename = _filename;
|
||||
puts(Format("ExcelSpreadsheet::Open(%s)", filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
void ExcelSpreadsheet::SetData(int row, int col, Value val) {
|
||||
puts(Format("ExcelSpreadsheet::SetData(%d, %d, %s)", row, col, val.ToString()));
|
||||
}
|
||||
15
bazaar/Functions4U_Demo/Functions4U_Demo.upp
Normal file
15
bazaar/Functions4U_Demo/Functions4U_Demo.upp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
uses
|
||||
Core,
|
||||
Functions4U;
|
||||
|
||||
file
|
||||
main.cpp,
|
||||
StaticPlugin readonly separator,
|
||||
Spreadsheet.cpp,
|
||||
Spreadsheet.h,
|
||||
Open.cpp,
|
||||
Excel.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
35
bazaar/Functions4U_Demo/Open.cpp
Normal file
35
bazaar/Functions4U_Demo/Open.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#include "Spreadsheet.h"
|
||||
|
||||
class OpenSpreadsheet : public SpreadsheetPlugin {
|
||||
private:
|
||||
String filename;
|
||||
|
||||
public:
|
||||
Spreadsheet_METHOD_LIST
|
||||
OpenSpreadsheet() {
|
||||
puts("OpenSpreadsheet new");
|
||||
}
|
||||
~OpenSpreadsheet() {
|
||||
puts("OpenSpreadsheet closing " + filename);
|
||||
puts("OpenSpreadsheet delete");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
INITBLOCK {
|
||||
PluginRegister(Spreadsheet, OpenSpreadsheet, "Open");
|
||||
}
|
||||
|
||||
bool OpenSpreadsheet::Open(const char *_filename) {
|
||||
filename = _filename;
|
||||
puts(Format("OpenSpreadsheet::Open(%s)", filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
void OpenSpreadsheet::SetData(int row, int col, Value val) {
|
||||
puts(Format("OpenSpreadsheet::SetData(%d, %d, %s)", row, col, val.ToString()));
|
||||
}
|
||||
19
bazaar/Functions4U_Demo/Spreadsheet.cpp
Normal file
19
bazaar/Functions4U_Demo/Spreadsheet.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#include <Functions4U/Functions4U.h>
|
||||
#include "Spreadsheet.h"
|
||||
|
||||
|
||||
bool SpreadsheetPlugin::Open(const char *filename) {return false;};
|
||||
void SpreadsheetPlugin::SetData(int row, int col, Value val) {};
|
||||
|
||||
|
||||
bool Spreadsheet::Open(const char *filename) {return (static_cast<SpreadsheetPlugin *>(GetData()))->Open(filename);}
|
||||
void Spreadsheet::SetData(int row, int col, Value val) {return (static_cast<SpreadsheetPlugin *>(GetData()))->SetData(row, col, val);}
|
||||
|
||||
|
||||
INITBLOCK {
|
||||
PluginRegister(Spreadsheet, SpreadsheetPlugin, "");
|
||||
}
|
||||
23
bazaar/Functions4U_Demo/Spreadsheet.h
Normal file
23
bazaar/Functions4U_Demo/Spreadsheet.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef _PluginDemo_Spreadsheet_h_
|
||||
#define _PluginDemo_Spreadsheet_h_
|
||||
|
||||
#include <Functions4U/Functions4U.h>
|
||||
|
||||
#define Spreadsheet_METHOD_LIST \
|
||||
virtual bool Open(const char *filename); \
|
||||
virtual void SetData(int row, int col, Value val);
|
||||
|
||||
|
||||
class SpreadsheetPlugin {
|
||||
public:
|
||||
Spreadsheet_METHOD_LIST
|
||||
};
|
||||
|
||||
|
||||
class Spreadsheet : public SpreadsheetPlugin, public StaticPlugin {
|
||||
public:
|
||||
Spreadsheet_METHOD_LIST
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
5
bazaar/Functions4U_Demo/init
Normal file
5
bazaar/Functions4U_Demo/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _Functions4U_Demo_icpp_init_stub
|
||||
#define _Functions4U_Demo_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "Functions4U/init"
|
||||
#endif
|
||||
119
bazaar/Functions4U_Demo/main.cpp
Normal file
119
bazaar/Functions4U_Demo/main.cpp
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#include "Spreadsheet.h"
|
||||
|
||||
|
||||
static bool end = false;
|
||||
|
||||
void TestGetchar()
|
||||
{
|
||||
if (end)
|
||||
getchar();
|
||||
}
|
||||
|
||||
void Puts(String s)
|
||||
{
|
||||
puts(s);
|
||||
String file = AppendFileName(GetDesktopFolder(), "log");
|
||||
SaveFile(file, LoadFile(file) + "\n" + s);
|
||||
}
|
||||
|
||||
void SpreadsheetDemo(Spreadsheet &spreadsheet) {
|
||||
spreadsheet.Open("myfile.xls");
|
||||
spreadsheet.SetData(4, 6, "Hello world");
|
||||
}
|
||||
|
||||
void PluginDemo() {
|
||||
Spreadsheet spreadsheet;
|
||||
|
||||
if (!PluginInit(spreadsheet, "Open")) {
|
||||
Puts("Impossible to init OpenOffice/LibreOffice");
|
||||
return;
|
||||
}
|
||||
SpreadsheetDemo(spreadsheet);
|
||||
if (!PluginInit(spreadsheet, "Excel")) {
|
||||
Puts("Impossible to init Excel");
|
||||
return;
|
||||
}
|
||||
SpreadsheetDemo(spreadsheet);
|
||||
}
|
||||
|
||||
void FilesDemo() {
|
||||
String filename1 = AppendFileName(GetDesktopFolder(), "Demo", "file1.txt");
|
||||
RealizePath(filename1);
|
||||
String str1 = "This is the First string";
|
||||
SaveFile(filename1, str1);
|
||||
String filename2 = AppendFileName(GetDesktopFolder(), "Demo", "file2.txt");
|
||||
String str2 = "This is the Second string";
|
||||
SaveFile(filename2, str2);
|
||||
|
||||
FileCat(filename1, filename2);
|
||||
Puts(Format("\nFileCat(%s, %s)", filename1, filename2));
|
||||
|
||||
// LaunchFile(filename1);
|
||||
// Puts(Format("LaunchFile(%s)", filename1));
|
||||
|
||||
int intres = FileCompare(filename1, filename2);
|
||||
Puts(Format("\nFileCompare(%s, %s) = %d (has to be -1)", filename1, filename2, intres));
|
||||
|
||||
int64 pos = FindStringInFile(filename1, "Second");
|
||||
Puts(Format("\nFindStringInFile(%s, %s) = %d (has to be 35)", filename1, filename2, pos));
|
||||
|
||||
bool boolres = FileStrAppend(filename1, ". Text appended at the end.");
|
||||
Puts(Format("\nFileStrAppend(%s, \". Text appended at the end.\") = %s (has to be true)",
|
||||
filename1, boolres ? "true" : "false"));
|
||||
|
||||
boolres = UpperFolder(GetFileDirectory(filename1));
|
||||
Puts(Format("\nUpperFolder(%s) = %s (has to be true)", filename1, boolres ? "true" : "false"));
|
||||
|
||||
String upperFolder = GetUpperFolder(GetFileDirectory(filename1));
|
||||
Puts(Format("\nGetUpperFolder(%s) = %s (has to be %s)", filename1, upperFolder, GetDesktopFolder()));
|
||||
|
||||
String stringres = GetNextFolder(GetUpperFolder(GetDesktopFolder()), GetFileDirectory(filename1));
|
||||
Puts(Format("\nGetNextFolder(%s, %s) = %s (has to be %s)", GetUpperFolder(GetDesktopFolder()),
|
||||
GetFileDirectory(filename1), stringres, GetDesktopFolder()));
|
||||
|
||||
String lfilename1 = ToLower(filename1);
|
||||
filename1 = FileRealName(lfilename1);
|
||||
Puts(Format("\nFileRealName(%s) = %s", lfilename1, filename1));
|
||||
|
||||
}
|
||||
|
||||
void NonReentrantDemo() {
|
||||
Puts("Trying to enter Non reentrant.");
|
||||
NON_REENTRANT_V;
|
||||
|
||||
Puts("Entered in Non reentrant. It has to be once.");
|
||||
NonReentrantDemo();
|
||||
NonReentrantDemo();
|
||||
}
|
||||
|
||||
void Test() {
|
||||
Puts("Files demo");
|
||||
FilesDemo();
|
||||
|
||||
Puts("\nPlugin demo");
|
||||
PluginDemo();
|
||||
|
||||
Puts("\nNonReentrant demo");
|
||||
NonReentrantDemo();
|
||||
|
||||
Puts("\nPress enter to end..."); TestGetchar();
|
||||
}
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
FileDelete(AppendFileName(GetDesktopFolder(), "log"));
|
||||
|
||||
Puts("Introduce number of test cycles or just type enter to run it once: ");
|
||||
char str[50];
|
||||
fgets(str, 49, stdin);
|
||||
int numTests = atoi(str);
|
||||
for (int i = 0; i < numTests; ++i)
|
||||
Test();
|
||||
end = true;
|
||||
Test();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue