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
00056
00057
00064 CEYLAN_DLL const Ceylan::LibtoolVersion & GetVersion() ;
00065
00066
00067
00087 #define CHECK_CEYLAN_VERSIONS() \
00088 Ceylan::LibtoolVersion headerVersion( \
00089 Ceylan::actualCeylanHeaderLibtoolVersion ) ; \
00090 if ( ! \
00091 Ceylan::GetVersion().isCompatibleWith( headerVersion ) ) \
00092 Ceylan::emergencyShutdown( \
00093 "Ceylan library version currently linked (" \
00094 + Ceylan::GetVersion().toString() \
00095 + ") is not compatible with the one read from the Ceylan " \
00096 "header files used to compile this application (" \
00097 + headerVersion.toString() + "), aborting." ) ;
00098
00099
00100
00107 inline Ceylan::Uint16 swapBytes( Ceylan::Uint16 arg )
00108 {
00109
00110 return static_cast<Ceylan::Uint16>( (arg<<8) | (arg>>8) ) ;
00111
00112 }
00113
00114
00115
00117 class CEYLAN_DLL UtilsException: public Exception
00118 {
00119
00120 public:
00121
00122 UtilsException( const std::string & message ):
00123 Exception( message )
00124 {
00125
00126 }
00127
00128
00129 virtual ~UtilsException() throw()
00130 {
00131
00132 }
00133
00134 } ;
00135
00136
00137
00146 class CEYLAN_DLL CommandLineParseException: public UtilsException
00147 {
00148
00149 public:
00150
00151 CommandLineParseException( const std::string & message ):
00152 UtilsException( message )
00153 {
00154
00155 }
00156
00157
00158 virtual ~CommandLineParseException() throw()
00159 {
00160
00161 }
00162
00163 } ;
00164
00165
00166
00188 CEYLAN_DLL void parseCommandLineOptions( std::string & readExecutableName ,
00189 std::list<std::string> & readOptions,
00190 Ceylan::Uint16 argumentCount, char ** argumentVector ) ;
00191
00192
00193
00194
00195 typedef Ceylan::Sint16 ExitCode ;
00196
00197
00199 extern CEYLAN_DLL const ExitCode ExitSuccess ;
00200
00201
00202
00204 extern CEYLAN_DLL const ExitCode ExitFailure ;
00205
00206
00207
00216 extern CEYLAN_DLL const ExitCode ExitDebugFailure ;
00217
00218
00219
00230 CEYLAN_DLL void emergencyShutdown( const std::string & message )
00231
00232 #ifndef CEYLAN_RUNS_ON_WINDOWS
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 __attribute__ ((noreturn))
00243
00244 #endif // CEYLAN_RUNS_ON_WINDOWS
00245 ;
00246
00247
00248
00249
00250
00251
00252
00253
00266 CEYLAN_DLL bool keyboardHit() ;
00267
00268
00269
00271 typedef Ceylan::Sint32 KeyChar ;
00272
00273
00274
00275 #if defined(CEYLAN_ARCH_NINTENDO_DS) && CEYLAN_ARCH_NINTENDO_DS == 1
00276
00277
00278
00279
00280
00282 typedef Ceylan::Uint32 DSBinaryInput ;
00283
00284
00285
00287 extern CEYLAN_DLL const DSBinaryInput ButtonX ;
00288
00289
00291 extern CEYLAN_DLL const DSBinaryInput ButtonY ;
00292
00293
00294
00296 extern CEYLAN_DLL const DSBinaryInput ButtonA ;
00297
00298
00300 extern CEYLAN_DLL const DSBinaryInput ButtonB ;
00301
00302
00303
00305 extern CEYLAN_DLL const DSBinaryInput ButtonStart ;
00306
00307
00309 extern CEYLAN_DLL const DSBinaryInput ButtonSelect ;
00310
00311
00312
00314 extern CEYLAN_DLL const DSBinaryInput ButtonLeft ;
00315
00316
00318 extern CEYLAN_DLL const DSBinaryInput ButtonRight ;
00319
00320
00321
00323 extern CEYLAN_DLL const DSBinaryInput ButtonUp ;
00324
00325
00327 extern CEYLAN_DLL const DSBinaryInput ButtonDown ;
00328
00329
00330
00332 extern CEYLAN_DLL const DSBinaryInput ShoulderButtonLeft ;
00333
00334
00336 extern CEYLAN_DLL const DSBinaryInput ShoulderButtonRight ;
00337
00338
00339
00341 extern CEYLAN_DLL const DSBinaryInput StylusContact ;
00342
00343
00345 extern CEYLAN_DLL const DSBinaryInput LidOpen ;
00346
00347
00348
00350 extern CEYLAN_DLL const DSBinaryInput AllUserInputs ;
00351
00352
00353 #endif // CEYLAN_ARCH_NINTENDO_DS
00354
00355
00356
00357
00368 CEYLAN_DLL KeyChar getChar() ;
00369
00370
00371
00378 extern CEYLAN_DLL const std::string DefaultWaitForKeyMessage ;
00379
00380
00381
00399 CEYLAN_DLL KeyChar waitForKey( const std::string & message
00400 = DefaultWaitForKeyMessage ) ;
00401
00402
00403
00429 template<class T, class Element>
00430 void split( const T & toSplit, const Element & delimiter,
00431 std::list<T> & result )
00432 {
00433
00434 typename T::const_iterator beginOfSlice = toSplit.begin() ;
00435 typename T::const_iterator endOfSlice = toSplit.begin() ;
00436
00437 typename T::const_iterator endOfToSplit = toSplit.end() ;
00438
00439 while ( endOfSlice != endOfToSplit )
00440 {
00441 endOfSlice = std::find( beginOfSlice, endOfToSplit, delimiter ) ;
00442
00443 T temp ;
00444
00445 std::copy( beginOfSlice, endOfSlice, std::back_inserter( temp ) ) ;
00446
00447 result.push_back( temp ) ;
00448
00449 beginOfSlice = endOfSlice + 1 ;
00450 }
00451
00452 }
00453
00454
00455
00498 template<class T, class Predicate>
00499 void split_if( const T & toSplit, Predicate & predicate,
00500 std::list<T> & result )
00501 {
00502
00503 typename T::const_iterator beginOfSlice = toSplit.begin() ;
00504 typename T::const_iterator endOfSlice = toSplit.begin() ;
00505
00506 typename T::const_iterator endOfToSplit = toSplit.end() ;
00507
00508 while( endOfSlice != endOfToSplit )
00509 {
00510 endOfSlice = std::find_if( beginOfSlice, endOfToSplit, predicate ) ;
00511
00512 T temp ;
00513
00514 std::copy( beginOfSlice, endOfSlice, std::back_inserter( temp ) ) ;
00515
00516 result.push_back( temp ) ;
00517
00518 beginOfSlice = endOfSlice + 1 ;
00519 }
00520
00521 }
00522
00523
00524
00532 CEYLAN_DLL void checkpoint( const std::string & message = "" ) ;
00533
00534
00535
00544 CEYLAN_DLL void breakpoint( const std::string & message = "" ) ;
00545
00546
00547 }
00548
00549
00550
00551 #endif // CEYLAN_UTILS_H_
00552