File: History.h

package info (click to toggle)
madlib 1.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,196 kB
  • sloc: cpp: 39,851; sh: 10,041; makefile: 473
file content (91 lines) | stat: -rw-r--r-- 2,315 bytes parent folder | download | duplicates (6)
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
// -*- C++ -*-
// -------------------------------------------------------------------
// MAdLib - Copyright (C) 2008-2009 Universite catholique de Louvain
//
// See the Copyright.txt and License.txt files for license information. 
// You should have received a copy of these files along with MAdLib. 
// If not, see <http://www.madlib.be/license/>
//
// Please report all bugs and problems to <contrib@madlib.be>
//
// Authors: Gaetan Compere, Jean-Francois Remacle
// -------------------------------------------------------------------

#ifndef _H_HISTORY
#define _H_HISTORY

#include "MAdSingleton.h"

#include <vector>
#include <ostream>
#include <string>

namespace MAd {

  // -------------------------------------------------------------------
  enum actionType {
    OP_CHECKCONSTRAINTS = 0,
    OP_CHECKGEOMETRY    = 1,
    OP_CHECKSHAPES      = 2,
    OPERATOR_APPLY      = 3,
    OPERATOR_UNAPPLY    = 4,
    UNKNOWN_ACTION      = 5
  };

  struct action {
    int opType;
    actionType actType;
    std::vector<int> intParams;

    bool operator!=(const action& other) {
      if ( opType  != other.opType  ) return true;
      if ( actType != other.actType ) return true;
      if ( intParams.size() != other.intParams.size() ) return true;
      for (unsigned int i=0; i<intParams.size(); i++) {
        if ( intParams[i] != other.intParams[i] ) return true;
      }
      return false;
    }
  };

  // -------------------------------------------------------------------
  class History {

  public:
  
    History()  {};
    ~History() {};
  
    void initialize();
    void finalize();
  
    void openJournal()  { open = true;  };
    void closeJournal() { open = false; };

    void add(int, actionType,...);
    void add(action);

    bool compare();

    void flushJournal(std::ostream& out) const;
    void flushJournal(std::string name) const;

    void loadJournal(std::string name);
  
  private:
  
    bool open; // indicates if the journal is in use

    std::vector<action> journal;      // list of actions

    std::vector<action> refJournal;  // journal to compare with
    int refCount;                    // position of the next action to compare
  };

  // -------------------------------------------------------------------

  typedef MAdSingleton<History> HistorySgl;

}

#endif