OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Element.h
Go to the documentation of this file.
1//
2// Class Element
3// The base class for all OPAL elements.
4// It implements the common behaviour of elements, it can also be used via
5// dynamic casting to determine whether an object represents an element.
6//
7// Each Element object contains a pointer to an OPALX beam line element,
8// known as the ``ideal'' element.
9//
10// If sharable flag is set, all occurrences of the element are supposed to
11// have the same imperfections. Thus the assembly is shared when it is used
12// more than once in beam lines or sequences.
13//
14// If the sharable flag is not set, each occurrence of the element is supposed
15// to have its own imperfections, but the same ideal representation.
16//
17// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
18// All rights reserved
19//
20// This file is part of OPAL.
21//
22// OPAL is free software: you can redistribute it and/or modify
23// it under the terms of the GNU General Public License as published by
24// the Free Software Foundation, either version 3 of the License, or
25// (at your option) any later version.
26//
27// You should have received a copy of the GNU General Public License
28// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
29//
30#ifndef OPAL_Element_HH
31#define OPAL_Element_HH
32
35
36#include <memory>
37#include <utility>
38
39class Element : public Object {
40public:
42 // Used in the SEQUENCE command.
44 IS_ENTRY, // Reference point is at element entrance.
45 IS_CENTRE, // Reference point is at element centre
46 IS_EXIT // Reference point is at element exit.
47 };
48
49 virtual ~Element();
50
52 // Return true, if the replacement is also an Element.
53 virtual bool canReplaceBy(Object* object);
54
56 // If an element with the name [b]name[/b] exists,
57 // return a pointer to that element.
58 // If no such element exists, throw [b]OpalException[/b].
59 static Element* find(const std::string& name);
60
62 // Return the string "ELEMENT".
63 virtual const std::string getCategory() const;
64
66 // If true, the object's execute() function should be traced.
67 // Always false for elements.
68 virtual bool shouldTrace() const;
69
71 // If true, the data structure should be updated before calling execute().
72 // Always false for elements.
73 virtual bool shouldUpdate() const;
74
76 virtual double getLength() const = 0;
77
79 virtual double getEntrance(ReferenceType) const;
80
82 virtual double getExit(ReferenceType) const;
83
85 // If true, all references to this name are to the same object.
86 virtual void setShared(bool);
87
89 // Return a pointer to the embedded OPALX ElementBase
90 inline ElementBase* getElement() const;
91
93 inline std::shared_ptr<ElementBase> getElementPtr() const;
94
96 inline void setElement(ElementBase*);
97 inline void setElement(std::shared_ptr<ElementBase> base);
98
99protected:
101 Element(int size, const char* name, const char* help);
102
104 Element(const std::string& name, Element* parent);
105
106private:
107 // Not implemented.
110 void operator=(const Element&);
111
112 // The embedded OPALX element.
113 std::shared_ptr<ElementBase> itsOPALXElement;
114};
115
116// Inline functions.
117// ------------------------------------------------------------------------
118
120
121inline std::shared_ptr<ElementBase> Element::getElementPtr() const { return itsOPALXElement; }
122
124 if (base == itsOPALXElement.get()) {
125 return;
126 }
127 itsOPALXElement.reset(base);
128}
129
130inline void Element::setElement(std::shared_ptr<ElementBase> base) {
131 itsOPALXElement = std::move(base);
132}
133
134#endif // OPAL_Element_HH
virtual double getEntrance(ReferenceType) const
Return arc length from origin to entrance (negative !).
Definition Element.cpp:54
virtual void setShared(bool)
Set shared flag.
Definition Element.cpp:80
virtual ~Element()
Definition Element.cpp:35
std::shared_ptr< ElementBase > getElementPtr() const
Return the embedded OPALX element as shared_ptr.
Definition Element.h:121
virtual const std::string getCategory() const
Return the object category as a string.
Definition Element.cpp:48
virtual double getLength() const =0
Return element length.
static Element * find(const std::string &name)
Find named Element.
Definition Element.cpp:39
ReferenceType
Reference for element positioning.
Definition Element.h:43
@ IS_EXIT
Definition Element.h:46
@ IS_ENTRY
Definition Element.h:44
@ IS_CENTRE
Definition Element.h:45
ElementBase * getElement() const
Return the embedded OPALX element.
Definition Element.h:119
Element(const Element &)
void operator=(const Element &)
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Definition Element.cpp:37
virtual bool shouldTrace() const
Trace flag.
Definition Element.cpp:50
void setElement(ElementBase *)
Assign new OPALX element.
Definition Element.h:123
virtual bool shouldUpdate() const
Update flag.
Definition Element.cpp:52
virtual double getExit(ReferenceType) const
Return arc length from origin to exit (positive !).
Definition Element.cpp:67
std::shared_ptr< ElementBase > itsOPALXElement
Definition Element.h:113
The base class for all OPAL objects.
Definition Object.h:45