File: Arr_with_history_2_reader.h

package info (click to toggle)
cgal 3.6.1-2
  • links: PTS
  • area: non-free
  • in suites: squeeze
  • size: 62,184 kB
  • ctags: 95,782
  • sloc: cpp: 453,758; ansic: 96,821; sh: 226; makefile: 120; xml: 2
file content (133 lines) | stat: -rw-r--r-- 3,878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) 2005-2007  Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_2_reader.h $
// $Id: Arr_with_history_2_reader.h 40195 2007-09-05 09:51:34Z ophirset $
// 
//
// Author(s)     : Ron Wein           <wein@post.tau.ac.il>
#ifndef CGAL_ARR_WITH_HISTORY_2_READER_H
#define CGAL_ARR_WITH_HISTORY_2_READER_H

/*! \file
 * The header file for the Arr_with_history_2_reader<Arrangement> class.
 */

#include <CGAL/IO/Arrangement_2_reader.h>
#include <CGAL/Arrangement_2/Arr_with_history_accessor.h>

CGAL_BEGIN_NAMESPACE

/*! \class
 * An auxiliary class for reading an arrangement with history from an
 * input stream.
 */
template <class ArrWithHistory_>
class Arr_with_history_2_reader : private Arrangement_2_reader<ArrWithHistory_>
{
public:

  typedef ArrWithHistory_                                 Arr_with_history_2;
  typedef Arr_with_history_2_reader<Arr_with_history_2>   Self;

protected:
 
  typedef Arrangement_2_reader<Arr_with_history_2>        Base;
  typedef typename Arr_with_history_2::Size               Size;
  typedef typename Arr_with_history_2::Curve_handle       Curve_handle;
  typedef typename Arr_with_history_2::Halfedge_handle    Halfedge_handle;

  typedef Arr_with_history_accessor<Arr_with_history_2>   Arr_with_hist_access;
  typedef typename Arr_with_history_2::Curve_2            Curve_2;

protected:

  // Data members:
  Curve_2               m_in_curve;
  Arr_with_hist_access  m_arr_with_hist_access;

private:

  // Copy constructor and assignment operator - not supported.
  Arr_with_history_2_reader (const Self& );
  Self& operator= (const Self& );

public:

  /*! Constructor. */
  Arr_with_history_2_reader (Arr_with_history_2& arr) :
    Base (arr),
    m_arr_with_hist_access (arr)
  {}

  /*! Read the arrangement. */
  template <class Formatter>
  void operator()(Formatter& formatter)
  {
    // Read the arrangement (without history).
    Base::operator() (formatter);
    
    // Read the inducing curves.
    formatter.read_curves_begin();

    const Size  number_of_curves = formatter.read_size("number_of_curves");
    Size        k;

    for (k = 0; k < number_of_curves; k++)
      _read_curve (formatter);

    formatter.read_curves_end();
    return;
  }

protected:

  /*! Read a curve with its induced edges. */
  template <class Formatter>
  void _read_curve (Formatter& formatter)
  {
    formatter.read_curve_begin();

    // Read the curve.
    formatter.read_curve (m_in_curve);

    // Insert the curve to the list of inducing curves of the arrangement.
    Curve_handle     new_cv = m_arr_with_hist_access.new_curve (m_in_curve);

    // Read the induced edges.
    formatter.read_induced_edges_begin();

    const Size       number_of_edges = formatter.read_size("induced_edges");
    std::size_t      curr_idx;
    Halfedge_handle  curr_he;
    Size             k;

    for (k = 0; k < number_of_edges; k++)
    {
      curr_idx = formatter.read_halfedge_index();
      curr_he = Halfedge_handle (this->m_halfedges[curr_idx]);

      // Connect the curve and the edge it induces.
      m_arr_with_hist_access.connect_curve_edge (new_cv, curr_he);
    }
    formatter.read_induced_edges_end();

    formatter.read_curve_end();
    return;
  }
   
};

CGAL_END_NAMESPACE

#endif