Solution wide code
Posted: Sun May 15, 2011 8:02 am
Hmm it looks like my indenting gets messed up when pasted into the code block, oh well.
Hey guys, so I am writing the last part of my senior design project which is a special video player for the n900 phone. Within my project I have four"projects", a video player, video editor, and video recorder (3 different applications), and a "framework" project. The four projects all share certain variable names with one another, such as the text for the GUI buttons. The functions also share certain functionality needs such as needing the current video file directory.
My solution to this was to create one .h file, the file above, as a purely static class (all the methods are static) where I simply have all the functions I need throughout each application. Elsewhere in my solution, I can just pull the function out of my ass (not quite like pulling a singleton instance out of my ass) ie I can call
My first question, does anything think this is bad design? 2nd question, originally I tried to initialize static members but got stuck because I never instantiate an instance of the static class. The compiler lets me define a variable as such:
but not because if I were to ever create instantiate instances of the static class the linker would shit itself. To get around this, I used the functions I mentioned at the top. Any have a better idea?
Code: Select all
/// Static class methods
#ifdef _WIN32
static inline const QString VideoFilesDirectory(){
return QString("../video/");
}
#else
static inline const QString VideoFilesDirectory(){
return QString("/home/user/MyDocs/.videos/");
}
#endif
// returns the complete image path for the button name.
static inline const QString ConstructImagePath(const QString& filename){
return QString(":/resources/images/" + filename + ".png").toLower();
}
// play/pause button text
static inline const QString PlayPauseButtonTitle(){
return QString("play_pause");
}
// record/stop button text
static inline const QString RecordStopButtonTitle(){
return QString("record_stop");
}
// play button text
static inline const QString PlayButtonTitle(){
return QString("play");
}
//pause button text
static inline const QString PauseButtonTitle(){
return QString("pause");
}
//stop button text
static inline const QString StopButtonTitle(){
return QString("stop");
}
//record button text
static inline const QString RecordButtonTitle(){
return QString("record");
}
// menu button text
static inline const QString MenuButtonTitle(){
return QString("menu");
}
// forward button text
static inline const QString ForwardButtonTitle(){
return QString("forward");
}
// backwards button text
static inline const QString BackwardsButtonTitle(){
return QString("backwards");
}
// cut button text
static inline const QString CutButtonTitle(){
return QString("cut");
}
// undo button text
static inline const QString UndoButtonTitle(){
return QString("undo");
}
// empty button text
static inline const QString EmptyButtonTitle(){
return QString("empty");
}
// strip the directory path from the filename
static inline const QString StripVideoDirectoryPathFromFilename(const QString& filename){
QString t = filename;
return t.remove(0, VideoFilesDirectory().length());
}
/// Public Enumeration
enum InstanceType {VideoPlayer, VideoEditor, VideoRecorder};
private:
// no initialization of class allowed
StaticClass();
StaticClass(const StaticClass& ref);
My solution to this was to create one .h file, the file above, as a purely static class (all the methods are static) where I simply have all the functions I need throughout each application. Elsewhere in my solution, I can just pull the function out of my ass (not quite like pulling a singleton instance out of my ass) ie I can call
Code: Select all
m_InstructionLabel->setText(StaticClass::StripVideoDirectoryPathFromFilename(m_Instance->GetFilename()));
Code: Select all
static QString MenuButtonTitle;
Code: Select all
static QString MenuButtonTitle= "menu";