summaryrefslogtreecommitdiff
path: root/ace/ARGV.h
blob: d64263ec960403d4b76937d652a3349c9172ad58 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* -*- C++ -*- */
// $Id$


// ============================================================================
//
// = LIBRARY
//    ace
// 
// = FILENAME
//    ARGV.h
//
// = AUTHOR
//    Doug Schmidt, Everett Anderson
// 
// ============================================================================

#if !defined (ACE_ARGUMENT_VECTOR_H)
#define ACE_ARGUMENT_VECTOR_H

#include "ace/ACE.h"
#include "ace/Containers.h"

class ACE_Export ACE_ARGV
{
  // = TITLE
  //     Transforms a string <buf> into an <argv> style vector of
  //     strings or an <argv> style vector of string <buf>, performing
  //     environment variable substitutions if necessary.
public:
  // = Initialization and termination.
  ACE_ARGV (const char buf[], int substitute_env_args = 1);
  // Converts <buf> into an <argv>-style vector of strings.  If
  // <substitute_env_args> is enabled then we'll substitute the
  // environment variables for each $ENV encountered in the string.
  // The subscript and argv() operations are not allowed on an
  // ACE_ARGV created this way.

  ACE_ARGV (char *argv[], int substitute_env_args = 1);
  // Converts <argv> into a linear string.  If <substitute_env_args>
  // is enabled then we'll substitute the environment variables for
  // each $ENV encountered in the string.
  // The buf() operation is not allowed on an ACE_ARGV created
  // this way.

  ACE_ARGV (int substitute_env_args = 1);
  // Entry point for creating an char *[] command line iteratively
  // via the add() method.  The argv() and buf() method calls are
  // allowed, and the result is recreated when called multiple times.
  // The subscript operator is not allowed.

  ~ACE_ARGV (void);
  // Destructor.

  // = Accessor arguments.
  const char *operator[] (size_t index);
  // Returns the <index>th string in the ARGV array.  

  char **argv (void);
  // Returns the <argv> array.  Caller should not delete this memory
  // since the <ARGV> destructor will delete it.  If the caller modifies
  // the array in the iterative mode, the changes are not saved to the
  // queue.

  size_t argc (void) const;
  // Returns <argc>. 

  const char *buf (void);
  // Returns the <buf>.  Caller should not delete this memory since
  // the <ARGV> destructor will delete it.

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

  ACE_ALLOC_HOOK_DECLARE;
  // Declare the dynamic allocation hooks.

  int add (const char *next_arg);
  // Add another argument.  This only works in the ITERATIVE state.

  int state (void) const;
  // What state is this ACE_ARGV in?

  // These are the states possible via the different constructors.
  enum States 
  {
    TO_STRING = 1,    
    // ACE_ARGV converts buf[] to char *argv[]
    TO_PTR_ARRAY = 2, 
    // ACE_ARGV converts char *argv[] to buf[]
    ITERATIVE = 3    
    // Builds buf[] or char *argv[] iteratively with add()
  };

private:

  int create_buf_from_queue (void);
  // Creates buf_ from the queue, deletes previous buf_.

  void string_to_array (void);
  // Converts buf_ into the char *argv[] format.

  int substitute_env_args_;
  // Replace args with environment variable values?

  int state_;
  // Current state marker.

  size_t argc_;
  // Number of arguments in the ARGV array. 

  char **argv_;
  // The array of string arguments. 

  char *buf_;
  // Buffer containing the <argv> contents.

  size_t length_;
  // Total length of the arguments in the queue, not counting
  // separating spaces

  ACE_Unbounded_Queue<char *> queue_;
  // Queue which keeps user supplied arguments.  This is only
  // active in the "iterative" mode.
};

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

#endif /* ACE_ARGUMENT_VECTOR_H */