/Switch

Native C++ port of .Net Framework on Windows, macOS, Linux, iOS and android (WinForms included).

Primary LanguageC++OtherNOASSERTION

GitHub Logo


build status Build status codecov license GPL v3 © Gammasoft std c++17 ready os Windows, macOS, linux development status

The Switch framework is...

  • a collection of native C++ classes libraries, similar to the .NET Framework;
  • written in efficient, modern C++14;
  • and highly portable and available on many different platforms (Windows, macOS, Linux, iOS and android);

For more information see Switch website (or markdown Documentations) and Reference Guide

Examples

The classic first application 'Hello World'.

Console

HelloWorld.cpp:

#include <Switch/Switch>

using namespace System;

namespace HelloWorld {
  class Program {
  public:
    static void Main() {
      Console::WriteLine("Hello, World!");
    }
  };
}

startup_(HelloWorld::Program);

CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)

Project(HelloWorld)
find_package(Switch REQUIRED)
add_executable(HelloWorld HelloWorld.cpp)
target_link_libraries(HelloWorld Switch.System)

Forms

HelloWorldForm.cpp:

#include <Switch/Switch>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

namespace HelloWorld {
  class Program {
  public:
    static void Main() {
      Application::EnableVisualStyles();
      
      Button button;
      button.Text = "Click me";
      button.Location = Point(10, 10);
      button.Click += delegate_(const object& sender, const EventArgs& e) {
        MessageBox::Show("Hello, World!");
      };
      
      Form form;
      form.Text = "Hello World Form";
      form.Controls().Add(button);
      
      Application::Run(form);
    }
  };
}

startup_(HelloWorld::Program);

CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)

Project(HelloWorldForm)
find_package(Switch REQUIRED)
add_executable(HelloWorldForm ${SWITCH_GUI} HelloWorldForm.cpp)
target_link_libraries(HelloWorldForm Switch.System.Windows.Forms)

TUnit

HelloWorldTest.cpp:

#include <Switch/Switch>

using namespace TUnit::Framework;
using namespace System;

namespace UnitTests {
  class TestFixture_(HelloWorldTest) {
    void Test_(CreateStringFromLiteral) {
      string s = "Hello, World!";
      Assert::AreEqual("Hello, World!", s);
    }

    void Test_(CreateStringFromChars) {
      string s = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
      Assert::AreEqual("Hello, World!", s);
    }
  };

  AddTestFixture_(HelloWorldTest);
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)

Project(HelloWorldTest)
find_package(Switch REQUIRED)
add_executable(HelloWorldTest HelloWorldTest.cpp)
target_link_libraries(HelloWorldTest Switch.TUnit.Main)

For more examples see Examples

Download and install Switch

Before running examples you must download and install Switch. To download and install it read Downloads page or Downloads.md file.