Commit 482dc861 authored by Christof Metzger-Kraus's avatar Christof Metzger-Kraus
Browse files

Second proposition for better error messages

parent 06e74873
......@@ -24,6 +24,11 @@
// Class AttributeHandler
// ------------------------------------------------------------------------
std::multimap<std::string,
std::pair<AttributeHandler::OwnerType,
std::string>
> AttributeHandler::attributeOwnerDictionary_s;
AttributeHandler::AttributeHandler
(const std::string &name, const std::string &help, AttributeBase *def):
RCObject(), itsName(name), itsHelp(help), itsDefault(def),
......@@ -89,3 +94,28 @@ void AttributeHandler::setReadOnly(bool flag) {
is_readonly = flag;
}
std::multimap<AttributeHandler::OwnerType, std::string> AttributeHandler::getOwner(const std::string &att) {
std::multimap<OwnerType, std::string> possibleOwners;
if (attributeOwnerDictionary_s.find(att) != attributeOwnerDictionary_s.end()) {
auto its = attributeOwnerDictionary_s.equal_range(att);
for (auto it = its.first; it != its.second; ++ it) {
auto owner = it->second;
possibleOwners.insert(std::make_pair(owner.first, owner.second));
}
}
return possibleOwners;
}
void AttributeHandler::addAttributeOwner(const std::string &owner,
const AttributeHandler::OwnerType &type,
const std::string &name) {
attributeOwnerDictionary_s.insert(std::make_pair(name,
std::make_pair(type,
owner)
)
);
}
\ No newline at end of file
......@@ -22,6 +22,7 @@
#include "AbstractObjects/AttributeBase.h"
#include "MemoryManagement/Pointer.h"
#include <string>
#include <map>
class Attribute;
class AttributeBase;
......@@ -111,6 +112,15 @@ public:
// then [b]OpalException[/b] is thrown.
void setReadOnly(bool);
enum OwnerType {
ELEMENT,
COMMAND,
SUB_COMMAND,
STATEMENT,
NONE};
static std::multimap<OwnerType, std::string> getOwner(const std::string &att);
static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name);
protected:
/// Attribute name.
......@@ -134,6 +144,8 @@ private:
AttributeHandler();
AttributeHandler(const AttributeHandler &);
void operator=(const AttributeHandler &);
static std::multimap<std::string, std::pair<OwnerType, std::string> > attributeOwnerDictionary_s;
};
#endif // OPAL_AttributeHandler_HH
#endif // OPAL_AttributeHandler_HH
\ No newline at end of file
......@@ -191,6 +191,15 @@ void Object::unregisterReference(Invalidator *ref) {
references.erase(ref);
}
void Object::registerOwnership(const AttributeHandler::OwnerType &itsClass) const {
if (getParent() != 0) return;
const unsigned int end = itsAttr.size();
const std::string name = getOpalName();
for (unsigned int i = 0; i < end; ++ i) {
AttributeHandler::addAttributeOwner(name, itsClass, itsAttr[i].getName());
}
}
void Object::printHelp(std::ostream &os) const {
*gmsg << endl << itsHelp << endl;
......@@ -335,4 +344,4 @@ Object::Object(const string &name, Object *parent):
std::ostream &operator<<(std::ostream &os, const Object &object) {
object.print(os);
return os;
}
}
\ No newline at end of file
......@@ -208,6 +208,8 @@ public:
// will no longer be notified of any change to [b]this[/b].
void unregisterReference(Invalidator *a);
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const;
/// The object attributes (see Attribute.hh).
std::vector<Attribute> itsAttr;
......
......@@ -178,6 +178,8 @@ Aperture::Aperture():
("DEFAULTAPERTURE", "The default beam screen for markers and drift generated in sequences");
itsAttr[FILE] = Attributes::makeString
("FILE", "Name of file to receive APERTURE output", "APERTURE.dat");
registerOwnership(AttributeHandler::STATEMENT);
}
Aperture::Aperture(const std::string &name, Aperture *parent):
DefaultVisitor(itsTable, false, false),
......
......@@ -167,6 +167,8 @@ MSplit::MSplit():
("STATIC", "recalculation if static equal false", true);
itsAttr[FILE] = Attributes::makeString
("FILE", "Name of file to receive SPLIT output", "SPLIT.dat");
registerOwnership(AttributeHandler::STATEMENT);
}
MSplit::MSplit(const std::string &name, MSplit *parent):
DefaultVisitor(itsTable, false, false),
......@@ -787,4 +789,4 @@ MSplit::A_row &MSplit::findRow(const PlaceRep &place) {
throw OpalException("MSplit::findRow()", "A_row \"" + os.str() +
"\" not found in twiss table \"" + getOpalName() + "\".");
#endif
}
}
\ No newline at end of file
......@@ -39,6 +39,8 @@ Call::Call():
"named file.") {
itsAttr[0] =
Attributes::makeString("FILE", "Name of file to be read", "CALL");
registerOwnership(AttributeHandler::STATEMENT);
}
......
......@@ -67,6 +67,8 @@ DumpFields::DumpFields() :
("Z_STEPS", "Number of steps in z");
itsAttr[9] = Attributes::makeString
("FILE_NAME", "Name of the file to which field data is dumped");
registerOwnership(AttributeHandler::STATEMENT);
}
DumpFields::~DumpFields() {
......@@ -186,5 +188,4 @@ void DumpFields::writeFieldThis(Component* field) {
"Something went wrong during writing "+filename_m);
}
fout.close();
}
}
\ No newline at end of file
......@@ -29,6 +29,8 @@ Echo::Echo():
Action(1, "ECHO",
"The \"ECHO\" statement sends a message to the ECHO file.") {
itsAttr[0] = Attributes::makeString("MESSAGE", "The message to be sent.");
registerOwnership(AttributeHandler::STATEMENT);
}
......
......@@ -33,6 +33,8 @@ Help::Help():
"types of an object.") {
itsAttr[0] =
Attributes::makeString("NAME", "Name of object for which help is wanted");
registerOwnership(AttributeHandler::STATEMENT);
}
......@@ -68,4 +70,4 @@ void Help::execute() {
void Help::parse(Statement &statement) {
parseShortcut(statement);
}
}
\ No newline at end of file
......@@ -193,6 +193,8 @@ Option::Option():
itsAttr[VERSION] = Attributes::makeReal
("VERSION", "Version of OPAL for which input file was written", 10000);
registerOwnership(AttributeHandler::STATEMENT);
FileStream::setEcho(echo);
rangen.init55(seed);
}
......
......@@ -35,6 +35,8 @@ PSystem::PSystem():
"operating system from all nodes.") {
itsAttr[0] = Attributes::makeString
("CMD", "A system command to be executed");
registerOwnership(AttributeHandler::COMMAND);
}
......
......@@ -126,6 +126,8 @@ Save::Save():
"followed by elements, and finally all sequences.") {
itsAttr[0] = Attributes::makeString
("FILE", "Name of file to be written", "SAVE");
registerOwnership(AttributeHandler::STATEMENT);
}
......
......@@ -74,6 +74,8 @@ Select::Select():
itsAttr[PATTERN] = Attributes::makeString
("PATTERN",
"Regular expression for matching names (default: all names)");
registerOwnership(AttributeHandler::SUB_COMMAND);
}
......
......@@ -32,6 +32,8 @@ Show::Show():
" regular expression.") {
itsAttr[0] = Attributes::makeString
("PATTERN", "Regular expression for pattern match");
registerOwnership(AttributeHandler::STATEMENT);
}
......@@ -61,4 +63,4 @@ void Show::execute() {
void Show::parse(Statement &statement) {
parseShortcut(statement);
}
}
\ No newline at end of file
......@@ -35,6 +35,8 @@ System::System():
"operating system.") {
itsAttr[0] = Attributes::makeString
("CMD", "A system command to be executed");
registerOwnership(AttributeHandler::COMMAND);
}
......
......@@ -30,6 +30,8 @@ Title::Title():
"output.") {
itsAttr[0] = Attributes::makeString
("STRING", "The title string");
registerOwnership(AttributeHandler::STATEMENT);
}
......@@ -55,4 +57,4 @@ void Title::execute() {
void Title::parse(Statement &statement) {
parseShortcut(statement);
}
}
\ No newline at end of file
......@@ -34,6 +34,8 @@ Value::Value():
"their values.") {
itsAttr[0] = Attributes::makeRealArray
("VALUE", "The values to be evaluated");
registerOwnership(AttributeHandler::STATEMENT);
}
......@@ -70,4 +72,4 @@ void Value::execute() {
void Value::parse(Statement &statement) {
parseShortcut(statement);
}
}
\ No newline at end of file
......@@ -31,6 +31,8 @@ What::What():
" values of an object.") {
itsAttr[0] = Attributes::makeString
("NAME", "Name of object to be displayed");
registerOwnership(AttributeHandler::STATEMENT);
}
......@@ -66,4 +68,4 @@ void What::execute() {
void What::parse(Statement &statement) {
parseShortcut(statement);
}
}
\ No newline at end of file
......@@ -49,7 +49,9 @@ ElementBase::ElementBase():
bgeometry_m(NULL),
sphys_m(NULL),
elType_m(isOther),
positionIsFixed(false)
positionIsFixed(false),
elementPosition_m(0.0),
elemedgeSet_m(false)
{}
......@@ -67,7 +69,9 @@ ElementBase::ElementBase(const ElementBase &right):
bgeometry_m(right.bgeometry_m),
sphys_m(right.sphys_m),
elType_m(right.elType_m),
positionIsFixed(right.positionIsFixed)
positionIsFixed(right.positionIsFixed),
elementPosition_m(right.elementPosition_m),
elemedgeSet_m(right.elemedgeSet_m)
{
if(sphys_m) {
......@@ -91,7 +95,9 @@ ElementBase::ElementBase(const std::string &name):
bgeometry_m(NULL),
sphys_m(NULL),
elType_m(isOther),
positionIsFixed(false)
positionIsFixed(false),
elementPosition_m(0.0),
elemedgeSet_m(false)
{}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment