-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Controller class, improved helpers and view renderer. Delegated the i…
…nterpolation decision to the controller from view.
- Loading branch information
1 parent
db39415
commit 5b762fb
Showing
15 changed files
with
216 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "Controller.h" | ||
|
||
//---Controller--- | ||
//---------------- | ||
string Controller::viewInputFormat = "@input-"; | ||
string Controller::viewOutputFormat = "@output-"; | ||
|
||
void Controller::prepareView() | ||
{ | ||
cout << this->viewChunk.c_str() | ||
<< endl; | ||
} | ||
|
||
void Controller::prepareViewInput() | ||
{ | ||
// Prompt the user for input | ||
} | ||
|
||
string &Controller::getViewInputFormat() | ||
{ | ||
return Controller::viewInputFormat; | ||
} | ||
|
||
string & Controller::getViewOutputFormat() | ||
{ | ||
return Controller::viewOutputFormat; | ||
} | ||
|
||
Controller::Controller() | ||
{ | ||
this->controllerName = new char[strlen("NO_CONTROLLER") + 1]; | ||
strcpy(this->controllerName, "NO_CONTROLLER"); | ||
this->viewChunk = ""; | ||
this->controllerAttributions = {}; | ||
} | ||
|
||
Controller::Controller(char *viewName, string &viewChunk, string &ViewExtension) | ||
{ | ||
string controllerName = viewName; | ||
controllerName.erase(controllerName.find(ViewExtension), ViewExtension.size()).append("Controller"); | ||
|
||
this->controllerName = new char[strlen(controllerName.c_str()) + 1]; | ||
strcpy(this->controllerName, controllerName.c_str()); | ||
this->viewChunk = viewChunk; | ||
this->controllerAttributions = controllerAttributions; | ||
|
||
this->prepareView(); | ||
} | ||
|
||
vector<string>& Controller::getControllerAttributions() | ||
{ | ||
return this->controllerAttributions; | ||
} | ||
|
||
char *Controller::getControllerName() | ||
{ | ||
return this->controllerName; | ||
} | ||
|
||
void Controller::operator=(const Controller &controller) | ||
{ | ||
if (controller.controllerName != NULL) | ||
{ | ||
delete[] this->controllerName; | ||
this->controllerName = new char[strlen(controller.controllerName) + 1]; | ||
strcpy(this->controllerName, controller.controllerName); | ||
} | ||
this->viewChunk = controller.viewChunk; | ||
this->controllerAttributions = controller.controllerAttributions; | ||
} | ||
|
||
bool Controller::hasInput(string &raw) | ||
{ | ||
return raw.find(Controller::getViewInputFormat()) != string::npos; | ||
} | ||
|
||
Controller::~Controller() | ||
{ | ||
delete[] this->controllerName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <vector> | ||
#include <string> | ||
|
||
#include "Helpers.h" | ||
|
||
using namespace std; | ||
|
||
class Controller { | ||
private: | ||
static string viewInputFormat; | ||
static string viewOutputFormat; | ||
|
||
char *controllerName; | ||
vector<string> controllerAttributions; | ||
string viewChunk; | ||
|
||
void prepareView(); | ||
void prepareViewInput(); | ||
// TODO: interpolate the view strings for output with the according variables received from the model. | ||
public: | ||
static string &getViewInputFormat(); | ||
static string &getViewOutputFormat(); | ||
static bool hasInput(string &); | ||
|
||
Controller(); | ||
Controller(char *, string &, string &); | ||
|
||
vector<string> &getControllerAttributions(); | ||
char *getControllerName(); | ||
|
||
void operator=(const Controller &); | ||
|
||
~Controller(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.