kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #13623
Re: Damned the 'undefined global constructor order'
Attached are two that work using the "set()" function.
As a third choice:
You could also create a new constructor that actually takes an int64_t bitmap, and use
GetLayerMask() to build it.
However I would rename GetLayerMask() to something more concise:
const LAYER_SET LAYER_SET::IMPORTANT_SET = LMSK( LAYER_CU_FRONT ) | LMSK( LAYER_CU_BACK );
So there, now you have 3 choices. This, plus the attached.
Dick
P.S. I sort of LAYER_SET better than LAYER_MSK as a type name.
#include <stdio.h>
#include <stdint.h>
//#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <vector>
#include <bitset>
enum LAYER_NUM
{
LAYER_CU_FRONT,
LAYER_CU_BACK,
};
#if 0
typedef std::bitset<64> LAYER_SET;
const LAYER_SET CU_EXTERNAL = LAYER_SET().set( LAYER_CU_FRONT ).set( LAYER_CU_BACK );
int main( int argc, char** argv )
{
printf( "value %" PRIu64 "\n", *(int64_t*) &CU_EXTERNAL );
return 0;
}
#else
typedef std::bitset<64> BASE_SET;
class LAYER_SET : public BASE_SET
{
public:
static const LAYER_SET CU_EXTERNAL;
LAYER_SET( const LAYER_SET& other )
{
*this = other;
}
LAYER_SET() : BASE_SET() {}
LAYER_SET& set( int index )
{
return (LAYER_SET&) BASE_SET::set( index );
}
};
const LAYER_SET LAYER_SET::CU_EXTERNAL = LAYER_SET().set( LAYER_CU_FRONT ).set( LAYER_CU_BACK );
int main( int argc, char** argv )
{
printf( "value %" PRIu64 "\n", *(int64_t*) &LAYER_SET::CU_EXTERNAL );
return 0;
}
#endif
Follow ups
References