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  Exclusive copyright is granted to Klaus Schmidt
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21 
22 
23 #include "cfl_attributes.h"
24 
25 
26 namespace faudes {
27 
28 /***********************************************************************************
29  *
30  * implementation of AttributeVoid
31  *
32  */
33 
34 // faudes type
35 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeVoid,Type)
36 
37 // constructor
39  FAUDES_OBJCOUNT_INC("Attribute");
40 }
41 
42 // constructor
44  FAUDES_OBJCOUNT_INC("Attribute");
45  DoAssign(rOther);
46 }
47 
48  // destructor
50  FAUDES_OBJCOUNT_DEC("Attribute");
51 }
52 
53 //DoWrite(rTr,rLabel,pContext)
54 void AttributeVoid::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
55  (void) rTw; (void) rLabel; (void) pContext;
56  FD_DC("AttributeVoid::DoWrite()");
57 }
58 
59 //DoWrite(rTr,rLabel,pContext)
60 void AttributeVoid::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
61  (void) rTw; (void) rLabel; (void) pContext;
62  FD_WARN("AttributeVoid::DoWrite()");
63  rTw.WriteComment(std::string("Attr Type ") + typeid(*this).name());
64  DoWrite(rTw,rLabel,pContext);
65 }
66 
67 //DoRead(rTr,rLabel,pContext)
68 void AttributeVoid::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
69  (void) rLabel; (void) pContext; (void) rTr;
70  FD_DC("AttributeVoid::DoRead()");
71 }
72 
73 //Skip(rTr)
75  FD_DC("AttributeVoid::Skip()");
76  Token token;
77  while(rTr.Peek(token)) {
78  // break on index or name, since this is the next element
79  if((token.Type()==Token::String) || (token.Type()==Token::Integer)) {
80  break;
81  }
82  // break on end, since this is the end of the set
83  if(token.Type()==Token::End) {
84  break;
85  }
86  // break on Consecutive section, since this belongs to the set
87  if((token.Type()==Token::Begin) && (token.StringValue() == "Consecutive")) {
88  break;
89  }
90  // skip any attribute section from other file format
91  if(token.Type()==Token::Begin){
92  rTr.ReadBegin(token.StringValue());
93  rTr.ReadEnd(token.StringValue());
94  continue;
95  }
96  // skip any other token from other file format
97  rTr.Get(token);
98  }
99 }
100 
101 
102 
103 /***********************************************************************************
104  *
105  * implementation of AttributeFlags
106  *
107  */
108 
109 // faudes type
111 
112 // Assign my members
113 void AttributeFlags::DoAssign(const AttributeFlags& rSrcAttr) {
114  // call virtual clear: TODO: dont clear in virtual function
115  Clear();
116  // assign my members
117  mFlags=rSrcAttr.mFlags;
118 }
119 
120 // Test my members for equality
121 bool AttributeFlags::DoEqual(const AttributeFlags& rOther) const {
122  return ( mFlags==rOther.mFlags );
123 }
124 
125 //DoWrite(rTw)
126 // Note: you should write attributes in a section, so that
127 // the AttributeVoid read method can detect and skip them.
128 // Here, we make an execption of the rule ...
129 void AttributeFlags::DoWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
130  (void) rLabel; (void) pContext;
132  FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
133  Token token;
134  token.SetInteger16(mFlags);
135  rTw << token;
136  }
137 }
138 
139 
140 //DoXWrite(rTw)
141 void AttributeFlags::DoXWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
142  (void) rLabel; (void) pContext;
144  FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
145  Token token;
146  token.SetEmpty("Flags");
147  token.InsAttributeInteger16("value",mFlags);
148  rTw << token;
149  }
150 }
151 
152 
153 //DoRead(rTr)
154 void AttributeFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
155  (void) rLabel; (void) pContext;
156  FD_DC("AttributeFlag(" << this << ")::DoRead(tr)");
157  Token token;
158  rTr.Peek(token);
159  // faudes format
160  if(token.IsInteger16()) {
161  rTr.Get(token);
162  mFlags=token.IntegerValue();
163  return;
164  }
165  // XML format
166  if(token.IsBegin())
167  if(token.StringValue()=="Flags") {
168  rTr.ReadBegin("Flags",token);
169  mFlags=token.AttributeIntegerValue("value");
170  rTr.ReadEnd("Flags");
171  return;
172  }
173  // default
175 }
176 
177 
178 } // namespace
Classes AttributeVoid and AttributeFlags
#define FD_DC(message)
Debug: optional report on container operations.
#define FD_WARN(message)
Debug: always report warnings.
#define FAUDES_OBJCOUNT_DEC(type)
#define FAUDES_OBJCOUNT_INC(type)
Debug: count objects, report on exit.
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Definition: cfl_types.h:946
Boolean flags Attribute.
bool DoEqual(const AttributeFlags &rOther) const
Test equality of configuration data.
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write to TokenWriter, see Type for public wrappers.
static const fType mDefFlags
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write to TokenWriter, see Type for public wrappers.
virtual bool IsDefault(void) const
Test for default value.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see Type for public wrappers.
fType mFlags
Flags (public access for convenience)
Minimal Attribute.
AttributeVoid(void)
Constructor.
virtual ~AttributeVoid(void)
Destructor.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Actual read method to read attribute from tokenreader.
static void Skip(TokenReader &rTr)
Skip attribute tokens.
void DoAssign(const AttributeVoid &rSrcAttr)
Assign attribute members.
virtual void DoDWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Actual write method to write the attribute to a TokenWriter.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Actual write method to write the attribute to a TokenWriter.
A TokenReader reads sequential tokens from a file or string.
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
void ReadBegin(const std::string &rLabel)
Open a section by specified label.
bool Get(Token &token)
Get next token.
bool Peek(Token &token)
Peek next token.
A TokenWriter writes sequential tokens to a file, a string or stdout.
void WriteComment(const std::string &rComment)
Write comment in faudes format.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
bool IsInteger16(void) const
Test token Type.
Definition: cfl_token.cpp:223
void SetInteger16(const Int number)
Initialize as Integer16 token.
Definition: cfl_token.cpp:128
const std::string & StringValue(void) const
Get string value of a name token.
Definition: cfl_token.cpp:177
Int AttributeIntegerValue(const std::string &name)
Access attribute value.
Definition: cfl_token.cpp:396
@ Integer
1234 (non-negative integer)
Definition: cfl_token.h:87
@ End
<\label> (end of section)
Definition: cfl_token.h:84
@ Begin
<label> (begin of section)
Definition: cfl_token.h:83
@ String
any string, space separated or quoted, must start with a letter
Definition: cfl_token.h:85
Int IntegerValue(void) const
Get integer value of a numeric token.
Definition: cfl_token.cpp:166
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:258
void SetEmpty(const std::string &rName)
Initialize as empty-tag token.
Definition: cfl_token.cpp:105
void InsAttributeInteger16(const std::string &name, Int value)
Insert named attribute with integer value.
Definition: cfl_token.cpp:327
TokenType Type(void) const
Get token Type.
Definition: cfl_token.cpp:198
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
libFAUDES resides within the namespace faudes.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen