summaryrefslogtreecommitdiff
path: root/src/options/argument_extender_implementation.h
blob: efcd55cae442bc841e750dd03fdf404254822c83 (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
/*********************                                                        */
/*! \file argument_extender_implementation.h
 ** \verbatim
 ** Top contributors (to current version):
 **   Paul Meng
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2017 by the authors listed in the file AUTHORS
 ** in the top-level source directory) and their institutional affiliations.
 ** All rights reserved.  See the file COPYING in the top-level source
 ** directory for licensing information.\endverbatim
 **
 ** \brief Utility class for extending commandline options.
 **
 ** Utility class for extending commandline options.
 **/

#include "cvc4_private.h"

#ifndef __CVC4__OPTIONS__ARGUMENT_EXTENDER_IMPLEMENTATION_H
#define __CVC4__OPTIONS__ARGUMENT_EXTENDER_IMPLEMENTATION_H

#include <cstddef>
#include <list>

#include "options/argument_extender.h"

namespace CVC4 {
namespace options {

/**
 * Utility class for implementing command line options parsing for the
 * Options class. This allows for adding preemption arguments.
 * Preemptions are processed immediately after the current argument.
 */
class ArgumentExtenderImplementation : public ArgumentExtender {
 public:
  /** Constructs a new empty ArgumentExtender.*/
  ArgumentExtenderImplementation();

  /** Destroys an ArgumentExtender and frees its associated memory.*/
  ~ArgumentExtenderImplementation();

  /**
   * This creates a copy of the current arguments list as a new array.
   * The new array is stored in argv.  The user of this function is
   * expected to own the memory of the string array, but not the
   * strings themselves.  The length of the new array is
   * numArguments() and is stored in argc.
   *
   * Preconditions:
   * - argc and argv are non-null.
   */
  void getArguments(int* argc, char*** argv) const override;

  /** Returns the number of arguments that are . */
  size_t numArguments() const override;

  /**
   * Inserts a copy of element into the front of the arguments list.
   * Preconditions: element is non-null and 0 terminated.
   */
  void pushFrontArgument(const char* element) override;

  /**
   * Inserts a copy of element into the back of the arguments list.
   * Preconditions: element is non-null and 0 terminated.
   */
  void pushBackArgument(const char* element) override;

  /** Removes the front of the arguments list.*/
  void popFrontArgument() override;

  /** Adds a new preemption to the arguments list. */
  void pushBackPreemption(const char* element) override;

  /**
   * Moves all of the preemptions into the front of the arguments
   * list.
   */
  void movePreemptionsToArguments() override;

  /** Returns true iff there is a pending preemption.*/
  bool hasPreemptions() const override;

 private:

  typedef std::list< char* > CharPointerList;

  /** Creates of copy of the arugments list.*/
  char** copyArguments() const;

  /** Allocates a copy and stores a copy in d_allocated.*/
  char* allocateCopy(const char* element);

  /** Contains a copy of the allocated strings.*/
  CharPointerList d_allocated;

  /**
   * A list of all of the preempted arguments. All of these pointers
   * in this list should be contained in d_allocated.
   */
  CharPointerList d_preemptions;

  /**
   * A list of all of the arguments. All of these pointers in this
   * list should be contained in d_allocated.
   */
  CharPointerList d_arguments;

};/* class ArgumentExtenderImplementation */

}/* CVC4::options namespace */
}/* CVC4 namespace */

#endif /* __CVC4__OPTIONS__ARGUMENT_EXTENDER_IMPLEMENTATION_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback