C++ indenting::main
Keywords: c++ indenting, cpp indenting, code style, code formating, coding convention.
Description: Complete example of my style of indenting.
// my style of indenting
#ifndef Dh_DDMM_indenting_example_HPP_1_1
#define Dh_DDMM_indenting_example_HPP_1_1
//system files
#include
// my includes
#include "my_class.hpp"
namespace S_space_name
{
namespace S_space_name
{
template // lonely keyword 'template'
<
int N_sone_int //!< in here comes blah blah for N_some int is
,typename N_type //!< in here comes blah blah for N_some int is
>
class C_orphan
: public C_mother //!< column (public|protected|private) base_class_name and blah blah for WHY.
, private C_father //!< comma (public|protected|private) base_class_name and blah blah for WHY.
{
public:
//! blah blah for Ee_some_enums
emnum Ee_some_enums
{
Ee_seFIRST //!< blah blah for Ee_seFIRST
,Ee_seSECOND //!< blah blah for Ee_seSECOND
,Ee_seTHIRD //!< blah blah for Ee_seTHIRD
,Ee_se4th //!< blah blah for Ee_se4th
,Ee_se5th //!< blah blah for Ee_se5th
}
C_orphan(){}
~C_orphan(){}
// virtual or static is in first 'colum'.
// second 'column' is return type
// third function name
// fourth parameters.
// sixth function body. depends on their complexity it can be in class body. Prefered out.
void F_do_something (){/* doing, doing, doing, doing, doing, doing, doing, doing; 120 column is limit*/}
virtual int Fv_run_something ( int Pi_p1, float Pi_p2, std::vector const& Pi_input data ) const;
static float Fs_common_work ();
template< int N1_sone_int, typename N1_type > // one line
void F_templ_func( float P_aaaa );
protected:
private:
};
template< int N_sone_int, typename N_type > // in one line
template // multi line
<
int N1_sone_int
,typename N1_type
>
void F_templ_func( float P_aaaa )
{
}
template< int N_sone_int, typename N_type > // in one line
void //!< return type
Fv_run_something //!< in here comes blah blah for Fv_run_something
( // in first 'colum' is type, in second are 'const', '&' or '*', in third is name of parameter
// YES the comma is in the begining!
int Pi_p1 //!< Explanation for p1
,float Pi_p2 //!< Explanation for p2
,std::vector< long double > const& Pi_input data //!< Explanation for input_data
)const // here is const
{
int I_i;
// simple 'if' goes in one line. checkig with const. FIRST const then '!=', and at last 'simple_condition'
if( false == simple_condition ) // in here comes blah blah for 'if( false == simple_condition )' or in line above.
{
// 'if''s body
}
if // in here comes blah blah for 'if'
( (
( 0 == cond1 )
|| ( 1 != cond2 )
)
|| ( 3 == cond3 )
&& ( 4 != cond4 )
)
{
}
else
{
}
// simple 'for'
for( int I_iter=0; I_iter<10; I_iter++) // in here comes blah blah for 'for( int I_iter=0; I_iter<10; I_iter++)' or in line above.
{
}
for // some very complex 'for'
(
int I_index = 0
,int I_cnt = 0 // comma on the start.
;
(
( 0 == cond1 )
|| ( 1 != cond2 )
)
|| ( 3 == cond3 )
&& ( 4 != cond4 )
;
I_index ++
,I_cnt +=5 // comma on the start.
)
{
}
// simple condition take one line
while( false == simple_condition ) // in here comes blah blah for 'while( false == simple_condition )' or in line above.
{
}
// complex condition more then one line
while //// in here comes blah blah for 'while'
(
(
( 0 == cond1 )
|| ( 1 != cond2 )
)
|| ( 3 == cond3 )
&& ( 4 != cond4 )
)
{
}
switch
( (
( 0 == cond1 )
|| ( 1 != cond2 )
)
|| ( 3 == cond3 )
&& ( 4 != cond4 )
)
{ // first 'case' keyword then open bracket, then cont, then close bracket, then column, then, ...
case( En_SOME_VAL_ONE ): // in here comes blah blah for En_SOME_VAL_ONE
{
}
break;
case( En_SOME_VAL_TWO ): // in here comes blah blah for En_SOME_VAL_TWO
{
}
break;
default: // in here comes blah blah for default
{
}
break;
}
return( 0 ); //!< observe return as function
}
}
}
#endif
Every space and new line is in count in above example.
Exeption are lines which contain ONLY comment.
// my style of indenting.
#ifndef Dh_DDMM_indenting_example_HPP_1_1
#define Dh_DDMM_indenting_example_HPP_1_1
#include
#include "my_class.hpp"
namespace S_space_name
{
namespace S_space_name
{
template
<
int N_sone_int
,typename N_type
>
class C_orphan
: public C_mother
, private C_father
{
public:
emnum Ee_some_enums
{
Ee_seFIRST
,Ee_seSECOND
,Ee_seTHIRD
,Ee_se4th
,Ee_se5th
}
C_orphan(){}
~C_orphan(){}
void F_do_something (){/* doing, doing, doing, doing, doing, doing, doing, doing; 120 column is limit*/}
virtual int Fv_run_something ( int Pi_p1, float Pi_p2, std::vector const& Pi_input data ) const;
static float Fs_common_work ();
template< int N1_sone_int, typename N1_type >
void F_templ_func( float P_aaaa );
protected:
private:
};
template< int N_sone_int, typename N_type >
template
<
int N1_sone_int
,typename N1_type
>
void F_templ_func( float P_aaaa )
{
}
template< int N_sone_int, typename N_type >
void
Fv_run_something
(
int Pi_p1
,float Pi_p2
,std::vector< long double > const& Pi_input data
)const
{
int I_i;
if( false == simple_condition )
{
}
if // in here comes blah blah for 'if'
( (
( 0 == cond1 )
|| ( 1 != cond2 )
)
|| ( 3 == cond3 )
&& ( 4 != cond4 )
)
{
}
else
{
}
for( int I_iter=0; I_iter<10; I_iter++)
{
}
for
(
int I_index = 0
,int I_cnt = 0
;
(
( 0 == cond1 )
|| ( 1 != cond2 )
)
|| ( 3 == cond3 )
&& ( 4 != cond4 )
;
I_index ++
,I_cnt +=5
)
{
}
while( false == simple_condition )
{
}
while
(
(
( 0 == cond1 )
|| ( 1 != cond2 )
)
|| ( 3 == cond3 )
&& ( 4 != cond4 )
)
{
}
switch
( (
( 0 == cond1 )
|| ( 1 != cond2 )
)
|| ( 3 == cond3 )
&& ( 4 != cond4 )
)
{
case( En_SOME_VAL_ONE ):
{
}
break;
case( En_SOME_VAL_TWO ):
{
}
break;
default:
{
}
break;
}
return( 0 );
}
}
}
#endif