cfl_attributes.cpp
Go to the documentation of this file.
1 /** @file cfl_attributes.cpp Classes AttributeVoid and AttributeFlags */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2006 Bernd Opitz
6  Copyright (C) 2024 Thomas Moor
7  Exclusive copyright is granted to Klaus Schmidt
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 
24 #include "cfl_attributes.h"
25 
26 
27 namespace faudes {
28 
29 /***********************************************************************************
30  *
31  * implementation of AttributeVoid
32  *
33  */
34 
35 // faudes type
36 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeVoid,Type)
37 
38 // constructor
40  FAUDES_OBJCOUNT_INC("Attribute");
41 }
42 
43 // constructor
45  FAUDES_OBJCOUNT_INC("Attribute");
46  DoAssign(rOther);
47 }
48 
49  // destructor
51  FAUDES_OBJCOUNT_DEC("Attribute");
52 }
53 
54 //DoWrite(rTr,rLabel,pContext)
55 void AttributeVoid::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
56  (void) rTw; (void) rLabel; (void) pContext;
57  FD_DC("AttributeVoid::DoWrite()");
58 }
59 
60 //DoWrite(rTr,rLabel,pContext)
61 void AttributeVoid::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
62  (void) rTw; (void) rLabel; (void) pContext;
63  FD_WARN("AttributeVoid::DoWrite()");
64  rTw.WriteComment(std::string("Attr Type ") + typeid(*this).name());
65  DoWrite(rTw,rLabel,pContext);
66 }
67 
68 //DoRead(rTr,rLabel,pContext)
69 void AttributeVoid::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
70  (void) rLabel; (void) pContext; (void) rTr;
71  FD_DC("AttributeVoid::DoRead()");
72 }
73 
74 //Skip(rTr)
76  FD_DC("AttributeVoid::Skip()");
77  Token token;
78  while(rTr.Peek(token)) {
79  // break on index or name, since this is the next element
80  if((token.Type()==Token::String) || (token.Type()==Token::Integer)) {
81  break;
82  }
83  // break on end, since this is the end of the set
84  if(token.Type()==Token::End) {
85  break;
86  }
87  // break on Consecutive section, since this belongs to the set
88  if((token.Type()==Token::Begin) && (token.StringValue() == "Consecutive")) {
89  break;
90  }
91  // skip any attribute section from other file format
92  if(token.Type()==Token::Begin){
93  rTr.ReadBegin(token.StringValue());
94  rTr.ReadEnd(token.StringValue());
95  continue;
96  }
97  // skip any other token from other file format
98  rTr.Get(token);
99  }
100 }
101 
102 
103 
104 /***********************************************************************************
105  *
106  * implementation of AttributeFlags
107  *
108  */
109 
110 // faudes type
112 
113 // Assign my members
114 void AttributeFlags::DoAssign(const AttributeFlags& rSrcAttr) {
115  // call virtual clear: TODO: dont clear in virtual function
116  Clear();
117  // assign my members
118  mFlags=rSrcAttr.mFlags;
119 }
120 
121 // Test my members for equality
122 bool AttributeFlags::DoEqual(const AttributeFlags& rOther) const {
123  return ( mFlags==rOther.mFlags );
124 }
125 
126 //DoWrite(rTw)
127 // Note: you should write attributes in a section, so that
128 // the AttributeVoid read method can detect and skip them.
129 // Here, we make an execption of the rule ...
130 void AttributeFlags::DoWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
131  (void) rLabel; (void) pContext;
133  FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
134  Token token;
135  token.SetInteger16(mFlags);
136  rTw << token;
137  }
138 }
139 
140 
141 //DoXWrite(rTw)
142 void AttributeFlags::DoXWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
143  (void) rLabel; (void) pContext;
145  FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
146  Token token;
147  token.SetEmpty("Flags");
148  token.InsAttributeInteger16("value",mFlags);
149  rTw << token;
150  }
151 }
152 
153 
154 //DoRead(rTr)
155 void AttributeFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
156  (void) rLabel; (void) pContext;
157  FD_DC("AttributeFlag(" << this << ")::DoRead(tr)");
158  Token token;
159  rTr.Peek(token);
160  // faudes format
161  if(token.IsInteger16()) {
162  rTr.Get(token);
163  mFlags=token.IntegerValue();
164  return;
165  }
166  // XML format
167  if(token.IsBegin())
168  if(token.StringValue()=="Flags") {
169  rTr.ReadBegin("Flags",token);
170  mFlags=token.AttributeIntegerValue("value");
171  rTr.ReadEnd("Flags");
172  return;
173  }
174  // default
176 }
177 
178 
179 } // namespace
#define FD_DC(message)
#define FD_WARN(message)
#define FAUDES_OBJCOUNT_DEC(type)
#define FAUDES_OBJCOUNT_INC(type)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition: cfl_types.h:951
bool DoEqual(const AttributeFlags &rOther) const
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
static const fType mDefFlags
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual bool IsDefault(void) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
virtual ~AttributeVoid(void)
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
static void Skip(TokenReader &rTr)
void DoAssign(const AttributeVoid &rSrcAttr)
virtual void DoDWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
bool Get(Token &token)
bool Peek(Token &token)
void WriteComment(const std::string &rComment)
bool IsInteger16(void) const
Definition: cfl_token.cpp:224
void SetInteger16(const Int number)
Definition: cfl_token.cpp:129
const std::string & StringValue(void) const
Definition: cfl_token.cpp:178
Int AttributeIntegerValue(const std::string &name)
Definition: cfl_token.cpp:397
@ Integer
1234 (non-negative integer)
Definition: cfl_token.h:88
@ End
<\label> (end of section)
Definition: cfl_token.h:85
@ Begin
<label> (begin of section)
Definition: cfl_token.h:84
@ String
any string, space separated or quoted, must start with a letter
Definition: cfl_token.h:86
Int IntegerValue(void) const
Definition: cfl_token.cpp:167
bool IsBegin(void) const
Definition: cfl_token.cpp:259
void SetEmpty(const std::string &rName)
Definition: cfl_token.cpp:106
void InsAttributeInteger16(const std::string &name, Int value)
Definition: cfl_token.cpp:328
TokenType Type(void) const
Definition: cfl_token.cpp:199

libFAUDES 2.33b --- 2025.05.07 --- c++ api documentaion by doxygen