Command.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // Description : Classes to deal with commands
  9. #pragma once
  10. #include <QString>
  11. #include <AzCore/std/containers/vector.h>
  12. #include <AzCore/std/string/conversions.h>
  13. #include "Util/EditorUtils.h"
  14. inline AZStd::string ToString(const QString& s)
  15. {
  16. return s.toUtf8().data();
  17. }
  18. class CCommand
  19. {
  20. static inline bool FromString(int32& val, const char* s)
  21. {
  22. if (!s)
  23. {
  24. return false;
  25. }
  26. val = static_cast<int>(strtol(s, nullptr, 10));
  27. const bool parsing_error = val == 0 && errno != 0;
  28. return !parsing_error;
  29. }
  30. public:
  31. CCommand(
  32. const AZStd::string& module,
  33. const AZStd::string& name,
  34. const AZStd::string& description,
  35. const AZStd::string& example)
  36. : m_module(module)
  37. , m_name(name)
  38. , m_description(description)
  39. , m_example(example)
  40. , m_bAlsoAvailableInScripting(false)
  41. {}
  42. virtual ~CCommand()
  43. {}
  44. // Class for storing function parameters as a type-erased string
  45. struct CArgs
  46. {
  47. public:
  48. CArgs()
  49. : m_stringFlags(0)
  50. {}
  51. template <typename T>
  52. void Add(T p)
  53. {
  54. assert(m_args.size() < 8 * sizeof(m_stringFlags));
  55. m_args.push_back(ToString(p));
  56. }
  57. void Add(const char* p)
  58. {
  59. assert(m_args.size() < 8 * sizeof(m_stringFlags));
  60. m_stringFlags |= 1 << m_args.size();
  61. m_args.push_back(p);
  62. }
  63. bool IsStringArg(int i) const
  64. {
  65. if (i < 0 || i >= GetArgCount())
  66. {
  67. return false;
  68. }
  69. if (m_stringFlags & (1 << i))
  70. {
  71. return true;
  72. }
  73. else
  74. {
  75. return false;
  76. }
  77. }
  78. size_t GetArgCount() const
  79. { return m_args.size(); }
  80. const AZStd::string& GetArg(int i) const
  81. {
  82. assert(0 <= i && i < GetArgCount());
  83. return m_args[i];
  84. }
  85. private:
  86. AZStd::vector<AZStd::string> m_args;
  87. unsigned char m_stringFlags; // This is needed to quote string parameters when logging a command.
  88. };
  89. const AZStd::string& GetName() const { return m_name; }
  90. const AZStd::string& GetModule() const { return m_module; }
  91. const AZStd::string& GetDescription() const { return m_description; }
  92. const AZStd::string& GetExample() const { return m_example; }
  93. void SetAvailableInScripting() { m_bAlsoAvailableInScripting = true; };
  94. bool IsAvailableInScripting() const { return m_bAlsoAvailableInScripting; }
  95. virtual QString Execute(const CArgs& args) = 0;
  96. // Only a command without any arguments and return value can be a UI command.
  97. virtual bool CanBeUICommand() const { return false; }
  98. protected:
  99. friend class CEditorCommandManager;
  100. AZStd::string m_module;
  101. AZStd::string m_name;
  102. AZStd::string m_description;
  103. AZStd::string m_example;
  104. bool m_bAlsoAvailableInScripting;
  105. template <typename T>
  106. static AZStd::string ToString_(T t) { return ::ToString(t); }
  107. static inline AZStd::string ToString_(const char* val)
  108. { return val; }
  109. template <typename T>
  110. static bool FromString_(T& t, const char* s) { return FromString(t, s); }
  111. static inline bool FromString_(const char*& val, const char* s)
  112. { return (val = s) != 0; }
  113. void PrintHelp()
  114. {
  115. CryLogAlways("%s.%s:", m_module.c_str(), m_name.c_str());
  116. if (m_description.length() > 0)
  117. {
  118. CryLogAlways(" %s", m_description.c_str());
  119. }
  120. if (m_example.length() > 0)
  121. {
  122. CryLogAlways(" Usage: %s", m_example.c_str());
  123. }
  124. }
  125. };
  126. class CCommand0
  127. : public CCommand
  128. {
  129. public:
  130. CCommand0(const AZStd::string& module, const AZStd::string& name,
  131. const AZStd::string& description, const AZStd::string& example,
  132. const AZStd::function<void()>& functor)
  133. : CCommand(module, name, description, example)
  134. , m_functor(functor) {}
  135. // UI metadata for this command, if any
  136. struct SUIInfo
  137. {
  138. AZStd::string caption;
  139. AZStd::string tooltip;
  140. AZStd::string description;
  141. AZStd::string iconFilename;
  142. int iconIndex;
  143. int commandId; // Windows command id
  144. SUIInfo()
  145. : iconIndex(0)
  146. , commandId(0) {}
  147. };
  148. inline QString Execute([[maybe_unused]] const CArgs& args)
  149. {
  150. assert(args.GetArgCount() == 0);
  151. m_functor();
  152. return "";
  153. }
  154. const SUIInfo& GetUIInfo() const { return m_uiInfo; }
  155. virtual bool CanBeUICommand() const { return true; }
  156. protected:
  157. friend class CEditorCommandManager;
  158. AZStd::function<void()> m_functor;
  159. SUIInfo m_uiInfo;
  160. };
  161. template <typename RT>
  162. class CCommand0wRet
  163. : public CCommand
  164. {
  165. public:
  166. CCommand0wRet(const AZStd::string& module, const AZStd::string& name,
  167. const AZStd::string& description, const AZStd::string& example,
  168. const AZStd::function<RT()>& functor);
  169. QString Execute(const CArgs& args);
  170. protected:
  171. friend class CEditorCommandManager;
  172. AZStd::function<RT()> m_functor;
  173. };
  174. template <LIST(1, typename P)>
  175. class CCommand1
  176. : public CCommand
  177. {
  178. public:
  179. CCommand1(const AZStd::string& module, const AZStd::string& name,
  180. const AZStd::string& description, const AZStd::string& example,
  181. const AZStd::function<void(LIST(1, P))>& functor);
  182. QString Execute(const CArgs& args);
  183. protected:
  184. friend class CEditorCommandManager;
  185. AZStd::function<void(LIST(1, P))> m_functor;
  186. };
  187. template <LIST(1, typename P), typename RT>
  188. class CCommand1wRet
  189. : public CCommand
  190. {
  191. public:
  192. CCommand1wRet(const AZStd::string& module, const AZStd::string& name,
  193. const AZStd::string& description, const AZStd::string& example,
  194. const AZStd::function<RT(LIST(1, P))>& functor);
  195. QString Execute(const CArgs& args);
  196. protected:
  197. friend class CEditorCommandManager;
  198. AZStd::function<RT(LIST(1, P))> m_functor;
  199. };
  200. template <LIST(2, typename P)>
  201. class CCommand2
  202. : public CCommand
  203. {
  204. public:
  205. CCommand2(const AZStd::string& module, const AZStd::string& name,
  206. const AZStd::string& description, const AZStd::string& example,
  207. const AZStd::function<void(LIST(2, P))>& functor);
  208. QString Execute(const CArgs& args);
  209. protected:
  210. friend class CEditorCommandManager;
  211. AZStd::function<void(LIST(2, P))> m_functor;
  212. };
  213. template <LIST(2, typename P), typename RT>
  214. class CCommand2wRet
  215. : public CCommand
  216. {
  217. public:
  218. CCommand2wRet(const AZStd::string& module, const AZStd::string& name,
  219. const AZStd::string& description, const AZStd::string& example,
  220. const AZStd::function<RT(LIST(2, P))>& functor);
  221. QString Execute(const CArgs& args);
  222. protected:
  223. friend class CEditorCommandManager;
  224. AZStd::function<RT(LIST(2, P))> m_functor;
  225. };
  226. template <LIST(3, typename P)>
  227. class CCommand3
  228. : public CCommand
  229. {
  230. public:
  231. CCommand3(const AZStd::string& module, const AZStd::string& name,
  232. const AZStd::string& description, const AZStd::string& example,
  233. const AZStd::function<void(LIST(3, P))>& functor);
  234. QString Execute(const CArgs& args);
  235. protected:
  236. friend class CEditorCommandManager;
  237. AZStd::function<void(LIST(3, P))> m_functor;
  238. };
  239. template <LIST(3, typename P), typename RT>
  240. class CCommand3wRet
  241. : public CCommand
  242. {
  243. public:
  244. CCommand3wRet(const AZStd::string& module, const AZStd::string& name,
  245. const AZStd::string& description, const AZStd::string& example,
  246. const AZStd::function<RT(LIST(3, P))>& functor);
  247. QString Execute(const CArgs& args);
  248. protected:
  249. friend class CEditorCommandManager;
  250. AZStd::function<RT(LIST(3, P))> m_functor;
  251. };
  252. template <LIST(4, typename P)>
  253. class CCommand4
  254. : public CCommand
  255. {
  256. public:
  257. CCommand4(const AZStd::string& module, const AZStd::string& name,
  258. const AZStd::string& description, const AZStd::string& example,
  259. const AZStd::function<void(LIST(4, P))>& functor);
  260. QString Execute(const CArgs& args);
  261. protected:
  262. friend class CEditorCommandManager;
  263. AZStd::function<void(LIST(4, P))> m_functor;
  264. };
  265. template <LIST(4, typename P), typename RT>
  266. class CCommand4wRet
  267. : public CCommand
  268. {
  269. public:
  270. CCommand4wRet(const AZStd::string& module, const AZStd::string& name,
  271. const AZStd::string& description, const AZStd::string& example,
  272. const AZStd::function<RT(LIST(4, P))>& functor);
  273. QString Execute(const CArgs& args);
  274. protected:
  275. friend class CEditorCommandManager;
  276. AZStd::function<RT(LIST(4, P))> m_functor;
  277. };
  278. template <LIST(5, typename P)>
  279. class CCommand5
  280. : public CCommand
  281. {
  282. public:
  283. CCommand5(const AZStd::string& module, const AZStd::string& name,
  284. const AZStd::string& description, const AZStd::string& example,
  285. const AZStd::function<void(LIST(5, P))>& functor);
  286. QString Execute(const CArgs& args);
  287. protected:
  288. friend class CEditorCommandManager;
  289. AZStd::function<void(LIST(5, P))> m_functor;
  290. };
  291. template <LIST(6, typename P)>
  292. class CCommand6
  293. : public CCommand
  294. {
  295. public:
  296. CCommand6(const AZStd::string& module, const AZStd::string& name,
  297. const AZStd::string& description, const AZStd::string& example,
  298. const AZStd::function<void(LIST(6, P))>& functor);
  299. QString Execute(const CArgs& args);
  300. protected:
  301. friend class CEditorCommandManager;
  302. AZStd::function<void(LIST(6, P))> m_functor;
  303. };
  304. //////////////////////////////////////////////////////////////////////////
  305. template <typename RT>
  306. CCommand0wRet<RT>::CCommand0wRet(const AZStd::string& module, const AZStd::string& name,
  307. const AZStd::string& description, const AZStd::string& example,
  308. const AZStd::function<RT()>& functor)
  309. : CCommand(module, name, description, example)
  310. , m_functor(functor)
  311. {
  312. }
  313. template <typename RT>
  314. QString CCommand0wRet<RT>::Execute(const CCommand::CArgs& args)
  315. {
  316. assert(args.GetArgCount() == 0);
  317. RT ret = m_functor();
  318. return ToString_(ret).c_str();
  319. }
  320. //////////////////////////////////////////////////////////////////////////
  321. template <LIST(1, typename P)>
  322. CCommand1<LIST(1, P)>::CCommand1(const AZStd::string& module, const AZStd::string& name,
  323. const AZStd::string& description, const AZStd::string& example,
  324. const AZStd::function<void(LIST(1, P))>& functor)
  325. : CCommand(module, name, description, example)
  326. , m_functor(functor)
  327. {
  328. }
  329. template <LIST(1, typename P)>
  330. QString CCommand1<LIST(1, P)>::Execute(const CCommand::CArgs& args)
  331. {
  332. assert(args.GetArgCount() == 1);
  333. if (args.GetArgCount() < 1)
  334. {
  335. CryLogAlways("Cannot execute the command %s.%s! One argument required.", m_module.c_str(), m_name.c_str());
  336. PrintHelp();
  337. return "";
  338. }
  339. P1 p1;
  340. bool ok = FromString_(p1, args.GetArg(0).c_str());
  341. if (ok)
  342. {
  343. m_functor(p1);
  344. }
  345. else
  346. {
  347. CryLogAlways("Cannot execute the command %s.%s(%s)! Invalid argument type.",
  348. m_module, m_name, args.GetArg(0).c_str());
  349. PrintHelp();
  350. }
  351. return "";
  352. }
  353. //////////////////////////////////////////////////////////////////////////
  354. template <LIST(1, typename P), typename RT>
  355. CCommand1wRet<LIST(1, P), RT>::CCommand1wRet(const AZStd::string& module, const AZStd::string& name,
  356. const AZStd::string& description, const AZStd::string& example,
  357. const AZStd::function<RT(LIST(1, P))>& functor)
  358. : CCommand(module, name, description, example)
  359. , m_functor(functor)
  360. {
  361. }
  362. template <LIST(1, typename P), typename RT>
  363. QString CCommand1wRet<LIST(1, P), RT>::Execute(const CCommand::CArgs& args)
  364. {
  365. assert(args.GetArgCount() == 1);
  366. if (args.GetArgCount() < 1)
  367. {
  368. CryLogAlways("Cannot execute the command %s.%s! One argument required.", m_module.c_str(), m_name.c_str());
  369. PrintHelp();
  370. return "";
  371. }
  372. P1 p1;
  373. bool ok = FromString_(p1, args.GetArg(0).c_str());
  374. if (ok)
  375. {
  376. RT ret = m_functor(p1);
  377. return ToString_(ret).c_str();
  378. }
  379. else
  380. {
  381. CryLogAlways("Cannot execute the command %s.%s(%s)! Invalid argument type.",
  382. m_module, m_name, args.GetArg(0).c_str());
  383. PrintHelp();
  384. }
  385. return "";
  386. }
  387. //////////////////////////////////////////////////////////////////////////
  388. template <LIST(2, typename P)>
  389. CCommand2<LIST(2, P)>::CCommand2(const AZStd::string& module, const AZStd::string& name,
  390. const AZStd::string& description, const AZStd::string& example,
  391. const AZStd::function<void(LIST(2, P))>& functor)
  392. : CCommand(module, name, description, example)
  393. , m_functor(functor)
  394. {
  395. }
  396. template <LIST(2, typename P)>
  397. QString CCommand2<LIST(2, P)>::Execute(const CCommand::CArgs& args)
  398. {
  399. assert(args.GetArgCount() == 2);
  400. if (args.GetArgCount() < 2)
  401. {
  402. CryLogAlways("Cannot execute the command %s.%s! Two arguments required.", m_module.c_str(), m_name.c_str());
  403. PrintHelp();
  404. return "";
  405. }
  406. P1 p1;
  407. P2 p2;
  408. bool ok = FromString_(p1, args.GetArg(0).c_str())
  409. && FromString_(p2, args.GetArg(1).c_str());
  410. if (ok)
  411. {
  412. m_functor(p1, p2);
  413. }
  414. else
  415. {
  416. CryLogAlways("Cannot execute the command %s.%s(%s,%s)! Invalid argument type(s).",
  417. m_module, m_name, args.GetArg(0).c_str(), args.GetArg(1).c_str());
  418. PrintHelp();
  419. }
  420. return "";
  421. }
  422. //////////////////////////////////////////////////////////////////////////
  423. template <LIST(2, typename P), typename RT>
  424. CCommand2wRet<LIST(2, P), RT>::CCommand2wRet(const AZStd::string& module, const AZStd::string& name,
  425. const AZStd::string& description, const AZStd::string& example,
  426. const AZStd::function<RT(LIST(2, P))>& functor)
  427. : CCommand(module, name, description, example)
  428. , m_functor(functor)
  429. {
  430. }
  431. template <LIST(2, typename P), typename RT>
  432. QString CCommand2wRet<LIST(2, P), RT>::Execute(const CCommand::CArgs& args)
  433. {
  434. assert(args.GetArgCount() == 2);
  435. if (args.GetArgCount() < 2)
  436. {
  437. CryLogAlways("Cannot execute the command %s.%s! Two arguments required.", m_module.c_str(), m_name.c_str());
  438. PrintHelp();
  439. return "";
  440. }
  441. P1 p1;
  442. P2 p2;
  443. bool ok = FromString_(p1, args.GetArg(0).c_str())
  444. && FromString_(p2, args.GetArg(1).c_str());
  445. if (ok)
  446. {
  447. RT ret = m_functor(p1, p2);
  448. return ToString_(ret).c_str();
  449. }
  450. else
  451. {
  452. CryLogAlways("Cannot execute the command %s.%s(%s,%s)! Invalid argument type(s).",
  453. m_module, m_name, args.GetArg(0).c_str(), args.GetArg(1).c_str());
  454. PrintHelp();
  455. }
  456. return "";
  457. }
  458. //////////////////////////////////////////////////////////////////////////
  459. template <LIST(3, typename P)>
  460. CCommand3<LIST(3, P)>::CCommand3(const AZStd::string& module, const AZStd::string& name,
  461. const AZStd::string& description, const AZStd::string& example,
  462. const AZStd::function<void(LIST(3, P))>& functor)
  463. : CCommand(module, name, description, example)
  464. , m_functor(functor)
  465. {
  466. }
  467. template <LIST(3, typename P)>
  468. QString CCommand3<LIST(3, P)>::Execute(const CCommand::CArgs& args)
  469. {
  470. assert(args.GetArgCount() == 3);
  471. if (args.GetArgCount() < 3)
  472. {
  473. CryLogAlways("Cannot execute the command %s.%s! Three arguments required.", m_module.c_str(), m_name.c_str());
  474. PrintHelp();
  475. return "";
  476. }
  477. P1 p1;
  478. P2 p2;
  479. P3 p3;
  480. bool ok = FromString_(p1, args.GetArg(0).c_str())
  481. && FromString_(p2, args.GetArg(1).c_str())
  482. && FromString_(p3, args.GetArg(2).c_str());
  483. if (ok)
  484. {
  485. m_functor(p1, p2, p3);
  486. }
  487. else
  488. {
  489. CryLogAlways("Cannot execute the command %s.%s(%s,%s,%s)! Invalid argument type(s).",
  490. m_module, m_name, args.GetArg(0).c_str(), args.GetArg(1).c_str(), args.GetArg(2).c_str());
  491. PrintHelp();
  492. }
  493. return "";
  494. }
  495. //////////////////////////////////////////////////////////////////////////
  496. template <LIST(3, typename P), typename RT>
  497. CCommand3wRet<LIST(3, P), RT>::CCommand3wRet(const AZStd::string& module, const AZStd::string& name,
  498. const AZStd::string& description, const AZStd::string& example,
  499. const AZStd::function<RT(LIST(3, P))>& functor)
  500. : CCommand(module, name, description, example)
  501. , m_functor(functor)
  502. {
  503. }
  504. template <LIST(3, typename P), typename RT>
  505. QString CCommand3wRet<LIST(3, P), RT>::Execute(const CCommand::CArgs& args)
  506. {
  507. assert(args.GetArgCount() == 3);
  508. if (args.GetArgCount() < 3)
  509. {
  510. CryLogAlways("Cannot execute the command %s.%s! Three arguments required.", m_module.c_str(), m_name.c_str());
  511. PrintHelp();
  512. return "";
  513. }
  514. P1 p1;
  515. P2 p2;
  516. P3 p3;
  517. bool ok = FromString_(p1, args.GetArg(0).c_str())
  518. && FromString_(p2, args.GetArg(1).c_str())
  519. && FromString_(p3, args.GetArg(2).c_str());
  520. if (ok)
  521. {
  522. RT ret = m_functor(p1, p2, p3);
  523. return ToString_(ret).c_str();
  524. }
  525. else
  526. {
  527. CryLogAlways("Cannot execute the command %s.%s(%s,%s,%s)! Invalid argument type(s).",
  528. m_module, m_name, args.GetArg(0).c_str(), args.GetArg(1).c_str(), args.GetArg(2).c_str());
  529. PrintHelp();
  530. }
  531. return "";
  532. }
  533. //////////////////////////////////////////////////////////////////////////
  534. template <LIST(4, typename P)>
  535. CCommand4<LIST(4, P)>::CCommand4(const AZStd::string& module, const AZStd::string& name,
  536. const AZStd::string& description, const AZStd::string& example,
  537. const AZStd::function<void(LIST(4, P))>& functor)
  538. : CCommand(module, name, description, example)
  539. , m_functor(functor)
  540. {
  541. }
  542. template <LIST(4, typename P)>
  543. QString CCommand4<LIST(4, P)>::Execute(const CCommand::CArgs& args)
  544. {
  545. assert(args.GetArgCount() == 4);
  546. if (args.GetArgCount() < 4)
  547. {
  548. CryLogAlways("Cannot execute the command %s.%s! Four arguments required.", m_module.c_str(), m_name.c_str());
  549. PrintHelp();
  550. return "";
  551. }
  552. P1 p1;
  553. P2 p2;
  554. P3 p3;
  555. P4 p4;
  556. bool ok = FromString_(p1, args.GetArg(0).c_str())
  557. && FromString_(p2, args.GetArg(1).c_str())
  558. && FromString_(p3, args.GetArg(2).c_str())
  559. && FromString_(p4, args.GetArg(3).c_str());
  560. if (ok)
  561. {
  562. m_functor(p1, p2, p3, p4);
  563. }
  564. else
  565. {
  566. CryLogAlways("Cannot execute the command %s.%s(%s,%s,%s,%s)! Invalid argument type(s).",
  567. m_module, m_name, args.GetArg(0).c_str(), args.GetArg(1).c_str(), args.GetArg(2).c_str(),
  568. args.GetArg(3).c_str());
  569. PrintHelp();
  570. }
  571. return "";
  572. }
  573. //////////////////////////////////////////////////////////////////////////
  574. template <LIST(4, typename P), typename RT>
  575. CCommand4wRet<LIST(4, P), RT>::CCommand4wRet(const AZStd::string& module, const AZStd::string& name,
  576. const AZStd::string& description, const AZStd::string& example,
  577. const AZStd::function<RT(LIST(4, P))>& functor)
  578. : CCommand(module, name, description, example)
  579. , m_functor(functor)
  580. {
  581. }
  582. template <LIST(4, typename P), typename RT>
  583. QString CCommand4wRet<LIST(4, P), RT>::Execute(const CCommand::CArgs& args)
  584. {
  585. assert(args.GetArgCount() == 4);
  586. if (args.GetArgCount() < 4)
  587. {
  588. CryLogAlways("Cannot execute the command %s.%s! Four arguments required.", m_module.c_str(), m_name.c_str());
  589. PrintHelp();
  590. return "";
  591. }
  592. P1 p1;
  593. P2 p2;
  594. P3 p3;
  595. P4 p4;
  596. bool ok = FromString_(p1, args.GetArg(0).c_str())
  597. && FromString_(p2, args.GetArg(1).c_str())
  598. && FromString_(p3, args.GetArg(2).c_str())
  599. && FromString_(p4, args.GetArg(3).c_str());
  600. if (ok)
  601. {
  602. RT ret = m_functor(p1, p2, p3, p4);
  603. return ToString_(ret).c_str();
  604. }
  605. else
  606. {
  607. CryLogAlways("Cannot execute the command %s.%s(%s,%s,%s,%s)! Invalid argument type(s).",
  608. m_module, m_name, args.GetArg(0).c_str(), args.GetArg(1).c_str(), args.GetArg(2).c_str(),
  609. args.GetArg(3).c_str());
  610. PrintHelp();
  611. }
  612. return "";
  613. }
  614. //////////////////////////////////////////////////////////////////////////
  615. template <LIST(5, typename P)>
  616. CCommand5<LIST(5, P)>::CCommand5(const AZStd::string& module, const AZStd::string& name,
  617. const AZStd::string& description, const AZStd::string& example,
  618. const AZStd::function<void(LIST(5, P))>& functor)
  619. : CCommand(module, name, description, example)
  620. , m_functor(functor)
  621. {
  622. }
  623. template <LIST(5, typename P)>
  624. QString CCommand5<LIST(5, P)>::Execute(const CCommand::CArgs& args)
  625. {
  626. assert(args.GetArgCount() == 5);
  627. if (args.GetArgCount() < 5)
  628. {
  629. CryLogAlways("Cannot execute the command %s.%s! Five arguments required.", m_module.c_str(), m_name.c_str());
  630. PrintHelp();
  631. return "";
  632. }
  633. P1 p1;
  634. P2 p2;
  635. P3 p3;
  636. P4 p4;
  637. P5 p5;
  638. bool ok = FromString_(p1, args.GetArg(0).c_str())
  639. && FromString_(p2, args.GetArg(1).c_str())
  640. && FromString_(p3, args.GetArg(2).c_str())
  641. && FromString_(p4, args.GetArg(3).c_str())
  642. && FromString_(p5, args.GetArg(4).c_str());
  643. if (ok)
  644. {
  645. m_functor(p1, p2, p3, p4, p5);
  646. }
  647. else
  648. {
  649. CryLogAlways("Cannot execute the command %s.%s(%s,%s,%s,%s,%s)! Invalid argument type(s).",
  650. m_module, m_name, args.GetArg(0).c_str(), args.GetArg(1).c_str(), args.GetArg(2).c_str(),
  651. args.GetArg(3).c_str(), args.GetArg(4).c_str());
  652. PrintHelp();
  653. }
  654. return "";
  655. }
  656. //////////////////////////////////////////////////////////////////////////
  657. template <LIST(6, typename P)>
  658. CCommand6<LIST(6, P)>::CCommand6(const AZStd::string& module, const AZStd::string& name,
  659. const AZStd::string& description, const AZStd::string& example,
  660. const AZStd::function<void(LIST(6, P))>& functor)
  661. : CCommand(module, name, description, example)
  662. , m_functor(functor)
  663. {
  664. }
  665. template <LIST(6, typename P)>
  666. QString CCommand6<LIST(6, P)>::Execute(const CCommand::CArgs& args)
  667. {
  668. assert(args.GetArgCount() == 6);
  669. if (args.GetArgCount() < 6)
  670. {
  671. CryLogAlways("Cannot execute the command %s.%s! Six arguments required.", m_module.c_str(), m_name.c_str());
  672. PrintHelp();
  673. return "";
  674. }
  675. P1 p1 = 0;
  676. P2 p2 = 0;
  677. P3 p3 = 0;
  678. P4 p4 = 0;
  679. P5 p5 = 0;
  680. P6 p6 = 0;
  681. bool ok = FromString_(p1, args.GetArg(0).c_str())
  682. && FromString_(p2, args.GetArg(1).c_str())
  683. && FromString_(p3, args.GetArg(2).c_str())
  684. && FromString_(p4, args.GetArg(3).c_str())
  685. && FromString_(p5, args.GetArg(4).c_str())
  686. && FromString_(p6, args.GetArg(5).c_str());
  687. if (ok)
  688. {
  689. m_functor(p1, p2, p3, p4, p5, p6);
  690. }
  691. else
  692. {
  693. CryLogAlways("Cannot execute the command %s.%s(%s,%s,%s,%s,%s,%s)! Invalid argument type(s).",
  694. m_module.c_str(), m_name.c_str(), args.GetArg(0).c_str(), args.GetArg(1).c_str(), args.GetArg(2).c_str(),
  695. args.GetArg(3).c_str(), args.GetArg(4).c_str(), args.GetArg(5).c_str());
  696. PrintHelp();
  697. }
  698. return "";
  699. }