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

libFAUDES 2.28a --- 2016.09.13 --- c++ api documentaion by doxygen