1 // CommandFactory.cpp: implementation of the CCommandFactory class.
3 //////////////////////////////////////////////////////////////////////
6 #include "CommandFactory.h"
8 #include "GlobalOptions.h"
9 #include "HelpCommand.h"
10 #include "HistoryCommand.h"
11 #include "InfoCommand.h"
12 #include "ValidateCommand.h"
13 #include "GetCommand.h"
14 #include "FileTypeCommand.h"
15 #include "PropertiesCommand.h"
17 //////////////////////////////////////////////////////////////////////
18 // Construction/Destruction
19 //////////////////////////////////////////////////////////////////////
21 CCommandFactory::CCommandFactory()
25 CCommandFactory::~CCommandFactory()
29 CCommand
* CCommandFactory::MakeCommand (std::string command
)
31 for (size_t i
= 0; i
< command
.size(); ++i
)
32 command
[i
] = char(tolower(command
[i
]));
34 CCommand
* pCommand
= NULL
;
35 if (command
== "help")
36 pCommand
= new CHelpCommand (this);
37 else if (command
== "info")
38 pCommand
= new CInfoCommand ();
39 else if (command
== "history")
40 pCommand
= new CHistoryCommand ();
41 else if (command
== "validate")
42 pCommand
= new CValidateCommand ();
43 else if (command
== "get")
44 pCommand
= new CGetCommand ();
45 else if (command
== "filetype")
46 pCommand
= new CFileTypeCommand ();
47 else if (command
== "properties")
48 pCommand
= new CPropertiesCommand ();
50 throw unknown_command (command
);
55 void CCommandFactory::PrintUsage () const
57 std::cout
<< "available commands: " << std::endl
;
60 std::cout
<< help
.GetCommandName () << ":\t\t" << help
.GetCommandDescription () << std::endl
;
63 std::cout
<< info
.GetCommandName () << ":\t\t" << info
.GetCommandDescription () << std::endl
;
65 CHistoryCommand history
;
66 std::cout
<< history
.GetCommandName () << ":\t" << history
.GetCommandDescription () << std::endl
;
68 CValidateCommand validate
;
69 std::cout
<< validate
.GetCommandName () << ":\t" << validate
.GetCommandDescription () << std::endl
;
72 std::cout
<< get
.GetCommandName () << ":\t\t" << get
.GetCommandDescription () << std::endl
;
74 CFileTypeCommand filetype
;
75 std::cout
<< filetype
.GetCommandName () << ":\t" << filetype
.GetCommandDescription () << std::endl
;
77 CPropertiesCommand properties
;
78 std::cout
<< properties
.GetCommandName () << ":\t" << properties
.GetCommandDescription () << std::endl
;