Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) RandomCode

 

RandomCode is a simple tool that creates random C++ code. I wrote it for the forums I visited: when somebody was begging for code ('Coult u pleaz gimme code 4 peer2peer programm?'), I posted a piece of random generated code with the comment 'Here it is, it just needs to have some bugs fixed!'. Programmers' humor is great, isn't it?

 

 

 

 

 

Downloads

 

 

The Windows executable of version 3.0 is created following how to cross-compile a Qt Creator project from Ubuntu to a windows executable: example 15: MinGW cross-compiling environment.

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./ToolRandomCode/ToolRandomCodeConsole.pro

 

include(../../ConsoleApplication.pri)
include(../../Libraries/Boost.pri)
<<<<<<< HEAD
<<<<<<< HEAD
include(../../Libraries/GeneralConsole.pri)
=======
=======
>>>>>>> f1bf4399a2eb2810d96a09e78b7ffcc78ed368bf

include(../../Classes/CppAbout/CppAbout.pri)
include(../../Classes/CppHelp/CppHelp.pri)
include(../../Classes/CppMenuDialog/CppMenuDialog.pri)
include(../../Classes/CppRichelBilderbeekProgram/CppRichelBilderbeekProgram.pri)
include(../../Classes/CppTrace/CppTrace.pri)
<<<<<<< HEAD
>>>>>>> f1bf4399a2eb2810d96a09e78b7ffcc78ed368bf
=======
>>>>>>> f1bf4399a2eb2810d96a09e78b7ffcc78ed368bf

#Specific, console
include(../../Classes/CppRandomCode/CppRandomCode.pri)
include(ToolRandomCodeConsole.pri)

SOURCES += main.cpp

 

 

 

 

 

Qt project file: ./ToolRandomCode/ToolRandomCodeDesktop.pro

 

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TEMPLATE = app
INCLUDEPATH += \
    ../../Classes/CppAbout \
    ../../Classes/CppQtAboutDialog \
    ../../Classes/CppQtHideAndShowDialog \
    ../../Classes/CppRandomCode

SOURCES += \
    ../../Classes/CppAbout/about.cpp \
    ../../Classes/CppQtAboutDialog/qtaboutdialog.cpp \
    ../../Classes/CppQtHideAndShowDialog/qthideandshowdialog.cpp \
    ../../Classes/CppRandomCode/randomcode.cpp \
    qtmain.cpp \
    qtrandomcodemaindialog.cpp \
    qtrandomcodemenudialog.cpp \
    randomcodemenudialog.cpp

HEADERS += \
    ../../Classes/CppAbout/about.h \
    ../../Classes/CppQtAboutDialog/qtaboutdialog.h \
    ../../Classes/CppQtHideAndShowDialog/qthideandshowdialog.h \
    ../../Classes/CppRandomCode/randomcode.h \
    qtrandomcodemaindialog.h \
    qtrandomcodemenudialog.h \
    randomcodemenudialog.h

FORMS += \
    ../../Classes/CppQtAboutDialog/qtaboutdialog.ui \
    qtrandomcodemaindialog.ui \
    qtrandomcodemenudialog.ui

RESOURCES += \
    ToolRandomCode.qrc

OTHER_FILES += \
    ../../Classes/CppQtHideAndShowDialog/Licence.txt

#
#
# Type of compile
#
#

CONFIG(release, debug|release) {
  DEFINES += NDEBUG NTRACE_BILDERBIKKEL
}

QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++

unix {
  QMAKE_CXXFLAGS += -Werror
}

#
#
# Boost
#
#

win32 {
  INCLUDEPATH += \
    ../../Libraries/boost_1_54_0
}

 

 

 

 

 

Qt project file: ./ToolRandomCode/ToolRandomCodeWebsite.pro

 

include(../../WebApplication.pri)
include(../../Libraries/BoostAll.pri)
include(../../Libraries/Wt.pri)
include(../../Libraries/GeneralConsole.pri)
include(../../Libraries/GeneralWeb.pri)

#Specific, console
include(../../Classes/CppRandomCode/CppRandomCode.pri)

#Specific, website
include(ToolRandomCodeWebsite.pri)

SOURCES += wtmain.cpp

 

 

 

 

 

./ToolRandomCode/ToolRandomCodeConsole.pri

 

INCLUDEPATH += \
    ../../Tools/ToolRandomCode

SOURCES += \
    ../../Tools/ToolRandomCode/randomcodemenudialog.cpp

HEADERS += \
    ../../Tools/ToolRandomCode/randomcodemenudialog.h

OTHER_FILES += \
    ../../Tools/ToolRandomCode/Licence.txt

RESOURCES += \
    ../../Tools/ToolRandomCode/ToolRandomCode.qrc

 

 

 

 

 

./ToolRandomCode/ToolRandomCodeDesktop.pri

 

include(../../Tools/ToolRandomCode/ToolRandomCodeConsole.pri)

FORMS += \
    ../../Tools/ToolRandomCode/qtrandomcodemenudialog.ui \
    ../../Tools/ToolRandomCode/qtrandomcodemaindialog.ui

SOURCES += \
    ../../Tools/ToolRandomCode/qtrandomcodemenudialog.cpp \
    ../../Tools/ToolRandomCode/qtrandomcodemaindialog.cpp

HEADERS += \
    ../../Tools/ToolRandomCode/qtrandomcodemenudialog.h \
    ../../Tools/ToolRandomCode/qtrandomcodemaindialog.h

 

 

 

 

 

./ToolRandomCode/ToolRandomCodeWebsite.pri

 

include(ToolRandomCodeConsole.pri)

INCLUDEPATH += ../../Tools/ToolRandomCode

SOURCES += \
    ../../Tools/ToolRandomCode/wtrandomcodegeneratedialog.cpp \
    ../../Tools/ToolRandomCode/wtrandomcodemenudialog.cpp

HEADERS += \
    ../../Tools/ToolRandomCode/wtrandomcodegeneratedialog.h \
    ../../Tools/ToolRandomCode/wtrandomcodemenudialog.h

 

 

 

 

 

./ToolRandomCode/main.cpp

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#include <algorithm>
#include <ctime>
#include <iostream>
#include <iterator>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include "randomcodemenudialog.h"
#pragma GCC diagnostic pop

int main(int argc, char *argv[])
{
  const std::vector<std::string> args {
    ribi::RandomCodeMenuDialog::ConvertArguments(argc,argv)
  };
  ribi::RandomCodeMenuDialog d;
  return d.Execute(args);
}

 

 

 

 

 

./ToolRandomCode/qtmain.cpp

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2012  Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <QApplication>
#include "qtrandomcodemenudialog.h"
#pragma GCC diagnostic pop

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  ribi::QtRandomCodeMenuDialog w;
  w.show();
  return a.exec();
}

 

 

 

 

 

./ToolRandomCode/qtrandomcodemaindialog.h

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#ifndef QTRANDOMCODEMAINDIALOG_H
#define QTRANDOMCODEMAINDIALOG_H

#include "qthideandshowdialog.h"

namespace Ui {
  class QtRandomCodeMainDialog;
}

namespace ribi {

class QtRandomCodeMainDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:
  explicit QtRandomCodeMainDialog(QWidget *parent = 0);
  QtRandomCodeMainDialog(const QtRandomCodeMainDialog&) = delete;
  QtRandomCodeMainDialog& operator=(const QtRandomCodeMainDialog&) = delete;
  ~QtRandomCodeMainDialog() noexcept;

protected:
  
  void keyPressEvent(QKeyEvent *);

private:
  Ui::QtRandomCodeMainDialog *ui;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif

private slots:
  void on_button_about_clicked();
  void on_button_generate_clicked();
};

} //~namespace ribi

#endif // QTRANDOMCODEMAINDIALOG_H

 

 

 

 

 

./ToolRandomCode/qtrandomcodemaindialog.cpp

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include "qtrandomcodemaindialog.h"

#include <string>
#include <vector>

#include <QDesktopWidget>
#include <QKeyEvent>

#include "about.h"
#include "qtaboutdialog.h"
#include "ui_qtrandomcodemaindialog.h"
#include "randomcode.h"
#include "randomcodemenudialog.h"
#include "trace.h"
#pragma GCC diagnostic pop

ribi::QtRandomCodeMainDialog::QtRandomCodeMainDialog(QWidget *parent) :
    QtHideAndShowDialog(parent),
    ui(new Ui::QtRandomCodeMainDialog)
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);

  //Put the dialog in the screen center
  const QRect screen = QApplication::desktop()->screenGeometry();
  this->setGeometry( screen.adjusted(64,64,-64,-64));
  this->move( screen.center() - this->rect().center() );

  ui->button_generate->click();
}

ribi::QtRandomCodeMainDialog::~QtRandomCodeMainDialog() noexcept
{
  delete ui;
}

void ribi::QtRandomCodeMainDialog::keyPressEvent(QKeyEvent * event)
{
  if (event->key() == Qt::Key_Escape) { close(); return; }
}

void ribi::QtRandomCodeMainDialog::on_button_generate_clicked()
{
  const std::vector<std::string> v = RandomCode::CreateRandomCode();
  ui->textEdit->clear();
  for(const std::string& s: v)
  {
    ui->textEdit->append(s.c_str());
  }
}

void ribi::QtRandomCodeMainDialog::on_button_about_clicked()
{
  About about = RandomCodeMenuDialog().GetAbout();
  //about.AddLibrary("QtConnectThreeWidget version: " + QtConnectThreeWidget::GetVersion());
  QtAboutDialog d(about);
  this->ShowChild(&d);
}

#ifndef NDEBUG
void ribi::QtRandomCodeMainDialog::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  TRACE("Starting ribi::QtRandomCodeMainDialog::Test");
  TRACE("Finished ribi::QtRandomCodeMainDialog::Test successfully");
}
#endif

 

 

 

 

 

./ToolRandomCode/qtrandomcodemenudialog.h

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#ifndef QTRANDOMCODEMENUDIALOG_H
#define QTRANDOMCODEMENUDIALOG_H

#include "qthideandshowdialog.h"

namespace Ui {
  class QtRandomCodeMenuDialog;
}

namespace ribi {

class QtRandomCodeMenuDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:
  explicit QtRandomCodeMenuDialog(QWidget *parent = 0);
  QtRandomCodeMenuDialog(const QtRandomCodeMenuDialog&) = delete;
  QtRandomCodeMenuDialog& operator=(const QtRandomCodeMenuDialog&) = delete;
  ~QtRandomCodeMenuDialog() noexcept;

protected:
  
  void keyPressEvent(QKeyEvent *);

private:
  Ui::QtRandomCodeMenuDialog *ui;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif

private slots:
  void on_button_about_clicked();
  void on_button_quit_clicked();
  void on_button_start_clicked();
};

} //~namespace ribi

#endif // QTRANDOMCODEMENUDIALOG_H

 

 

 

 

 

./ToolRandomCode/qtrandomcodemenudialog.cpp

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include "qtrandomcodemenudialog.h"

#include <QDesktopWidget>
#include <QKeyEvent>

#include "randomcodemenudialog.h"
#include "qtaboutdialog.h"
#include "qtrandomcodemaindialog.h"
#include "qthideandshowdialog.h"
#include "trace.h"
#include "ui_qtrandomcodemenudialog.h"
#pragma GCC diagnostic pop

ribi::QtRandomCodeMenuDialog::QtRandomCodeMenuDialog(QWidget *parent) :
    QtHideAndShowDialog(parent),
    ui(new Ui::QtRandomCodeMenuDialog)
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);
}

ribi::QtRandomCodeMenuDialog::~QtRandomCodeMenuDialog() noexcept
{
  delete ui;
}

void ribi::QtRandomCodeMenuDialog::keyPressEvent(QKeyEvent * event)
{
  if (event->key() == Qt::Key_Escape) { close(); return; }
}

void ribi::QtRandomCodeMenuDialog::on_button_about_clicked()
{
  About a = RandomCodeMenuDialog().GetAbout();
  a.AddLibrary("QtHideAndShowDialog version: " + QtHideAndShowDialog::GetVersion());
  QtAboutDialog d(a);
  d.setWindowIcon(this->windowIcon());
  d.setStyleSheet(this->styleSheet());
  this->ShowChild(&d);
}

void ribi::QtRandomCodeMenuDialog::on_button_quit_clicked()
{
  close();
}

void ribi::QtRandomCodeMenuDialog::on_button_start_clicked()
{
  QtRandomCodeMainDialog d;
  ShowChild(&d);
}


#ifndef NDEBUG
void ribi::QtRandomCodeMenuDialog::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  TRACE("Starting ribi::QtRandomCodeMenuDialog::Test");
  TRACE("Finished ribi::QtRandomCodeMenuDialog::Test successfully");
}
#endif

 

 

 

 

 

./ToolRandomCode/randomcodemenudialog.h

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#ifndef RANDOMCODEMENUDIALOG_H
#define RANDOMCODEMENUDIALOG_H

#include "menudialog.h"

namespace ribi {

struct RandomCodeMenuDialog : public MenuDialog
{
  About GetAbout() const noexcept;
  Help GetHelp() const noexcept;
  boost::shared_ptr<const Program> GetProgram() const noexcept;
  std::string GetVersion() const noexcept;
  std::vector<std::string> GetVersionHistory() const noexcept;

  private:
  int ExecuteSpecific(const std::vector<std::string>& argv) noexcept;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

} //~namespace ribi

#endif // RANDOMCODEMENUDIALOG_H

 

 

 

 

 

./ToolRandomCode/randomcodemenudialog.cpp

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#include "randomcode.h"

#include <cassert>
#include <ctime>
#include <iostream>
#include <iterator>

#include "randomcodemenudialog.h"
#include "richelbilderbeekprogram.h"
#include "trace.h"

int ribi::RandomCodeMenuDialog::ExecuteSpecific(const std::vector<std::string>& /*argv*/) noexcept
{
  #ifndef NDEBUG
  Test();
  #endif
  //From http://www.richelbilderbeek.nl/CppRandomizeTimer.htm
  std::srand(std::time(0));

  //Create the random code
  const std::vector<std::string> v
    = RandomCode::CreateRandomCode();

  //Display the random code
  std::copy(
    v.begin(),
    v.end(),
    std::ostream_iterator<std::string>(std::cout,"\n")
  );

  return 0;
}

ribi::About ribi::RandomCodeMenuDialog::GetAbout() const noexcept
{
  About a(
    "Richel Bilderbeek",
    "RandomCode",
    "tool to generate random C++ code",
    "the 24th of February 2014",
    "2007-2014",
    "http://www.richelbilderbeek.nl/ToolRandomCode.htm",
    GetVersion(),
    GetVersionHistory());
  a.AddLibrary("RandomCode version: " + RandomCode::GetVersion());
  return a;
}

ribi::Help ribi::RandomCodeMenuDialog::GetHelp() const noexcept
{
  return Help(
    this->GetAbout().GetFileTitle(),
    this->GetAbout().GetFileDescription(),
    {

    },
    {

    }
  );
}

boost::shared_ptr<const ribi::Program> ribi::RandomCodeMenuDialog::GetProgram() const noexcept
{
  const boost::shared_ptr<const Program> p {
    new ProgramRandomCode
  };
  assert(p);
  return p;
}

std::string ribi::RandomCodeMenuDialog::GetVersion() const noexcept
{
  return "4.3";
}

std::vector<std::string> ribi::RandomCodeMenuDialog::GetVersionHistory() const noexcept
{
  return {
    "2007-xx-xx: version 1.0: initial version in C++ Builder",
    "2010-12-03: version 2.0: port to Qt Creator",
    "2011-01-07: version 3.0: added menu, reworked file architecture",
    "2011-04-24: version 4.0: major architectural change, created web version",
    "2011-08-31: version 4.1: added Welcome picture for web version",
    "2012-12-25: version 4.2: added menu for desktop version",
    "2014-02-24: version 4.3: added command-line version"
  };
}

#ifndef NDEBUG
void ribi::RandomCodeMenuDialog::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  TRACE("Starting ribi::RandomCodeMenuDialog::Test");
  RandomCodeMenuDialog d;
  d.Execute( { "RandomCode" } );

  TRACE("Finished ribi::RandomCodeMenuDialog::Test successfully");
}
#endif

 

 

 

 

 

./ToolRandomCode/wtmain.cpp

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <Wt/WApplication>
#include <Wt/WContainerWidget>

#include "wtautoconfig.h"
#include "wtrandomcodemenudialog.h"
#pragma GCC diagnostic pop

struct WtRandomCodeApplication : public Wt::WApplication
{
  WtRandomCodeApplication(const Wt::WEnvironment& env)
  : Wt::WApplication(env)
  {
    this->setTitle("RandomCode");
    this->useStyleSheet("wt.css");
    root()->addWidget(new ribi::WtRandomCodeMenuDialog);
  }
};

Wt::WApplication * createApplication(const Wt::WEnvironment& env)
{
  return new WtRandomCodeApplication(env);
}

int main(int argc, char **argv)
{
  ribi::WtAutoConfig a(argc,argv,createApplication);
  ribi::WtAutoConfig::SaveDefaultStylesheet();
  return a.Run();
}

 

 

 

 

 

./ToolRandomCode/wtrandomcodegeneratedialog.h

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#ifndef WTRANDOMCODEGENERATEDIALOG_H
#define WTRANDOMCODEGENERATEDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <Wt/WContainerWidget>
#pragma GCC diagnostic pop

namespace Wt
{
  struct WPushButton;
  struct WTextArea;
}

namespace ribi {

struct WtRandomCodeGenerateDialog : public Wt::WContainerWidget
{
  WtRandomCodeGenerateDialog();
  WtRandomCodeGenerateDialog(const WtRandomCodeGenerateDialog&) = delete;
  WtRandomCodeGenerateDialog& operator=(const WtRandomCodeGenerateDialog&) = delete;
  private:
  Wt::WPushButton * const m_button_generate;
  Wt::WTextArea * const m_text_area;
  void OnGenerateClick();
};

} //~namespace ribi

#endif // WTRANDOMCODEGENERATEDIALOG_H

 

 

 

 

 

./ToolRandomCode/wtrandomcodegeneratedialog.cpp

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <Wt/WBreak>
#include <Wt/WPushButton>
#include <Wt/WTextArea>

#include "wtrandomcodegeneratedialog.h"
#include "randomcode.h"
#pragma GCC diagnostic pop

ribi::WtRandomCodeGenerateDialog::WtRandomCodeGenerateDialog()
  : m_button_generate(new Wt::WPushButton),
    m_text_area(new Wt::WTextArea)
{
  this->setContentAlignment(Wt::AlignCenter);
  this->addWidget(m_text_area);
  this->addWidget(new Wt::WBreak());
  this->addWidget(m_button_generate);
  m_text_area->setMinimumSize(800,400);

  m_button_generate->setText("Generate");

  m_button_generate->clicked().connect(
    this, &ribi::WtRandomCodeGenerateDialog::OnGenerateClick);

  OnGenerateClick();
}

void ribi::WtRandomCodeGenerateDialog::OnGenerateClick()
{
  const std::vector<std::string> v = RandomCode::CreateRandomCode();
  std::string s;
  for(const auto line: v)
  {
    s += line + '\n';
  }
  m_text_area->setText(s);
}

 

 

 

 

 

./ToolRandomCode/wtrandomcodemenudialog.h

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#ifndef WTRANDOMCODEMENUDIALOG_H
#define WTRANDOMCODEMENUDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <boost/signals2.hpp>

#include <Wt/WContainerWidget>
#include <Wt/WPushButton>
#pragma GCC diagnostic pop

namespace Wt
{
  struct WWidget;
}

namespace ribi {

struct WtAboutDialog;
struct WtRandomCodeGenerateDialog;

struct WtRandomCodeMenuDialog : public Wt::WContainerWidget
{
  WtRandomCodeMenuDialog();
  private:
  void CheckResources();
  WtAboutDialog * CreateNewAboutDialog();
  WtRandomCodeGenerateDialog * CreateNewGenerateDialog() const;
  Wt::WWidget * CreateNewWelcomeDialog() const;
};

} //~namespace ribi

#endif // WTRANDOMCODEMENUDIALOG_H

 

 

 

 

 

./ToolRandomCode/wtrandomcodemenudialog.cpp

 

//---------------------------------------------------------------------------
/*
RandomCode, tool to generate random C++ code
Copyright (C) 2007-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolRandomCode.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <cassert>

//#include <boost/filesystem.hpp>


#include <Wt/WBreak>
#include <Wt/WGroupBox>
#include <Wt/WImage>
#include <Wt/WLabel>
#include <Wt/WText>
#include <Wt/WStackedWidget>
#include <Wt/WMenu>

#include "about.h"
#include "fileio.h"
#include "randomcodemenudialog.h"
#include "wtaboutdialog.h"
#include "wtautoconfig.h"
#include "wtrandomcodemenudialog.h"
#include "wtrandomcodegeneratedialog.h"

//QFile must be #included after Wt header files
#include <QFile>
#pragma GCC diagnostic pop

ribi::WtRandomCodeMenuDialog::WtRandomCodeMenuDialog()
{
  CheckResources();
  this->setContentAlignment(Wt::AlignCenter);
  {
    Wt::WText * const title = new Wt::WText("RandomCode");
    title->setStyleClass("title");
    this->addWidget(title);
  }
  //Menu
  {
    Wt::WStackedWidget * const contents = new Wt::WStackedWidget;
    Wt::WMenu * const menu = new Wt::WMenu(contents,Wt::Horizontal);
    //Using CSS styleclass is the best (only?) way to display the menu well
    menu->setStyleClass("menu");
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "Welcome",
        CreateNewWelcomeDialog());
      menu->addItem(item);
    }
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "Start",
        CreateNewGenerateDialog());
      menu->addItem(item);
    }
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "About",
        CreateNewAboutDialog());
      menu->addItem(item);
    }
    //Display menu on top
    this->addWidget(menu);
    this->addWidget(new Wt::WBreak);
    //Display contents below menu
    this->addWidget(contents);
  }
}

void ribi::WtRandomCodeMenuDialog::CheckResources()
{
//Create resources
  std::vector<std::string> image_names;
  image_names.push_back("ToolRandomCodeWelcome.png");

  for(const std::string& filename: image_names)
  {

    if (!fileio::FileIo().IsRegularFile(filename))
    {
      QFile f( (std::string(":/images/") + filename).c_str() );
      f.copy(filename.c_str());
    }
    if (!fileio::FileIo().IsRegularFile(filename))
    {
      const std::string s = "File not found: " + filename;
      throw std::logic_error(s.c_str());
    }
    assert(fileio::FileIo().IsRegularFile(filename));
  }
}

ribi::WtAboutDialog * ribi::WtRandomCodeMenuDialog::CreateNewAboutDialog()
{
  About a = RandomCodeMenuDialog().GetAbout();
  a.AddLibrary("WtAutoConfig version: " + WtAutoConfig::GetVersion());
  WtAboutDialog * const d = new WtAboutDialog(a,false);
  assert(d);
  return d;
}

ribi::WtRandomCodeGenerateDialog * ribi::WtRandomCodeMenuDialog::CreateNewGenerateDialog() const
{
  WtRandomCodeGenerateDialog * const d = new WtRandomCodeGenerateDialog;
  assert(d);
  return d;
}

Wt::WWidget * ribi::WtRandomCodeMenuDialog::CreateNewWelcomeDialog() const
{
  Wt::WContainerWidget * dialog = new Wt::WContainerWidget;
  dialog->setContentAlignment(Wt::AlignCenter);
  dialog->addWidget(new Wt::WBreak);
  new Wt::WLabel("Welcome to RandomCode",dialog);
  new Wt::WBreak(dialog);
  new Wt::WBreak(dialog);
  new Wt::WLabel("The goal of RandomCode is to generate random C++ code",dialog);
  new Wt::WBreak(dialog);
  new Wt::WBreak(dialog);
  Wt::WGroupBox * const box = new Wt::WGroupBox("Explanation",dialog);
  box->addWidget(new Wt::WImage("ToolRandomCodeWelcome.png"));
  return dialog;
}

 

 

 

 

 

./ToolRandomCode/crosscompiletowindows.sh

 

#!/bin/sh
#From http://richelbilderbeek.nl/CppQtCrosscompileToWindowsExample15.htm

echo "Cross compiling to Windows"

echo "1/2: Creating Windows makefile"
i686-pc-mingw32-qmake ToolRandomCodeDesktop.pro

echo "2/2: making makefile"

make

echo "Done"

 

 

 

 

 

./ToolRandomCode/zip.sh

 

#!/bin/sh

echo "Removing user information"
rm *.user

echo "Removing possible temp file"
rm copy.txt
rm tmp.txt


echo "Creating of all main folders"

mkdir temp_zip
mkdir temp_zip/Classes
mkdir temp_zip/Tools

echo "Creating of all subfolders"

mkdir temp_zip/Classes/CppAbout
mkdir temp_zip/Classes/CppQtAboutDialog
mkdir temp_zip/Classes/CppQtHideAndShowDialog
mkdir temp_zip/Classes/CppRandomCode
mkdir temp_zip/Classes/CppWtAboutDialog
mkdir temp_zip/Classes/CppWtAutoConfig
mkdir temp_zip/Tools/ToolRandomCode

echo "Copying files"

cp ../../Classes/CppAbout/about.cpp temp_zip/Classes/CppAbout/about.cpp
cp ../../Classes/CppAbout/about.h temp_zip/Classes/CppAbout/about.h
cp ../../Classes/CppQtAboutDialog/qtaboutdialog.cpp temp_zip/Classes/CppQtAboutDialog/qtaboutdialog.cpp
cp ../../Classes/CppQtAboutDialog/qtaboutdialog.h temp_zip/Classes/CppQtAboutDialog/qtaboutdialog.h
cp ../../Classes/CppQtAboutDialog/qtaboutdialog.ui temp_zip/Classes/CppQtAboutDialog/qtaboutdialog.ui
cp ../../Classes/CppQtHideAndShowDialog/Licence.txt temp_zip/Classes/CppQtHideAndShowDialog/Licence.txt
cp ../../Classes/CppQtHideAndShowDialog/qthideandshowdialog.cpp temp_zip/Classes/CppQtHideAndShowDialog/qthideandshowdialog.cpp
cp ../../Classes/CppQtHideAndShowDialog/qthideandshowdialog.h temp_zip/Classes/CppQtHideAndShowDialog/qthideandshowdialog.h
cp ../../Classes/CppRandomCode/randomcode.cpp temp_zip/Classes/CppRandomCode/randomcode.cpp
cp ../../Classes/CppRandomCode/randomcode.h temp_zip/Classes/CppRandomCode/randomcode.h
cp ../../Classes/CppWtAboutDialog/wtaboutdialog.cpp temp_zip/Classes/CppWtAboutDialog/wtaboutdialog.cpp
cp ../../Classes/CppWtAboutDialog/wtaboutdialog.h temp_zip/Classes/CppWtAboutDialog/wtaboutdialog.h
cp ../../Classes/CppWtAutoConfig/wtautoconfig.cpp temp_zip/Classes/CppWtAutoConfig/wtautoconfig.cpp
cp ../../Classes/CppWtAutoConfig/wtautoconfig.h temp_zip/Classes/CppWtAutoConfig/wtautoconfig.h
cp ../../Tools/ToolRandomCode/Licence.txt temp_zip/Tools/ToolRandomCode/Licence.txt
cp ../../Tools/ToolRandomCode/R.png temp_zip/Tools/ToolRandomCode/R.png
cp ../../Tools/ToolRandomCode/RichelbilderbeekNlBackground.png temp_zip/Tools/ToolRandomCode/RichelbilderbeekNlBackground.png
cp ../../Tools/ToolRandomCode/ToolRandomCode.png temp_zip/Tools/ToolRandomCode/ToolRandomCode.png
cp ../../Tools/ToolRandomCode/ToolRandomCode.qrc temp_zip/Tools/ToolRandomCode/ToolRandomCode.qrc
cp ../../Tools/ToolRandomCode/ToolRandomCodeDesktop.pro temp_zip/Tools/ToolRandomCode/ToolRandomCodeDesktop.pro
cp ../../Tools/ToolRandomCode/ToolRandomCodeDesktopConsole.pro temp_zip/Tools/ToolRandomCode/ToolRandomCodeDesktopConsole.pro
cp ../../Tools/ToolRandomCode/ToolRandomCodeIcon14x14.png temp_zip/Tools/ToolRandomCode/ToolRandomCodeIcon14x14.png
cp ../../Tools/ToolRandomCode/ToolRandomCodeWebsite.pro temp_zip/Tools/ToolRandomCode/ToolRandomCodeWebsite.pro
cp ../../Tools/ToolRandomCode/ToolRandomCodeWelcome.png temp_zip/Tools/ToolRandomCode/ToolRandomCodeWelcome.png
cp ../../Tools/ToolRandomCode/main temp_zip/Tools/ToolRandomCode/main
cp ../../Tools/ToolRandomCode/main.cpp temp_zip/Tools/ToolRandomCode/main.cpp
cp ../../Tools/ToolRandomCode/qtmain.cpp temp_zip/Tools/ToolRandomCode/qtmain.cpp
cp ../../Tools/ToolRandomCode/qtrandomcodemaindialog.cpp temp_zip/Tools/ToolRandomCode/qtrandomcodemaindialog.cpp
cp ../../Tools/ToolRandomCode/qtrandomcodemaindialog.h temp_zip/Tools/ToolRandomCode/qtrandomcodemaindialog.h
cp ../../Tools/ToolRandomCode/qtrandomcodemaindialog.ui temp_zip/Tools/ToolRandomCode/qtrandomcodemaindialog.ui
cp ../../Tools/ToolRandomCode/qtrandomcodemenudialog.cpp temp_zip/Tools/ToolRandomCode/qtrandomcodemenudialog.cpp
cp ../../Tools/ToolRandomCode/qtrandomcodemenudialog.h temp_zip/Tools/ToolRandomCode/qtrandomcodemenudialog.h
cp ../../Tools/ToolRandomCode/qtrandomcodemenudialog.ui temp_zip/Tools/ToolRandomCode/qtrandomcodemenudialog.ui
cp ../../Tools/ToolRandomCode/randomcodemenudialog.cpp temp_zip/Tools/ToolRandomCode/randomcodemenudialog.cpp
cp ../../Tools/ToolRandomCode/randomcodemenudialog.h temp_zip/Tools/ToolRandomCode/randomcodemenudialog.h
cp ../../Tools/ToolRandomCode/wt.css temp_zip/Tools/ToolRandomCode/wt.css
cp ../../Tools/ToolRandomCode/wtmain.cpp temp_zip/Tools/ToolRandomCode/wtmain.cpp
cp ../../Tools/ToolRandomCode/wtrandomcodegeneratedialog.cpp temp_zip/Tools/ToolRandomCode/wtrandomcodegeneratedialog.cpp
cp ../../Tools/ToolRandomCode/wtrandomcodegeneratedialog.h temp_zip/Tools/ToolRandomCode/wtrandomcodegeneratedialog.h
cp ../../Tools/ToolRandomCode/wtrandomcodemenudialog.cpp temp_zip/Tools/ToolRandomCode/wtrandomcodemenudialog.cpp
cp ../../Tools/ToolRandomCode/wtrandomcodemenudialog.h temp_zip/Tools/ToolRandomCode/wtrandomcodemenudialog.h
cp ../../Tools/ToolRandomCode/zip.sh temp_zip/Tools/ToolRandomCode/zip.sh

FILENAME="ToolRandomCodeSource"
ZIP_FILENAME=$FILENAME".zip"

echo "Compressing files"

cd temp_zip
zip -r $FILENAME Classes
zip -r $FILENAME Tools
cd ..
cp "temp_zip/"$ZIP_FILENAME $ZIP_FILENAME

echo "Cleaning up"

echo "Emptying subfolders"

rm temp_zip/Classes/CppAbout/*.*
rm temp_zip/Classes/CppQtAboutDialog/*.*
rm temp_zip/Classes/CppQtHideAndShowDialog/*.*
rm temp_zip/Classes/CppRandomCode/*.*
rm temp_zip/Classes/CppWtAboutDialog/*.*
rm temp_zip/Classes/CppWtAutoConfig/*.*
rm temp_zip/Tools/ToolRandomCode/*.*

echo "Removing subfolders"

rmdir temp_zip/Classes/CppAbout
rmdir temp_zip/Classes/CppQtAboutDialog
rmdir temp_zip/Classes/CppQtHideAndShowDialog
rmdir temp_zip/Classes/CppRandomCode
rmdir temp_zip/Classes/CppWtAboutDialog
rmdir temp_zip/Classes/CppWtAutoConfig
rmdir temp_zip/Tools/ToolRandomCode

echo "Removing main folders"

rmdir temp_zip/Classes
rmdir temp_zip/Tools

echo "Removing temporary folder"

rm temp_zip/*.*
rmdir temp_zip

echo "Done"

# CreateQtProjectZipFile, version 1.3
# Copyright (C) 2012 Richel Bilderbeek
# Programmed on the 10th of June 2012
# by Richel Bilderbeek
#
# CreateQtProjectZipFile can be downloaded from http://www.richelbilderbeek.nl/ToolCreateQtProjectZipFile.htm
# Licenced under GPL 3.0

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml