Files
sdk/runtime/bin/process_script.h
T
dgrove@google.com 4c0f559d23 Initial checkin.
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@15 260f80e4-7a28-3924-810f-c04153c831b5
2011-10-05 05:20:07 +00:00

61 lines
1.5 KiB
C++

// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef BIN_PROCESS_SCRIPT_H_
#define BIN_PROCESS_SCRIPT_H_
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
class CommandLineOptions {
public:
explicit CommandLineOptions(int max_count)
: count_(0), max_count_(max_count), arguments_(NULL) {
static const int kWordSize = sizeof(intptr_t);
arguments_ = reinterpret_cast<char **>(malloc(max_count * kWordSize));
if (arguments_ == NULL) {
max_count_ = 0;
}
}
~CommandLineOptions() {
free(arguments_);
count_ = 0;
max_count_ = 0;
arguments_ = NULL;
}
int count() const { return count_; }
char** arguments() const { return arguments_; }
char* GetArgument(int index) const {
return (index >= 0 && index < count_) ? arguments_[index] : NULL;
}
void AddArgument(char* argument) {
if (count_ < max_count_) {
arguments_[count_] = argument;
count_ += 1;
} else {
abort(); // We should never get into this situation.
}
}
void operator delete(void* pointer) { abort(); }
private:
void* operator new(size_t size);
CommandLineOptions(const CommandLineOptions&);
void operator=(const CommandLineOptions&);
int count_;
int max_count_;
char** arguments_;
};
extern Dart_Result LoadScript(const char* script_name);
#endif // BIN_PROCESS_SCRIPT_H_