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

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen