Skip to content

Commit e3cc934

Browse files
authored
Merge pull request ComputationalRadiationPhysics#2532 from psychocoderHPC/topic-compileTimeString
compile time string
2 parents 6187858 + 59c1e25 commit e3cc934

File tree

14 files changed

+178
-58
lines changed

14 files changed

+178
-58
lines changed

docs/source/usage/workflows/probeParticles.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Workflow
2727
>;
2828
2929
using Probes = Particles<
30-
bmpl::string< 'p', 'r', 'o', 'b', 'e' >,
30+
PMACC_CSTRING( "probe" ),
3131
ParticleFlagsProbes,
3232
MakeSeq_t<
3333
position< position_pic >,

include/picongpu/param/speciesDefinition.param

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
#pragma once
3434

3535
#include "picongpu/simulation_defines.hpp"
36+
#include "picongpu/particles/Particles.hpp"
37+
3638
#include <pmacc/particles/Identifier.hpp>
3739
#include <pmacc/compileTime/conversion/MakeSeq.hpp>
3840
#include <pmacc/identifier/value_identifier.hpp>
39-
4041
#include <pmacc/particles/traits/FilterByFlag.hpp>
41-
#include "picongpu/particles/Particles.hpp"
42-
#include <boost/mpl/string.hpp>
42+
#include <pmacc/compileTime/String.hpp>
4343

4444
namespace picongpu
4545
{
@@ -72,7 +72,7 @@ using ParticleFlagsPhotons = bmpl::vector<
7272

7373
/* define species photons */
7474
using PIC_Photons = Particles<
75-
bmpl::string< 'p', 'h' >,
75+
PMACC_CSTRING( "ph" ),
7676
ParticleFlagsPhotons,
7777
DefaultParticleAttributes
7878
>;
@@ -97,7 +97,7 @@ using ParticleFlagsElectrons = bmpl::vector<
9797

9898
/* define species electrons */
9999
using PIC_Electrons = Particles<
100-
bmpl::string< 'e' >,
100+
PMACC_CSTRING( "e" ),
101101
ParticleFlagsElectrons,
102102
DefaultParticleAttributes
103103
>;
@@ -124,7 +124,7 @@ using ParticleFlagsIons = bmpl::vector<
124124

125125
/* define species ions */
126126
using PIC_Ions = Particles<
127-
bmpl::string< 'i' >,
127+
PMACC_CSTRING( "i" ),
128128
ParticleFlagsIons,
129129
DefaultParticleAttributes
130130
>;
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/* Copyright 2018 Rene Widera
2+
*
3+
* This file is part of PMacc.
4+
*
5+
* PMacc is free software: you can redistribute it and/or modify
6+
* it under the terms of either the GNU General Public License or
7+
* the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* PMacc is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License and the GNU Lesser General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* and the GNU Lesser General Public License along with PMacc.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
#pragma once
23+
24+
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
25+
26+
27+
namespace pmacc
28+
{
29+
namespace compileTime
30+
{
31+
/** get character of an C-string
32+
*
33+
* @tparam T_len length of the string
34+
*
35+
* @param cstr input string
36+
* @param idx index of the character
37+
* @return if x < T_len character at index idx, else '0'
38+
*/
39+
template<
40+
int T_len
41+
>
42+
constexpr auto
43+
elem_at(
44+
char const ( & cstr )[ T_len ],
45+
size_t const idx
46+
)
47+
-> char
48+
{
49+
return idx < T_len ? cstr[ idx ] : 0;
50+
}
51+
52+
/** compile time string
53+
*
54+
* The size of the instance is 1 byte.
55+
*/
56+
template< char ... T_c >
57+
struct String
58+
{
59+
/** get stored string */
60+
static auto
61+
str()
62+
-> std::string
63+
{
64+
return std::string(
65+
std::array<
66+
char,
67+
sizeof...( T_c ) + 1
68+
>( {
69+
T_c ...,
70+
// at terminal zero to support empty strings
71+
0
72+
} ).data( )
73+
);
74+
}
75+
};
76+
77+
78+
#define PMACC_CHAR_AT_N(z, n, name ) pmacc::compileTime::elem_at< sizeof(name) >( name, n ),
79+
80+
/** create a compile time string type
81+
*
82+
* Support strings with up to 64 characters.
83+
* Longer strings are cropped to 64 characters.
84+
*
85+
* usage example:
86+
* @code{.cpp}
87+
* // create an instance of the compile time string
88+
* auto particleName = PMACC_CSTRING( "electrons" ){};
89+
* // create a C++ type (can be used as template parameter)
90+
* using Electrons = PMACC_CSTRING( "electrons" );
91+
* @endcode
92+
*/
93+
94+
#define PMACC_CSTRING( str ) \
95+
/* // PMACC_CSTRING("example") is transformed in \
96+
* pmacc::compileTime::String< \
97+
* pmacc::compileTime::elem_at< sizeof("example") >( sizeof("example", 0 ), \
98+
* pmacc::compileTime::elem_at< sizeof("example") >( sizeof("example", 1 ), \
99+
* ... \
100+
* pmacc::compileTime::elem_at< sizeof("example") >( sizeof("example", 63 ), \
101+
* 0 \
102+
* > \
103+
*/ \
104+
pmacc::compileTime::String< \
105+
BOOST_PP_REPEAT_FROM_TO( \
106+
0, \
107+
/* support up to 64 charactres */ \
108+
64, \
109+
PMACC_CHAR_AT_N, \
110+
str \
111+
) \
112+
/* add a end zero because PMACC_CHAR_AT_N end with a comma */ \
113+
0 \
114+
>
115+
116+
} // namespace compileTime
117+
} // namespace pmacc

include/pmacc/particles/memory/frames/Frame.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include <boost/mpl/contains.hpp>
4848

4949
#include "pmacc/particles/ParticleDescription.hpp"
50-
#include <boost/mpl/string.hpp>
5150

5251
namespace pmacc
5352
{
@@ -156,7 +155,7 @@ public InheritLinearly<
156155

157156
HINLINE static std::string getName()
158157
{
159-
return std::string(boost::mpl::c_str<Name>::value);
158+
return Name::str();
160159
}
161160

162161
};

include/pmacc/particles/traits/ResolveAliasFromSpecies.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace traits
5050
* > ParticleFlagsElectrons;
5151
*
5252
* typedef picongpu::Particles<
53-
* bmpl::string<'e'>,
53+
* PMACC_CSTRING( "e" ),
5454
* ParticleFlagsElectrons,
5555
* DefaultAttributesSeq
5656
* > PIC_Electrons;

include/pmacc/traits/GetCTName.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#pragma once
2323

24-
#include <boost/mpl/string.hpp>
24+
#include <pmacc/compileTime/String.hpp>
2525

2626

2727
namespace pmacc
@@ -32,14 +32,14 @@ namespace traits
3232
/** Return the compile time name
3333
*
3434
* @tparam T_Type type of the object where the name is queried
35-
* @return ::type name of the object as boost::mpl::string,
35+
* @return ::type name of the object as pmacc::compileTime::String,
3636
* empty string is returned if the trait is not specified for
3737
* T_Type
3838
*/
3939
template< typename T_Type >
4040
struct GetCTName
4141
{
42-
using type = boost::mpl::string< >;
42+
using type = pmacc::compileTime::String< >;
4343
};
4444

4545
template< typename T_Type >

share/picongpu/examples/Bremsstrahlung/include/picongpu/param/speciesDefinition.param

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
#pragma once
2121

2222
#include "picongpu/simulation_defines.hpp"
23+
#include "picongpu/particles/Particles.hpp"
24+
2325
#include <pmacc/particles/Identifier.hpp>
2426
#include <pmacc/compileTime/conversion/MakeSeq.hpp>
2527
#include <pmacc/identifier/value_identifier.hpp>
26-
2728
#include <pmacc/particles/traits/FilterByFlag.hpp>
28-
#include "picongpu/particles/Particles.hpp"
29-
#include <boost/mpl/string.hpp>
29+
#include <pmacc/compileTime/String.hpp>
3030

3131

3232
namespace picongpu
@@ -65,7 +65,7 @@ using ParticleFlagsPhotons = bmpl::vector<
6565

6666
/* define species photons */
6767
using PIC_Photons = Particles<
68-
bmpl::string< 'p', 'h' >,
68+
PMACC_CSTRING( "ph" ),
6969
ParticleFlagsPhotons,
7070
DefaultParticleAttributes
7171
>;
@@ -91,7 +91,7 @@ using ParticleFlagsIons = bmpl::vector<
9191

9292
/* define species ions */
9393
using PIC_Ions = Particles<
94-
bmpl::string< 'i' >,
94+
PMACC_CSTRING( "i" ),
9595
ParticleFlagsIons,
9696
DefaultParticleAttributes
9797
>;
@@ -118,7 +118,7 @@ using ParticleFlagsElectrons = bmpl::vector<
118118

119119
/* define species electrons */
120120
using PIC_Electrons = Particles<
121-
bmpl::string< 'e' >,
121+
PMACC_CSTRING( "e" ),
122122
ParticleFlagsElectrons,
123123
DefaultParticleAttributes
124124
>;

share/picongpu/examples/Bunch/include/picongpu/param/speciesDefinition.param

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
#pragma once
2121

2222
#include "picongpu/simulation_defines.hpp"
23+
#include "picongpu/particles/Particles.hpp"
24+
2325
#include <pmacc/particles/Identifier.hpp>
2426
#include <pmacc/compileTime/conversion/MakeSeq.hpp>
2527
#include <pmacc/identifier/value_identifier.hpp>
26-
2728
#include <pmacc/particles/traits/FilterByFlag.hpp>
28-
#include "picongpu/particles/Particles.hpp"
29-
#include <boost/mpl/string.hpp>
29+
#include <pmacc/compileTime/String.hpp>
3030

3131

3232
namespace picongpu
@@ -71,7 +71,7 @@ using ParticleFlagsPhotons = bmpl::vector<
7171

7272
/* define species photons */
7373
using PIC_Photons = Particles<
74-
bmpl::string< 'p', 'h' >,
74+
PMACC_CSTRING( "ph" ),
7575
ParticleFlagsPhotons,
7676
DefaultParticleAttributes
7777
>;
@@ -96,7 +96,7 @@ using ParticleFlagsElectrons = bmpl::vector<
9696

9797
/* define species electrons */
9898
using PIC_Electrons = Particles<
99-
bmpl::string< 'e' >,
99+
PMACC_CSTRING( "e" ),
100100
ParticleFlagsElectrons,
101101
DefaultParticleAttributes
102102
>;

share/picongpu/examples/FoilLCT/include/picongpu/param/speciesDefinition.param

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
#pragma once
3434

3535
#include "picongpu/simulation_defines.hpp"
36+
#include "picongpu/particles/Particles.hpp"
37+
3638
#include <pmacc/particles/Identifier.hpp>
3739
#include <pmacc/compileTime/conversion/MakeSeq.hpp>
3840
#include <pmacc/identifier/value_identifier.hpp>
39-
4041
#include <pmacc/particles/traits/FilterByFlag.hpp>
41-
#include "picongpu/particles/Particles.hpp"
42-
#include <boost/mpl/string.hpp>
42+
#include <pmacc/compileTime/String.hpp>
4343

4444

4545
namespace picongpu
@@ -81,7 +81,7 @@ using ParticleFlagsElectrons = bmpl::vector<
8181

8282
/* define species electrons */
8383
using Electrons = Particles<
84-
bmpl::string< 'e' >,
84+
PMACC_CSTRING( "e" ),
8585
ParticleFlagsElectrons,
8686
DefaultParticleAttributes
8787
>;
@@ -117,7 +117,7 @@ using ParticleFlagsHydrogen = bmpl::vector<
117117

118118
/* define species Hydrogen */
119119
using Hydrogen = Particles<
120-
bmpl::string< 'H' >,
120+
PMACC_CSTRING( "H" ),
121121
ParticleFlagsHydrogen,
122122
IonParticleAttributes
123123
>;
@@ -153,7 +153,7 @@ using ParticleFlagsCarbon = bmpl::vector<
153153

154154
/* define species Carbon */
155155
using Carbon = Particles<
156-
bmpl::string< 'C' >,
156+
PMACC_CSTRING( "C" ),
157157
ParticleFlagsCarbon,
158158
IonParticleAttributes
159159
>;
@@ -189,7 +189,7 @@ using ParticleFlagsNitrogen = bmpl::vector<
189189

190190
/* define species Nitrogen */
191191
using Nitrogen = Particles<
192-
bmpl::string< 'N' >,
192+
PMACC_CSTRING( "N" ),
193193
ParticleFlagsNitrogen,
194194
IonParticleAttributes
195195
>;
@@ -204,7 +204,7 @@ using ParticleFlagsProbes = bmpl::vector<
204204

205205
/* define species Probe */
206206
using Probes = Particles<
207-
bmpl::string< 'p', 'r', 'o', 'b', 'e' >,
207+
PMACC_CSTRING( "probe" ),
208208
ParticleFlagsProbes,
209209
MakeSeq_t<
210210
position< position_pic >,

share/picongpu/examples/KelvinHelmholtz/include/picongpu/param/speciesDefinition.param

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
#pragma once
2121

2222
#include "picongpu/simulation_defines.hpp"
23+
#include "picongpu/particles/Particles.hpp"
24+
2325
#include <pmacc/particles/Identifier.hpp>
2426
#include <pmacc/compileTime/conversion/MakeSeq.hpp>
2527
#include <pmacc/identifier/value_identifier.hpp>
26-
2728
#include <pmacc/particles/traits/FilterByFlag.hpp>
28-
#include "picongpu/particles/Particles.hpp"
29-
#include <boost/mpl/string.hpp>
29+
#include <pmacc/compileTime/String.hpp>
3030

3131

3232
#ifndef PARAM_RADIATION
@@ -71,7 +71,7 @@ using ParticleFlagsElectrons = bmpl::vector<
7171

7272
/* define species electrons */
7373
using PIC_Electrons = Particles<
74-
bmpl::string< 'e' >,
74+
PMACC_CSTRING( "e" ),
7575
ParticleFlagsElectrons,
7676
DefaultParticleAttributes
7777
>;
@@ -98,7 +98,7 @@ using ParticleFlagsIons = bmpl::vector<
9898

9999
/* define species ions */
100100
using PIC_Ions = Particles<
101-
bmpl::string< 'i' >,
101+
PMACC_CSTRING( "i" ),
102102
ParticleFlagsIons,
103103
DefaultParticleAttributes
104104
>;

0 commit comments

Comments
 (0)