00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef CEYLAN_UTILS_H_
00028 #define CEYLAN_UTILS_H_
00029
00030
00031 #include "CeylanLibtoolVersion.h"
00032 #include "CeylanException.h"
00033 #include "CeylanTypes.h"
00034 #include "CeylanHeaderVersion.h"
00035
00036
00037 #include <string>
00038 #include <list>
00039 #include <algorithm>
00040
00041
00042
00049 namespace Ceylan
00050 {
00051
00052
00053
00054
00055
00057 CEYLAN_DLL const Ceylan::LibtoolVersion & GetVersion() ;
00058
00059
00060
00080 #define CHECK_CEYLAN_VERSIONS() \
00081 Ceylan::LibtoolVersion headerVersion( \
00082 Ceylan::actualCeylanHeaderLibtoolVersion ) ; \
00083 if ( ! \
00084 Ceylan::GetVersion().isCompatibleWith( headerVersion ) ) \
00085 Ceylan::emergencyShutdown( \
00086 "Ceylan library version currently linked (" \
00087 + Ceylan::GetVersion().toString() \
00088 + ") is not compatible with the one read from the Ceylan " \
00089 "header files used to compile this application (" \
00090 + headerVersion.toString() + "), aborting." ) ;
00091
00092
00093
00100 inline Ceylan::Uint16 swapBytes( Ceylan::Uint16 arg )
00101 {
00102
00103 return static_cast<Ceylan::Uint16>( (arg<<8) | (arg>>8) ) ;
00104
00105 }
00106
00107
00108
00110 class CEYLAN_DLL UtilsException: public Exception
00111 {
00112
00113 public:
00114
00115 UtilsException( const std::string & message ):
00116 Exception( message )
00117 {
00118
00119 }
00120
00121
00122 virtual ~UtilsException() throw()
00123 {
00124
00125 }
00126
00127 } ;
00128
00129
00130
00139 class CEYLAN_DLL CommandLineParseException: public UtilsException
00140 {
00141
00142 public:
00143
00144 CommandLineParseException( const std::string & message ):
00145 UtilsException( message )
00146 {
00147
00148 }
00149
00150
00151 virtual ~CommandLineParseException() throw()
00152 {
00153
00154 }
00155
00156 } ;
00157
00158
00159
00181 CEYLAN_DLL void parseCommandLineOptions( std::string & readExecutableName ,
00182 std::list<std::string> & readOptions,
00183 Ceylan::Uint16 argumentCount, char ** argumentVector ) ;
00184
00185
00186
00187
00188 typedef Ceylan::Sint16 ExitCode ;
00189
00190
00192 extern CEYLAN_DLL const ExitCode ExitSuccess ;
00193
00194
00195
00197 extern CEYLAN_DLL const ExitCode ExitFailure ;
00198
00199
00200
00209 extern CEYLAN_DLL const ExitCode ExitDebugFailure ;
00210
00211
00212
00225 CEYLAN_DLL void emergencyShutdown( const std::string & message )
00226
00227 #ifndef CEYLAN_RUNS_ON_WINDOWS
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 __attribute__ ((noreturn))
00238
00239 #endif // CEYLAN_RUNS_ON_WINDOWS
00240 ;
00241
00242
00243
00244
00245
00246
00247
00248
00261 CEYLAN_DLL bool keyboardHit() ;
00262
00263
00264
00266 typedef Ceylan::Sint32 KeyChar ;
00267
00268
00269
00270 #if defined(CEYLAN_ARCH_NINTENDO_DS) && CEYLAN_ARCH_NINTENDO_DS == 1
00271
00272
00273
00274
00275
00277 typedef Ceylan::Uint32 DSBinaryInput ;
00278
00279
00280
00282 extern CEYLAN_DLL const DSBinaryInput ButtonX ;
00283
00284
00286 extern CEYLAN_DLL const DSBinaryInput ButtonY ;
00287
00288
00289
00291 extern CEYLAN_DLL const DSBinaryInput ButtonA ;
00292
00293
00295 extern CEYLAN_DLL const DSBinaryInput ButtonB ;
00296
00297
00298
00300 extern CEYLAN_DLL const DSBinaryInput ButtonStart ;
00301
00302
00304 extern CEYLAN_DLL const DSBinaryInput ButtonSelect ;
00305
00306
00307
00309 extern CEYLAN_DLL const DSBinaryInput ButtonLeft ;
00310
00311
00313 extern CEYLAN_DLL const DSBinaryInput ButtonRight ;
00314
00315
00316
00318 extern CEYLAN_DLL const DSBinaryInput ButtonUp ;
00319
00320
00322 extern CEYLAN_DLL const DSBinaryInput ButtonDown ;
00323
00324
00325
00327 extern CEYLAN_DLL const DSBinaryInput ShoulderButtonLeft ;
00328
00329
00331 extern CEYLAN_DLL const DSBinaryInput ShoulderButtonRight ;
00332
00333
00334
00336 extern CEYLAN_DLL const DSBinaryInput StylusContact ;
00337
00338
00340 extern CEYLAN_DLL const DSBinaryInput LidOpen ;
00341
00342
00343
00345 extern CEYLAN_DLL const DSBinaryInput AllUserInputs ;
00346
00347
00348 #endif // CEYLAN_ARCH_NINTENDO_DS
00349
00350
00351
00352
00363 CEYLAN_DLL KeyChar getChar() ;
00364
00365
00366
00373 extern CEYLAN_DLL const std::string DefaultWaitForKeyMessage ;
00374
00375
00376
00394 CEYLAN_DLL KeyChar waitForKey( const std::string & message
00395 = DefaultWaitForKeyMessage ) ;
00396
00397
00398
00424 template<class T, class Element>
00425 void split( const T & toSplit, const Element & delimiter,
00426 std::list<T> & result )
00427 {
00428
00429 typename T::const_iterator beginOfSlice = toSplit.begin() ;
00430 typename T::const_iterator endOfSlice = toSplit.begin() ;
00431
00432 typename T::const_iterator endOfToSplit = toSplit.end() ;
00433
00434 while ( endOfSlice != endOfToSplit )
00435 {
00436 endOfSlice = std::find( beginOfSlice, endOfToSplit, delimiter ) ;
00437
00438 T temp ;
00439
00440 std::copy( beginOfSlice, endOfSlice, std::back_inserter( temp ) ) ;
00441
00442 result.push_back( temp ) ;
00443
00444 beginOfSlice = endOfSlice + 1 ;
00445 }
00446
00447 }
00448
00449
00450
00493 template<class T, class Predicate>
00494 void split_if( const T & toSplit, Predicate & predicate,
00495 std::list<T> & result )
00496 {
00497
00498 typename T::const_iterator beginOfSlice = toSplit.begin() ;
00499 typename T::const_iterator endOfSlice = toSplit.begin() ;
00500
00501 typename T::const_iterator endOfToSplit = toSplit.end() ;
00502
00503 while( endOfSlice != endOfToSplit )
00504 {
00505 endOfSlice = std::find_if( beginOfSlice, endOfToSplit, predicate ) ;
00506
00507 T temp ;
00508
00509 std::copy( beginOfSlice, endOfSlice, std::back_inserter( temp ) ) ;
00510
00511 result.push_back( temp ) ;
00512
00513 beginOfSlice = endOfSlice + 1 ;
00514 }
00515
00516 }
00517
00518
00526 CEYLAN_DLL void checkpoint( const std::string & message = "" ) ;
00527
00528
00537 CEYLAN_DLL void breakpoint( const std::string & message = "" ) ;
00538
00539
00540 }
00541
00542
00543
00544 #endif // CEYLAN_UTILS_H_
00545