1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: a sample console (as opposed to GUI) progam using wxWindows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
22 #include <wx/string.h>
26 // ----------------------------------------------------------------------------
27 // conditional compilation
28 // ----------------------------------------------------------------------------
34 //#define TEST_THREADS
36 // ============================================================================
38 // ============================================================================
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
46 #include <wx/thread.h>
48 static size_t gs_counter
= (size_t)-1;
49 static wxCriticalSection gs_critsect
;
51 class MyThread
: public wxThread
56 // thread execution starts here
57 virtual void *Entry();
60 virtual void OnExit();
66 MyThread::MyThread(char ch
)
73 void *MyThread::Entry()
76 wxCriticalSectionLocker
lock(gs_critsect
);
77 if ( gs_counter
== (size_t)-1 )
83 for ( size_t n
= 0; n
< 10; n
++ )
97 void MyThread::OnExit()
99 wxCriticalSectionLocker
lock(gs_critsect
);
103 #endif // TEST_THREADS
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
111 void PrintArray(const char* name
, const wxArrayString
& array
)
113 printf("Dump of the array '%s'\n", name
);
115 size_t nCount
= array
.GetCount();
116 for ( size_t n
= 0; n
< nCount
; n
++ )
118 printf("\t%s[%u] = '%s'\n", name
, n
, array
[n
].c_str());
122 #endif // TEST_ARRAYS
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 int main(int argc
, char **argv
)
130 if ( !wxInitialize() )
132 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
144 puts("*** Initially:");
146 PrintArray("a1", a1
);
148 wxArrayString
a2(a1
);
149 PrintArray("a2", a2
);
151 wxSortedArrayString
a3(a1
);
152 PrintArray("a3", a3
);
154 puts("*** After deleting a string from a1");
157 PrintArray("a1", a1
);
158 PrintArray("a2", a2
);
159 PrintArray("a3", a3
);
161 puts("*** After reassigning a1 to a2 and a3");
163 PrintArray("a2", a2
);
164 PrintArray("a3", a3
);
165 #endif // TEST_ARRAYS
169 for ( size_t n
= 0; n
< 8000; n
++ )
171 s
<< (char)('A' + (n
% 26));
175 msg
.Printf("A very very long message: '%s', the end!\n", s
.c_str());
177 // this one shouldn't be truncated
180 // but this one will because log functions use fixed size buffer
181 wxLogMessage("A very very long message 2: '%s', the end!\n", s
.c_str());
185 static const size_t nThreads
= 3;
186 MyThread
*threads
[nThreads
];
188 for ( n
= 0; n
< nThreads
; n
++ )
190 threads
[n
] = new MyThread('+' + n
);
194 // wait until all threads terminate
197 wxCriticalSectionLocker
lock(gs_critsect
);
202 puts("\nThat's all, folks!");
204 for ( n
= 0; n
< nThreads
; n
++ )
206 threads
[n
]->Delete();
208 #endif // TEST_THREADS