1 #include "moviedata.hpp"
4 struct moviefile our_movie
;
6 std::vector
<char>& get_host_memory()
8 return our_movie
.host_memory
;
14 class get_gamename_cmd
: public command
17 get_gamename_cmd() throw(std::bad_alloc
) : command("get-gamename") {}
18 void invoke(const std::string
& args
, window
* win
) throw(std::bad_alloc
, std::runtime_error
)
21 throw std::runtime_error("This command does not take parameters");
22 out(win
) << "Game name is '" << our_movie
.gamename
<< "'" << std::endl
;
24 std::string
get_short_help() throw(std::bad_alloc
) { return "Get the game name"; }
25 std::string
get_long_help() throw(std::bad_alloc
)
27 return "Syntax: get-gamename\n"
28 "Prints the game name\n";
32 class print_authors_cmd
: public command
35 print_authors_cmd() throw(std::bad_alloc
) : command("show-authors") {}
36 void invoke(const std::string
& args
, window
* win
) throw(std::bad_alloc
, std::runtime_error
)
39 throw std::runtime_error("This command does not take parameters");
41 for(auto i
= our_movie
.authors
.begin(); i
!= our_movie
.authors
.end(); i
++) {
42 out(win
) << (idx
++) << ": " << i
->first
<< "|" << i
->second
<< std::endl
;
44 out(win
) << "End of authors list" << std::endl
;
46 std::string
get_short_help() throw(std::bad_alloc
) { return "Show the run authors"; }
47 std::string
get_long_help() throw(std::bad_alloc
)
49 return "Syntax: show-authors\n"
50 "Shows the run authors\n";
54 class add_author_command
: public command
57 add_author_command() throw(std::bad_alloc
) : command("add-author") {}
58 void invoke(const std::string
& args
, window
* win
) throw(std::bad_alloc
, std::runtime_error
)
60 tokensplitter
t(args
);
61 fieldsplitter
f(t
.tail());
64 if(full
== "" && nick
== "")
65 throw std::runtime_error("Bad author name");
66 our_movie
.authors
.push_back(std::make_pair(full
, nick
));
67 out(win
) << (our_movie
.authors
.size() - 1) << ": " << full
<< "|" << nick
<< std::endl
;
69 std::string
get_short_help() throw(std::bad_alloc
) { return "Add an author"; }
70 std::string
get_long_help() throw(std::bad_alloc
)
72 return "Syntax: add-author <fullname>\n"
73 "Syntax: add-author |<nickname>\n"
74 "Syntax: add-author <fullname>|<nickname>\n"
75 "Adds a new author\n";
79 class remove_author_command
: public command
82 remove_author_command() throw(std::bad_alloc
) : command("remove-author") {}
83 void invoke(const std::string
& args
, window
* win
) throw(std::bad_alloc
, std::runtime_error
)
85 tokensplitter
t(args
);
86 uint64_t index
= parse_value
<uint64_t>(t
.tail());
87 if(index
>= our_movie
.authors
.size())
88 throw std::runtime_error("No such author");
89 our_movie
.authors
.erase(our_movie
.authors
.begin() + index
);
91 std::string
get_short_help() throw(std::bad_alloc
) { return "Remove an author"; }
92 std::string
get_long_help() throw(std::bad_alloc
)
94 return "Syntax: remove-author <id>\n"
95 "Removes author with ID <id>\n";
99 class edit_author_command
: public command
102 edit_author_command() throw(std::bad_alloc
) : command("edit-author") {}
103 void invoke(const std::string
& args
, window
* win
) throw(std::bad_alloc
, std::runtime_error
)
105 tokensplitter
t(args
);
106 uint64_t index
= parse_value
<uint64_t>(t
);
107 if(index
>= our_movie
.authors
.size())
108 throw std::runtime_error("No such author");
109 fieldsplitter
f(t
.tail());
110 std::string full
= f
;
111 std::string nick
= f
;
112 if(full
== "" && nick
== "") {
113 out(win
) << "syntax: edit-author <authornum> <author>" << std::endl
;
116 our_movie
.authors
[index
] = std::make_pair(full
, nick
);
118 std::string
get_short_help() throw(std::bad_alloc
) { return "Edit an author"; }
119 std::string
get_long_help() throw(std::bad_alloc
)
121 return "Syntax: edit-author <authorid> <fullname>\n"
122 "Syntax: edit-author <authorid> |<nickname>\n"
123 "Syntax: edit-author <authorid> <fullname>|<nickname>\n"
124 "Edits author name\n";