LCOV - code coverage report
Current view: top level - src - Desc.h (source / functions) Hit Total Coverage
Test: app.info Lines: 23 37 62.2 %
Date: 2010-12-13 Functions: 14 22 63.6 %
Branches: 4 10 40.0 %

           Branch data     Line data    Source code
       1                 :            : // $Id: Desc.h 6219 2008-10-01 05:39:07Z vern $
       2                 :            : //
       3                 :            : // See the file "COPYING" in the main distribution directory for copyright.
       4                 :            : 
       5                 :            : #ifndef descriptor_h
       6                 :            : #define descriptor_h
       7                 :            : 
       8                 :            : #include <stdio.h>
       9                 :            : #include "BroString.h"
      10                 :            : 
      11                 :            : typedef enum {
      12                 :            :         DESC_READABLE,
      13                 :            :         DESC_PORTABLE,
      14                 :            :         DESC_BINARY,
      15                 :            : } desc_type;
      16                 :            : 
      17                 :            : typedef enum {
      18                 :            :         STANDARD_STYLE,
      19                 :            :         ALTERNATIVE_STYLE,
      20                 :            : } desc_style;
      21                 :            : 
      22                 :            : class BroFile;
      23                 :            : 
      24                 :            : class ODesc {
      25                 :            : public:
      26                 :            :         ODesc(desc_type t=DESC_READABLE, BroFile* f=0);
      27                 :            : 
      28                 :            :         ~ODesc();
      29                 :            : 
      30                 :     546751 :         int IsReadable() const          { return type == DESC_READABLE; }
      31                 :     140538 :         int IsPortable() const          { return type == DESC_PORTABLE; }
      32                 :     408686 :         int IsBinary() const            { return type == DESC_BINARY; }
      33                 :            : 
      34                 :          0 :         int IsShort() const             { return is_short; }
      35                 :         16 :         void SetShort()                 { is_short = 1; }
      36                 :          0 :         void SetShort(int s)            { is_short = s; }
      37                 :            : 
      38                 :            :         // Whether we want to have quotes around strings.
      39                 :     246142 :         int WantQuotes() const  { return want_quotes; }
      40                 :          0 :         void SetQuotes(int q)   { want_quotes = q; }
      41                 :            : 
      42                 :            :         // Whether we want to print statistics like access time and execution
      43                 :            :         // count where available.
      44                 :          0 :         int IncludeStats() const        { return include_stats; }
      45                 :          0 :         void SetIncludeStats(int s)     { include_stats = s; }
      46                 :            : 
      47                 :     123071 :         desc_style Style() const        { return style; }
      48                 :       4965 :         void SetStyle(desc_style s)     { style = s; }
      49                 :            : 
      50                 :       4965 :         void SetFlush(int arg_do_flush) { do_flush = arg_do_flush; }
      51                 :            : 
      52                 :            :         void PushIndent();
      53                 :            :         void PopIndent();
      54                 :            :         int GetIndentLevel() const      { return indent_level; }
      55                 :            : 
      56                 :            :         void Add(const char* s, int do_indent=1);
      57                 :     107706 :         void AddN(const char* s, int len)       { AddBytes(s, len); }
      58                 :            :         void Add(int i);
      59                 :            :         void Add(uint32 u);
      60                 :            :         void Add(int64 i);
      61                 :            :         void Add(uint64 u);
      62                 :            :         void Add(double d);
      63                 :            : 
      64                 :            :         // Add s as a counted string.
      65                 :            :         void AddCS(const char* s);
      66                 :            : 
      67                 :            :         void AddBytes(const BroString* s);
      68                 :            : 
      69                 :            :         void Add(const char* s1, const char* s2)
      70                 :            :                 { Add(s1); Add(s2); }
      71                 :            : 
      72                 :            :         void AddSP(const char* s1, const char* s2)
      73                 :            :                 { Add(s1); AddSP(s2); }
      74                 :            : 
      75                 :          0 :         void AddSP(const char* s )
      76                 :          0 :                 { Add(s); SP(); }
      77                 :            : 
      78                 :          0 :         void AddCount(bro_int_t n)
      79                 :            :                 {
      80         [ #  # ]:          0 :                 if ( ! IsReadable() )
      81                 :            :                         {
      82                 :          0 :                         Add(n);
      83                 :          0 :                         SP();
      84                 :            :                         }
      85                 :          0 :                 }
      86                 :            : 
      87                 :         13 :         void SP()       {
      88         [ +  - ]:         13 :                         if ( ! IsBinary() )
      89                 :         13 :                                 Add(" ", 0);
      90                 :         13 :                         }
      91                 :         32 :         void NL()       {
      92 [ +  - ][ -  + ]:         32 :                         if ( ! IsBinary() && ! is_short )
                 [ -  + ]
      93                 :          0 :                                 Add("\n", 0);
      94                 :         32 :                         }
      95                 :            : 
      96                 :            :         // Returns the description as a string.
      97                 :     108593 :         const char* Description() const         { return (const char*) base; }
      98                 :            : 
      99                 :          0 :         const u_char* Bytes() const     { return (const u_char *) base; }
     100                 :      71226 :         byte_vec TakeBytes()
     101                 :            :                 {
     102                 :      71226 :                 const void* t = base;
     103                 :      71226 :                 base = 0;
     104                 :      71226 :                 size = 0;
     105                 :            : 
     106                 :            :                 // Don't clear offset, as we want to still support
     107                 :            :                 // subsequent calls to Len().
     108                 :            : 
     109                 :      71226 :                 return byte_vec(t);
     110                 :            :                 }
     111                 :            : 
     112                 :      71226 :         int Len() const         { return offset; }
     113                 :            : 
     114                 :            : protected:
     115                 :            :         void Indent();
     116                 :            : 
     117                 :            :         void AddBytes(const void* bytes, unsigned int n);
     118                 :            : 
     119                 :            :         // Make buffer big enough for n bytes beyond bufp.
     120                 :            :         void Grow(unsigned int n);
     121                 :            : 
     122                 :            :         void OutOfMemory();
     123                 :            : 
     124                 :            :         desc_type type;
     125                 :            :         desc_style style;
     126                 :            : 
     127                 :            :         void* base;             // beginning of buffer
     128                 :            :         unsigned int offset;    // where we are in the buffer
     129                 :            :         unsigned int size;      // size of buffer in bytes
     130                 :            : 
     131                 :            :         BroFile* f;     // or the file we're using.
     132                 :            : 
     133                 :            :         int indent_level;
     134                 :            :         int is_short;
     135                 :            :         int want_quotes;
     136                 :            :         int do_flush;
     137                 :            :         int include_stats;
     138                 :            : };
     139                 :            : 
     140                 :            : #endif

Generated by: LCOV version 1.8