summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/GPlot_File.h
blob: 2975c9df4580ff24c0dee89eb79e40375bf64157 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//=============================================================================
/**
 *  @file    GPlot_File.h
 *
 *  $Id$
 *
 *  @author Tim Harrison
 */
//=============================================================================


#ifndef ACE_GPlot_File_H
#define ACE_GPlot_File_H
#include /**/ "ace/pre.h"

#include "ace/Map_Manager.h"
#include "old_event_export.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Null_Mutex.h"

/**
 * @class ACE_GPlot_File
 *
 * @brief Reads and writes files in GPlot format.
 *
 * Gplot formats are as follows:
 * entry   value
 * entry   value
 * entry   value
 * ...
 * They represent x,y pairs to be graphed by GPlot.  entry's are
 * type long.  value's are type long or float.
 */
class TAO_RTOLDEvent_Export ACE_GPlot_File
{
public:
  /// Construction.
  ACE_GPlot_File (void);

  /// Destruction.  Calls this->close.
  ~ACE_GPlot_File (void);

  /**
   * If the file does not exist, create it. If the file exists open
   * the file and read all the entries into map_.  Returns 0 on
   * success, -1 on failure.
   */
  int open (const char *filename);

  /// Close the file and sync all the contents.
  void close (void);

  /// Get the entry at this value.  Returns 0 if a value was found.
  /// Returns -1 if no value has been set for <entry>.
  int get (long entry, long &value);

  /// Get the entry at this value.  Returns 0 if a value was found.
  /// Returns -1 if no value has been set for <entry>.
  int get (long entry, float &value);

  /// Set the entry at this value.
  void set (long entry, long value);

  /// Set the entry at this value.
  void set (long entry, float value);

  /// Compare <value> with the value at <entry>.  Store the largest.
  void set_greatest (long entry, long value);

  /// Compare <value> with the value at <entry>.  Store the largest.
  void set_greatest (long entry, float value);

  /// Compare <value> with the value at <entry>.  Store the smallest.
  void set_least (long entry, long value);

  /// Compare <value> with the value at <entry>.  Store the smallest.
  void set_least (long entry, float value);

  /// Dump state of the object.
  void dump (void);

private:
  // = map_ stores all values.  It is sync'ed to file when this->close
  // is called.
  typedef ACE_Map_Entry <long, char *> GPLOT_ENTRY;
  typedef ACE_Map_Manager<long, char *, ACE_Null_Mutex> GPLOT_MAP;
  typedef ACE_Map_Iterator <long, char *, ACE_Null_Mutex> GPLOT_ITERATOR;

  GPLOT_MAP map_;

  char filename_[BUFSIZ];
  FILE *write_file_;

  /// Only close once.
  int closed_;
};

#if defined (__ACE_INLINE__)
#include "GPlot_File.i"
#endif /* __ACE_INLINE__ */


#include /**/ "ace/post.h"
#endif /* ACE_GPlot_File_H */