syncing uppdev

git-svn-id: svn://ultimatepp.org/upp/trunk@1525 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-08-23 17:33:39 +00:00
parent ca64a6dc01
commit ef678f9447
7 changed files with 190 additions and 19 deletions

View file

@ -0,0 +1,13 @@
description "Report example\377";
uses
CtrlLib,
Report,
PdfDraw;
file
main.cpp charset "UTF-8";
mainconfig
"" = "GUI";

View file

@ -0,0 +1,6 @@
#ifndef _ReportWithChineseCharacter_icpp_init_stub
#define _ReportWithChineseCharacter_icpp_init_stub
#include "CtrlLib/init"
#include "Report/init"
#include "PdfDraw/init"
#endif

View file

@ -0,0 +1,29 @@
#include <Report/Report.h>
using namespace Upp;
GUI_APP_MAIN
{
Report r;
r.Header("[A2> Page $$P");
r << "This is some [* QTF text";
r << t_("顯示[* QTF 文字");
r << "&&Let's report some table:";
r << t_("輸出表格式報表:");
String tab;
tab << "{{1:1:1:1:1:1:2 A:: B:: C:: D:: E:: F:: G (wider)";
for(int row = 0; row < 20; row++)
for(int column = 0; column < 7; column++)
tab << ":: " << row << ":" << column << t_("測試");
r << tab;
r.NewPage();
int y = r.GetY();
r.DrawEllipse(300, y + 50, 3000, 2000, LtRed, 20);
r.DrawText(500, y + 50 + 950, "Some free drawing in this page!", Arial(100));
r.DrawText(500, y + 50 + 1100, t_("在這頁隨便畫一些東西!"), Arial(100));
r.SetY(y + 50 + 3000);
r << "More of [/ QTF] [C6* text";
Perform(r);
}

View file

@ -1,25 +1,34 @@
#include <Report/Report.h>
using namespace Upp;
struct TableRowTracer : RichTextLayoutTracer {
VectorMap<int, int> pgr;
virtual void TableRow(const Rect& page, PageY y, int, const RichTable&) {
pgr.GetAdd(y.page, 0)++;
}
};
GUI_APP_MAIN
{
Report r;
r.Header("[A2> Page $$P");
r << "This is some [* QTF text";
r << "&&Let's report some table:";
String tab;
tab << "{{1:1:1:1:1:1:2 A:: B:: C:: D:: E:: F:: G (wider)";
for(int row = 0; row < 20; row++)
for(int column = 0; column < 7; column++)
tab << ":: " << row << ":" << column;
r << tab;
r.NewPage();
int y = r.GetY();
r.DrawEllipse(300, y + 50, 3000, 2000, LtRed, 20);
r.DrawText(500, y + 50 + 950, "Some free drawing in this page!", Arial(100));
Vector<Point> poly;
poly << Point(200,200) << Point(700,200) << Point(700,500) << Point(200,500) << Point(200,200);
r.DrawPolygon(poly, Cyan, 2, Red, 0, Null);
r.SetY(y + 50 + 3000);
r << "More of [/ QTF] [C6* text";
Perform(r);
r.Footer("[R1 ");
TableRowTracer t;
r.SetRichTextLayoutTracer(t);
String qtf = "&[R This is a demonstration of [* RichTextLayoutTracer]&&&{{1 Table";
for(int i = 0; i < 100; i++)
qtf << ":: " << i;
qtf << "}}";
r.Put(qtf);
Report rr;
for(int i = 0; i < r.GetCount(); i++) {
if(i)
rr.NewPage();
rr.Footer("[R1 There is " + AsString(t.pgr.Get(i, 0)) + " table rows on this page");
rr.DrawDrawing(r.GetPageSize(), r[i]);
}
Perform(rr);
}

4
uppdev/pthread_tls/init Normal file
View file

@ -0,0 +1,4 @@
#ifndef _pthread_tls_icpp_init_stub
#define _pthread_tls_icpp_init_stub
#include "Core/init"
#endif

View file

@ -0,0 +1,96 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
//#include <Core/Core.h>
#ifndef TLS_PRE_ALLOC
#define TLS_PRE_ALLOC false
#endif
#ifndef NUM_THREADS
#define NUM_THREADS 10
#endif
#ifndef NUM_TESTS
#define NUM_TESTS 1<<28
#endif
pthread_key_t p_key;
struct tls_ {
int id;
long check;
};
#if TLS_PRE_ALLOC
static tls_ tls[NUM_THREADS];
#endif
bool update_tls() {
tls_ *tmp = (tls_*)pthread_getspecific(p_key);
volatile long chk = tmp->check;
tmp->check += 1;
if (chk+1 == tmp->check)
return true;
else
return false;
}
void* work(void* p_tls) {
pthread_setspecific(p_key, p_tls);
printf("Starting thread id: %d, v: %d\n", ((tls_*)pthread_getspecific(p_key))->id, ((tls_*)pthread_getspecific(p_key))->check);
int test_nr = 0;
do {
if (!update_tls())
return NULL;
} while (NUM_TESTS < 0 || ++test_nr < NUM_TESTS);
tls_ *tmp = (tls_*)pthread_getspecific(p_key);
printf("Leaving thread %d value %d ...\n", tmp->id, tmp->check);
#if !TLS_PRE_ALLOC
free(tmp);
pthread_setspecific(p_key, NULL);
#endif
return (void*)-1;
}
int main(int argc, const char *argv[])
{
clock_t clk = clock();
pthread_key_create(&p_key, NULL);
pthread_t threads[NUM_THREADS];
long ret;
void* ret_ptr = &ret;
int thread_id = 0;
while (thread_id < NUM_THREADS) {
#if TLS_PRE_ALLOC
printf("Thread specific data is pre allocated ...\n", thread_id);
tls[thread_id].id = thread_id;
tls[thread_id].check = thread_id;
if (pthread_create(&threads[thread_id], NULL, work, &tls[thread_id]) != 0) {
printf("Cannot create thread %d\n", thread_id);
break;
}
#else
printf("Allocating thread specific data for thread %d ...\n", thread_id);
tls_ *tls = new tls_;
tls->id = thread_id;
tls->check = thread_id;
if (pthread_create(&threads[thread_id], NULL, work, tls) != 0) {
printf("Cannot create thread %d\n", thread_id);
break;
}
#endif
thread_id++;
}
for (int i=0; i < thread_id; i++) {
pthread_join(threads[i], &ret_ptr);
if (!ret_ptr)
printf("thread %d TSS update has errors !!!\n", i);
}
pthread_key_delete(p_key);
printf("CPU time: %f\n", (float)(clock()-clk)/CLOCKS_PER_SEC);
return 0;
}

View file

@ -0,0 +1,14 @@
description "pthread thread local storage test\377";
uses
Core;
library
pthread;
file
pthread_tls.cpp;
mainconfig
"" = "";