1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #include <Ice/ArgVector.h>
6 #include <cstring>
7 
ArgVector(int argcP,const char * const argvP[])8 IceInternal::ArgVector::ArgVector(int argcP, const char* const argvP[])
9 {
10     assert(argcP >= 0);
11     _args.resize(argcP);
12     for(int i = 0; i < argcP; ++i)
13     {
14         _args[i] = argvP[i];
15     }
16     setupArgcArgv();
17 }
18 
ArgVector(const::std::vector<::std::string> & vec)19 IceInternal::ArgVector::ArgVector(const ::std::vector< ::std::string>& vec)
20 {
21     _args = vec;
22     setupArgcArgv();
23 }
24 
ArgVector(const ArgVector & rhs)25 IceInternal::ArgVector::ArgVector(const ArgVector& rhs)
26 {
27     _args = rhs._args;
28     setupArgcArgv();
29 }
30 
31 IceInternal::ArgVector&
operator =(const ArgVector & rhs)32 IceInternal::ArgVector::operator=(const ArgVector& rhs)
33 {
34     delete[] argv;
35     argv = 0;
36     _args = rhs._args;
37     setupArgcArgv();
38     return *this;
39 }
40 
~ArgVector()41 IceInternal::ArgVector::~ArgVector()
42 {
43     delete[] argv;
44 }
45 
46 void
setupArgcArgv()47 IceInternal::ArgVector::setupArgcArgv()
48 {
49     argc = static_cast<int>(_args.size());
50     if((argv = new char*[argc + 1]) == 0)
51     {
52         throw ::std::bad_alloc();
53     }
54     for(int i = 0; i < argc; i++)
55     {
56         argv[i] = const_cast<char*>(_args[i].c_str());
57     }
58     argv[argc] = 0;
59 }
60