summaryrefslogtreecommitdiff
path: root/ACE/apps/Gateway/Gateway/File_Parser.h
blob: 1e2fdae4990b6a532a8f3ba435e309b1d17f288e (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
/* -*- C++ -*- */

//=============================================================================
/**
 *  @file    File_Parser.h
 *
 *  @author Doug Schmidt
 */
//=============================================================================


#ifndef _FILE_PARSER
#define _FILE_PARSER

#include "ace/Basic_Types.h"

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

/**
 * @class FPRT
 *
 * @brief This class serves as a namespace for the <Return_Type>.
 */
class FPRT
{
public:
  enum Return_Type
  {
    RT_EOLINE,
    RT_EOFILE,
    RT_SUCCESS,
    RT_COMMENT,
    RT_DEFAULT,
    RT_PARSE_ERROR
  };
};

/**
 * @class File_Parser
 *
 * @brief Class used to parse the configuration file for the
 * <Consumer_Map>.
 */
template <class ENTRY>
class File_Parser
{
public:
  /// Destructor.
  virtual ~File_Parser ();

  // = Open and Close the file specified
  int open (const ACE_TCHAR filename[]);
  int close ();

  virtual FPRT::Return_Type read_entry (ENTRY &entry,
                                        int &line_number) = 0;
  // Pure virtual hook that subclasses override and use the protected
  // methods to fill in the <entry>.

protected:
  /// Read the next ASCII word.
  FPRT::Return_Type getword (char buf[]);

  /// Read the next integer.
  FPRT::Return_Type getint (ACE_INT32 &value);

  /**
   * Read the next "word," which is demarcated by <delimiter>s.
   *
   * @@ This function is inherently flawed since it doesn't take a
   * count of the size of <buf>...
   */
  FPRT::Return_Type readword (char buf[]);

  /// Returns true if <ch> is a delimiter, i.e., ' ', ',', or '\t'.
  int delimiter (char ch);

  /// Returns true if <ch> is the comment character, i.e., '#'.
  int comments (char ch);

  /// Skips to the remainder of a line, e.g., when we find a comment
  /// character.
  int skipline ();

  /// Pointer to the file we're reading.
  FILE *infile_;
};

#include "File_Parser.cpp"

#endif /* _FILE_PARSER */