logger.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_PLAYER_LOGGER_H
00033 #define RCSC_PLAYER_LOGGER_H
00034 
00035 #include <rcsc/geom/vector_2d.h>
00036 #include <rcsc/geom/circle_2d.h>
00037 #include <rcsc/geom/rect_2d.h>
00038 #include <rcsc/geom/triangle_2d.h>
00039 
00040 #include <boost/cstdint.hpp>
00041 
00042 #include <cstdio>
00043 
00044 namespace rcsc {
00045 
00046 class GameTime;
00047 
00052 class Logger {
00053 public:
00054 
00055     static const boost::int32_t LEVEL_00 = 0x00000000;
00056     static const boost::int32_t LEVEL_01 = 0x00000001;
00057     static const boost::int32_t LEVEL_02 = 0x00000002;
00058     static const boost::int32_t LEVEL_03 = 0x00000004;
00059     static const boost::int32_t LEVEL_04 = 0x00000008;
00060     static const boost::int32_t LEVEL_05 = 0x00000010;
00061     static const boost::int32_t LEVEL_06 = 0x00000020;
00062     static const boost::int32_t LEVEL_07 = 0x00000040;
00063     static const boost::int32_t LEVEL_08 = 0x00000080;
00064     static const boost::int32_t LEVEL_09 = 0x00000100;
00065     static const boost::int32_t LEVEL_10 = 0x00000200;
00066     static const boost::int32_t LEVEL_11 = 0x00000400;
00067     static const boost::int32_t LEVEL_12 = 0x00000800;
00068     static const boost::int32_t LEVEL_13 = 0x00001000;
00069     static const boost::int32_t LEVEL_14 = 0x00002000;
00070     static const boost::int32_t LEVEL_15 = 0x00004000;
00071     static const boost::int32_t LEVEL_16 = 0x00008000;
00072     static const boost::int32_t LEVEL_17 = 0x00010000;
00073     static const boost::int32_t LEVEL_18 = 0x00020000;
00074     static const boost::int32_t LEVEL_19 = 0x00040000;
00075     static const boost::int32_t LEVEL_20 = 0x00080000;
00076     static const boost::int32_t LEVEL_21 = 0x00100000;
00077     static const boost::int32_t LEVEL_22 = 0x00200000;
00078     static const boost::int32_t LEVEL_23 = 0x00400000;
00079     static const boost::int32_t LEVEL_24 = 0x00800000;
00080     static const boost::int32_t LEVEL_25 = 0x01000000;
00081     static const boost::int32_t LEVEL_26 = 0x02000000;
00082     static const boost::int32_t LEVEL_27 = 0x04000000;
00083     static const boost::int32_t LEVEL_28 = 0x08000000;
00084     static const boost::int32_t LEVEL_29 = 0x10000000;
00085     static const boost::int32_t LEVEL_30 = 0x20000000;
00086     static const boost::int32_t LEVEL_31 = 0x40000000;
00087     static const boost::int32_t LEVEL_32 = 0x80000000;
00088     static const boost::int32_t LEVEL_ANY = 0xffffffff;
00089 
00090     /*************************************************
00091     Log Message Line Format:
00092     Line := <Time> <Level> <Type> <Content>
00093     Time := integer value
00094     Level := integer value
00095     Type :=  T | p | l | c | t | r | m
00096     Text := <Str>
00097     Point := <x:Real> <y:Real>[ <Color>]
00098     Line := <x1:Real> <y1:Real> <x2:Real> <y2:Real>[ <Color>]
00099     Circle := <x:Real> <y:Real> <r:Real>[ <Color>]
00100     Triangle := <x1:Real> <y1:Real> <x2:Real> <y2:Real> <x3:Real> <y3:Real>[ <Color>]
00101     Rectangle := <leftX:Real> <topY:Real> <width:Real> <height:Real>[ <Color>]
00102     Message := <x:Real> <y:Real>[ (c <Color>)] <Str>
00103     **************************************************/
00104 
00105     static const boost::int32_t SYSTEM    = LEVEL_01;
00106     static const boost::int32_t SENSOR    = LEVEL_02;
00107     static const boost::int32_t WORLD     = LEVEL_03;
00108     static const boost::int32_t ACTION    = LEVEL_04;
00109     static const boost::int32_t INTERCEPT = LEVEL_05;
00110     static const boost::int32_t KICK      = LEVEL_06;
00111     static const boost::int32_t DRIBBLE   = LEVEL_07;
00112     static const boost::int32_t PASS      = LEVEL_08;
00113     static const boost::int32_t CROSS     = LEVEL_09;
00114     static const boost::int32_t SHOOT     = LEVEL_10;
00115     static const boost::int32_t CLEAR     = LEVEL_11;
00116     static const boost::int32_t TEAM      = LEVEL_12;
00117     static const boost::int32_t ROLE      = LEVEL_13;
00118 
00119 private:
00120 
00122     const GameTime * M_time;
00123 
00125     FILE* M_fout;
00126 
00128     boost::int32_t M_flags;
00129 
00130 public:
00134     Logger();
00135 
00139     ~Logger();
00140 
00147     void setLogFlag( const GameTime * time,
00148                      const boost::int32_t id,
00149                      const bool on = true );
00150 
00156     bool isLogFlag( const boost::int32_t id ) const
00157       {
00158           return ( M_flags & id );
00159       }
00160 
00165     void open( const char * file_path );
00166 
00171     bool isOpen()
00172       {
00173           return ( M_fout != NULL );
00174       }
00175 
00180     void print( const char * msg );
00181 
00185     void flush();
00186 
00190     void clear();
00191 
00192 
00198     void addText( const boost::int32_t id,
00199                   const char * msg,
00200                   ... );
00201 
00208     void addPoint( const boost::int32_t id,
00209                    const double & x,
00210                    const double & y,
00211                    const char * color = NULL );
00212 
00213     void addPoint( const boost::int32_t id,
00214                    const Vector2D & pos,
00215                    const char * color = NULL )
00216       {
00217           addPoint( id, pos.x, pos.y, color );
00218       }
00219 
00228     void addPoint( const boost::int32_t id,
00229                    const double & x,
00230                    const double & y,
00231                    const char r, const char g, const char b );
00232 
00233     void addPoint( const boost::int32_t id,
00234                    const Vector2D & pos,
00235                    const char r, const char g, const char b )
00236       {
00237           addPoint( id, pos.x, pos.y, r, g, b );
00238       }
00239 
00248     void addLine( const boost::int32_t id,
00249                   const double & x1,
00250                   const double & y1,
00251                   const double & x2,
00252                   const double & y2,
00253                   const char * color = NULL );
00254 
00255     void addLine( const boost::int32_t id,
00256                   const Vector2D & start,
00257                   const Vector2D & end,
00258                   const char * color = NULL )
00259       {
00260           addLine( id, start.x, start.y, end.x, end.y, color );
00261       }
00262 
00273     void addLine( const boost::int32_t id,
00274                   const double & x1,
00275                   const double & y1,
00276                   const double & x2,
00277                   const double & y2,
00278                   const char r, const char g, const char b );
00279 
00280     void addLine( const boost::int32_t id,
00281                   const Vector2D & start,
00282                   const Vector2D & end,
00283                   const char r, const char g, const char b )
00284       {
00285           addLine( id, start.x, start.y, end.x, end.y, r, g, b );
00286       }
00287 
00295     void addCircle( const boost::int32_t id,
00296                     const double & x,
00297                     const double & y,
00298                     const double & radius,
00299                     const char * color = NULL );
00300 
00301     void addCircle( const boost::int32_t id,
00302                     const Vector2D & center,
00303                     const double & radius,
00304                     const char * color = NULL )
00305       {
00306           addCircle( id, center.x, center.y, radius, color );
00307       }
00308 
00309     void addCircle( const boost::int32_t id,
00310                     const Circle2D & circle,
00311                     const char * color = NULL )
00312       {
00313           addCircle( id, circle.center().x, circle.center().y, circle.radius(), color );
00314       }
00315 
00325     void addCircle( const boost::int32_t id,
00326                     const double & x,
00327                     const double & y,
00328                     const double & radius,
00329                     const char r, const char g, const char b );
00330 
00331     void addCircle( const boost::int32_t id,
00332                     const Vector2D & center,
00333                     const double & radius,
00334                     const char r, const char g, const char b )
00335       {
00336           addCircle( id, center.x, center.y, radius, r, g, b );
00337       }
00338 
00339     void addCircle( const boost::int32_t id,
00340                     const Circle2D & circle,
00341                     const char r, const char g, const char b )
00342       {
00343           addCircle( id,
00344                      circle.center().x, circle.center().y, circle.radius(),
00345                      r, g, b );
00346       }
00347 
00358     void addTriangle( const boost::int32_t id,
00359                       const double & x1,
00360                       const double & y1,
00361                       const double & x2,
00362                       const double & y2,
00363                       const double & x3,
00364                       const double & y3,
00365                       const char * color = NULL );
00366 
00367     void addTriangle( const boost::int32_t id,
00368                       const Vector2D & p1,
00369                       const Vector2D & p2,
00370                       const Vector2D & p3,
00371                       const char * color = NULL )
00372       {
00373           addTriangle( id,
00374                        p1.x, p1.y,
00375                        p2.x, p2.y,
00376                        p3.x, p3.y,
00377                        color );
00378       }
00379 
00380     void addTriangle( const boost::int32_t id,
00381                       const Triangle2D & tri,
00382                       const char * color = NULL )
00383       {
00384           addTriangle( id,
00385                        tri.a().x, tri.a().y,
00386                        tri.b().x, tri.b().y,
00387                        tri.c().x, tri.c().y,
00388                        color );
00389       }
00390 
00403     void addTriangle( const boost::int32_t id,
00404                       const double & x1,
00405                       const double & y1,
00406                       const double & x2,
00407                       const double & y2,
00408                       const double & x3,
00409                       const double & y3,
00410                       const char r, const char g, const char b );
00411 
00412     void addTriangle( const boost::int32_t id,
00413                       const Vector2D & p1,
00414                       const Vector2D & p2,
00415                       const Vector2D & p3,
00416                       const char r, const char g, const char b )
00417       {
00418           addTriangle( id,
00419                        p1.x, p1.y,
00420                        p2.x, p2.y,
00421                        p3.x, p3.y,
00422                        r, g, b );
00423       }
00424 
00425     void addTriangle( const boost::int32_t id,
00426                       const Triangle2D & tri,
00427                       const char r, const char g, const char b )
00428       {
00429           addTriangle( id,
00430                        tri.a().x, tri.a().y,
00431                        tri.b().x, tri.b().y,
00432                        tri.c().x, tri.c().y,
00433                        r, g, b );
00434       }
00435 
00444     void addRect( const boost::int32_t id,
00445                   const double & left,
00446                   const double & top,
00447                   const double & length,
00448                   const double & width,
00449                   const char * color = NULL );
00450 
00451     void addRect( const boost::int32_t id,
00452                   const Rect2D & rect,
00453                   const char * color = NULL )
00454       {
00455           addRect( id,
00456                    rect.left(), rect.top(),
00457                    rect.size().length(), rect.size().width(),
00458                    color );
00459       }
00460 
00471     void addRect( const boost::int32_t id,
00472                   const double & left,
00473                   const double & top,
00474                   const double & length,
00475                   const double & width,
00476                   const char r, const char g, const char b );
00477 
00478     void addRect( const boost::int32_t id,
00479                   const Rect2D & rect,
00480                   const char r, const char g, const char b )
00481       {
00482           addRect( id,
00483                    rect.left(), rect.top(),
00484                    rect.size().length(), rect.size().width(),
00485                    r, g, b );
00486       }
00487 
00495     void addMessage( const boost::int32_t id,
00496                      const double & x,
00497                      const double & y,
00498                      const char * msg,
00499                      const char * color = NULL );
00500 
00501     void addMessage( const boost::int32_t id,
00502                      const Vector2D & pos,
00503                      const char * msg,
00504                      const char * color = NULL )
00505       {
00506           addMessage( id,
00507                       pos.x, pos.y, msg,
00508                       color );
00509       }
00510 
00520     void addMessage( const boost::int32_t id,
00521                      const double & x,
00522                      const double & y,
00523                      const char * msg,
00524                      const char r, const char g, const char b );
00525 
00526     void addMessage( const boost::int32_t id,
00527                      const Vector2D & pos,
00528                      const char * msg,
00529                      const char r, const char g, const char b )
00530       {
00531           addMessage( id,
00532                       pos.x, pos.y, msg,
00533                       r, g, b );
00534       }
00535 
00536 };
00537 
00539 extern Logger dlog;
00540 
00541 }
00542 
00543 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0