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 // destructor
44  FAUDES_OBJCOUNT_DEC("Attribute");
45 }
46 
47 //DoWrite(rTr,rLabel,pContext)
48 void AttributeVoid::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
49  (void) rTw; (void) rLabel; (void) pContext;
50  FD_DC("AttributeVoid::DoWrite()");
51 }
52 
53 //DoWrite(rTr,rLabel,pContext)
54 void AttributeVoid::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
55  (void) rTw; (void) rLabel; (void) pContext;
56  FD_WARN("AttributeVoid::DoWrite()");
57  rTw.WriteComment(std::string("Attr Type ") + typeid(*this).name());
58  DoWrite(rTw,rLabel,pContext);
59 }
60 
61 //DoRead(rTr,rLabel,pContext)
62 void AttributeVoid::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
63  (void) rLabel; (void) pContext; (void) rTr;
64  FD_DC("AttributeVoid::DoRead()");
65 }
66 
67 //Skip(rTr)
69  FD_DC("AttributeVoid::Skip()");
70  Token token;
71  while(rTr.Peek(token)) {
72  // break on index or name, since this is the next element
73  if((token.Type()==Token::String) || (token.Type()==Token::Integer)) {
74  break;
75  }
76  // break on end, since this is the end of the set
77  if(token.Type()==Token::End) {
78  break;
79  }
80  // break on Consecutive section, since this belongs to the set
81  if((token.Type()==Token::Begin) && (token.StringValue() == "Consecutive")) {
82  break;
83  }
84  // skip any attribute section from other file format
85  if(token.Type()==Token::Begin){
86  rTr.ReadBegin(token.StringValue());
87  rTr.ReadEnd(token.StringValue());
88  continue;
89  }
90  // skip any other token from other file format
91  rTr.Get(token);
92  }
93 }
94 
95 
96 
97 /***********************************************************************************
98  *
99  * implementation of AttributeFlags
100  *
101  */
102 
103 // faudes type
105 
106 // Assign my members
107 void AttributeFlags::DoAssign(const AttributeFlags& rSrcAttr) {
108  // call virtual clear: TODO: dont clear in virtual function
109  Clear();
110  // assign my members
111  mFlags=rSrcAttr.mFlags;
112 }
113 
114 // Test my members for equality
115 bool AttributeFlags::DoEqual(const AttributeFlags& rOther) const {
116  return ( mFlags==rOther.mFlags );
117 }
118 
119 //DoWrite(rTw)
120 // Note: you should write attributes in a section, so that
121 // the AttributeVoid read method can detect and skip them.
122 // Here, we make an execption of the rule ...
123 void AttributeFlags::DoWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
124  (void) rLabel; (void) pContext;
126  FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
127  Token token;
128  token.SetInteger16(mFlags);
129  rTw << token;
130  }
131 }
132 
133 
134 //DoXWrite(rTw)
135 void AttributeFlags::DoXWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
136  (void) rLabel; (void) pContext;
138  FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
139  Token token;
140  token.SetEmpty("Flags");
141  token.InsAttributeInteger16("value",mFlags);
142  rTw << token;
143  }
144 }
145 
146 
147 //DoRead(rTr)
148 void AttributeFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
149  (void) rLabel; (void) pContext;
150  FD_DC("AttributeFlag(" << this << ")::DoRead(tr)");
151  Token token;
152  rTr.Peek(token);
153  // faudes format
154  if(token.IsInteger16()) {
155  rTr.Get(token);
156  mFlags=token.IntegerValue();
157  return;
158  }
159  // XML format
160  if(token.IsBegin())
161  if(token.StringValue()=="Flags") {
162  rTr.ReadBegin("Flags",token);
163  mFlags=token.AttributeIntegerValue("value");
164  rTr.ReadEnd("Flags");
165  return;
166  }
167  // default
169 }
170 
171 
172 } // 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.
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.
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.31h --- 2024.01.29 --- c++ api documentaion by doxygen