Skip to content

CodeStyle

Iván Cea Fontenla edited this page Feb 24, 2020 · 1 revision

Code Style

Includes

Header file

#!c++
#ifndef IMASIENGINE_FILENAME_EXT
#define IMASIENGINE_FILENAME_EXT

#include <std1>
#include <std2>
#include <lib1_1>
#include <lib1_2>
#include <lib2_1>
#include <lib2_2>

#include "folder1/projectFile1.hpp"
#include "folder1/projectFile2.hpp"
#include "folder2/projectFile1.hpp"
#include "folder2/projectFile2.hpp"


// Code


#endif // IMASIENGINE_FILENAME_EXT

Source file

#!c++
#include "headerFile.hpp"

#include <std1>
#include <std2>
#include <lib1_1>
#include <lib1_2>
#include <lib2_1>
#include <lib2_2>

#include "folder1/projectFile1.hpp"
#include "folder1/projectFile2.hpp"
#include "folder2/projectFile1.hpp"
#include "folder2/projectFile2.hpp"

using namespace namespace1
using namespace namespace2
using namespace3::name1;
using namespace3::name2;
using namespace4::name1;
using namespace4::name2;

// Code

Classes and Namespaces

Header file

#!c++

namespace NamespaceName
{
    template <
        typename T,
        typename = typename std::enable_if<
            std::is_same<T, float>::value
            || std::is_same<T, double>::value
        >::type
    >
    class ClassName
        : Base1
        , Base2
    {
    private:

        Type _privateField;
        Type _privateField2;

        static void privateStaticFunction();

        void privateFunction(Type* param1, Type* param2 = nullptr);

    protected:

        Type _protectedField;
        Type _protectedField2;

        static void protectedStaticFunction();

        void protectedFunction(Type param1, Type param2 = Type::value);
        void protectedFunction2(Type param1, Type param2 = Type::value);

    public:

        Type publicField;
        Type publicField2;

        static void publicStaticFunction();

        ClassName();
        ClassName(Type param);
        ClassName(const ClassName& className);
        ClassName(ClassName&& className);
        ~ClassName();

        void publicFunction() const;
        template <typename T> publicFunction(T* pointer);

    }
}

Source file

#!c++

namespace NamespaceName
{
    int ClassName::staticMember = 33;

    ClassName::staticMethod()
    {
        ...
    }

    ClassName::staticMethod2()
    {
        ...
    }

    ClassName::ClassName()
        : Base1()
        , Base2()
        , _myField(666.f)
    {
    }

    ClassName::ClassName(Type param)
        : Base1()
        , Base2()
        , _myField(param)
    {
    }

    ClassName::ClassName(const ClassName& className)
    {

    }

    ClassName::ClassName(ClassName&& className)
    {
    }

    ClassName::~ClassName()
    {
    }

    void ClassName::privateFunction(Type* param1, Type* param2)
    {
    }

    void ClassName::protectedFunction(Type param1, Type param2)
    {
    }

    void ClassName::publicFunction() const
    {
    }

    void ClassName::privateStaticFunction()
    {
    }

    void ClassName::protectedStaticFunction()
    {
    }

    void ClassName::publicStaticFunction()
    {
    }
}

###Nesting Namespaces###

#!c++
namespace Imasi
{
    namespace Engine
    {
        ...
    }
}

###Spaces###

#!c++
void myFunction();

int* myArray = { 1, 2, 3 };

if (true)
{
    ...
}

for (int i = 0; i < 10; i++)
{
    ...
}

while (true)
{
    ...
}

do
{
    ...
}
while (true);

switch (xxx)
{
    case Xxx:
    {
        ...
        break;
    }

    case Yyy:
    {
        ...
        break;
    }

    default:
    {
        ...
    }
}

###Initializations###

#!c++
ColorTexture2D::ColorTexture2D()
    : Texture()
    , _width(0)
    , _height(0)
{
    _type = getTextureType();
}
Clone this wiki locally