BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
newcolour.h
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef NEWCOLOUR_H
19#define NEWCOLOUR_H
20
21#include <iomanip>
22#include <iostream>
23#include <string>
24
25#include "published.h"
26
27namespace GMAD
28{
38 class NewColour: public Published<NewColour>
39 {
40 public:
41 std::string name;
42 double red;
43 double green;
44 double blue;
45 double alpha;
46
48 NewColour();
50 void clear();
52 void print() const;
54 template <typename T>
55 void set_value(std::string property, T value, bool bExit=true);
56
57 private:
59 void PublishMembers();
60 };
61
62 template <typename T>
63 void NewColour::set_value(std::string property, T value, bool bExit)
64 {
65#ifdef BDSDEBUG
66 std::cout << "colour> Setting value " << std::setw(25) << std::left << property << value << std::endl;
67#endif
68 // member method can throw runtime_error, catch and exit gracefully
69 try
70 {set(this,property,value);}
71 catch(const std::runtime_error&)
72 {
73 std::cerr << "Error: crystal> unknown option \"" << property << "\" with value \"" << value << "\"" << std::endl;
74 if (bExit)
75 {exit(1);}
76 else
77 {std::rethrow_exception(std::current_exception());} // to be caught by python
78 }
79 }
80}
81
82#endif
Colour definition for parser.
Definition newcolour.h:39
void print() const
Print some properties.
Definition newcolour.cc:46
void set_value(std::string property, T value, bool bExit=true)
Set methods by property name and value.
Definition newcolour.h:63
NewColour()
Constructor.
Definition newcolour.cc:22
void PublishMembers()
publish members
Definition newcolour.cc:37
void clear()
Reset.
Definition newcolour.cc:28
Class that provides introspection to its members.
Definition published.h:48
void set(NewColour *instance, const std::string &name, double value)
Definition published.h:100
Parser namespace for GMAD language. Combination of Geant4 and MAD.