YAPOG  0.0.1
Yet Another Pokemon Online Game
RectReader.hxx
Go to the documentation of this file.
1 #ifndef YAPOG_RECTREADER_HXX
2 # define YAPOG_RECTREADER_HXX
3 
7 
8 namespace yap
9 {
10  template <typename T>
11  const String RectReader<T>::DEFAULT_XML_ROOT_NODE_NAME = "Rect";
12 
13  template <typename T>
14  inline RectReader<T>::RectReader (sf::Rect<T>& rect)
15  : rect_ (rect)
16  , xmlRootNodeName_ (DEFAULT_XML_ROOT_NODE_NAME)
17  {
18  }
19 
20  template <typename T>
22  sf::Rect<T>& rect,
23  const String& xmlRootNodeName)
24  : rect_ (rect)
25  , xmlRootNodeName_ (xmlRootNodeName)
26  {
27  }
28 
29  template <typename T>
31  {
32  }
33 
34  template <typename T>
35  inline void RectReader<T>::Visit (XmlReader& visitable)
36  {
37  String data = visitable.ReadString (xmlRootNodeName_);
39  StringHelper::Split (data, ",", result);
40 
41  rect_.left = StringHelper::Parse<T> (result[0]);
42  rect_.top = StringHelper::Parse<T> (result[1]);
43  rect_.width = StringHelper::Parse<T> (result[2]);
44  rect_.height = StringHelper::Parse<T> (result[3]);
45  }
46 
47  template <typename T>
48  inline void RectReader<T>::Visit (IPacket& visitable)
49  {
50  // Does nothing.
51  // Unable to Read<T> from IReader.
52  // Implemented in specializations.
53  }
54 
55  template <>
56  inline void RectReader<float>::Visit (IPacket& visitable)
57  {
58  rect_.left = visitable.ReadFloat ();
59  rect_.top = visitable.ReadFloat ();
60  rect_.width = visitable.ReadFloat ();
61  rect_.height = visitable.ReadFloat ();
62  }
63 } // namespace yap
64 
65 #endif // YAPOG_RECTREADER_HXX