File: bitfieldmeter.h

package info (click to toggle)
xosview 1.9.3-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,056 kB
  • sloc: cpp: 10,117; makefile: 142; ansic: 32; awk: 13; sh: 8
file content (81 lines) | stat: -rw-r--r-- 2,323 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
//  Copyright (c) 1999, 2006 Thomas Waldmann (ThomasWaldmann@gmx.de)
//  based on work of Mike Romberg ( mike.romberg@noaa.gov )
//
//  This file may be distributed under terms of the GPL
//
//
#ifndef _BITFIELDMETER_H_
#define _BITFIELDMETER_H_

#include "meter.h"
#include "timer.h"

class BitFieldMeter : public Meter {
public:
  BitFieldMeter( XOSView *parent, int numBits = 1, int numfields = 1,
	      const char *title = "",
	      const char *bitlegend = "", const char *fieldlegend = "",
	      int docaptions = 0, int dolegends = 0, int dousedlegends = 0 );
  virtual ~BitFieldMeter( void );

  virtual void drawfields( int manditory = 0 );
  void drawBits( int manditory = 0 );

  void setfieldcolor( int field, const char *color );
  void setfieldcolor( int field, unsigned long color);
  void docaptions( int val ) { docaptions_ = val; }
  void dolegends( int val ) { dolegends_ = val; }
  void dousedlegends( int val ) { dousedlegends_ = val; }
  void reset( void );

  void setUsed (float val, float total);
  void setBits(int startbit, unsigned char values);

  void draw( void );
  void checkevent( void );
  void disableMeter ( void );

  virtual void checkResources( void );

protected:
  enum UsedType { INVALID_0, FLOAT, PERCENT, AUTOSCALE, INVALID_TAIL };

  int numfields_;
  float *fields_;
  float total_, used_, lastused_;
  int *lastvals_, *lastx_;
  unsigned long *colors_;
  unsigned long usedcolor_;
  UsedType print_;
  int printedZeroTotalMesg_;
  int numWarnings_;

  unsigned long onColor_, offColor_;
  char *bits_, *lastbits_;
  int numbits_;

  void SetUsedFormat ( const char * const str );
  void drawfieldlegend( void );
  void drawused( int manditory );
  bool checkX(int x, int width) const;

  void setNumFields(int n);
  void setNumBits(int n);
  char *fieldLegend_;

  void setfieldlegend(const char *fieldlegend);

private:
  Timer _timer;
protected:
  void IntervalTimerStart() { _timer.start(); }
  void IntervalTimerStop() { _timer.stop(); }
  //  Before, we simply called _timer.report(), which returns usecs.
  //  However, it suffers from wrap/overflow/sign-bit problems, so
  //  instead we use doubles for everything.
  double IntervalTimeInMicrosecs() { return _timer.report_usecs(); }
  double IntervalTimeInSecs() { return _timer.report_usecs()/1e6; }
};

#endif