summaryrefslogtreecommitdiffstats
path: root/src/uscxml/debug/Complexity.h
blob: 76330fd139fef401730174557a40da1e5ece995f (plain)
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
/**
 *  @file
 *  @author     2012-2015 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de)
 *  @copyright  Simplified BSD
 *
 *  @cond
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the FreeBSD license as published by the FreeBSD
 *  project.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 *  You should have received a copy of the FreeBSD license along with this
 *  program. If not, see <http://www.opensource.org/licenses/bsd-license>.
 *  @endcond
 */

#ifndef COMPLEXITY_H_F972C065
#define COMPLEXITY_H_F972C065

#include "uscxml/Common.h"              // for USCXML_API
#include "uscxml/Interpreter.h"

namespace uscxml {

class USCXML_API Complexity {
public:
	
	enum Variant {
		IGNORE_NOTHING      = 0x0000,
		IGNORE_HISTORY      = 0x0001,
		IGNORE_NESTED_DATA  = 0x0002,
		IGNORE_UNREACHABLE  = 0x0004,
	};
	
	Complexity() : value(0), nestedData(0) {}
	Complexity(uint64_t value) : value(value), nestedData(0) {}
	
	Complexity& operator+=(const Complexity& rhs) {
		value += rhs.value;
		nestedData += rhs.nestedData;
		history.insert(history.end(), rhs.history.begin(), rhs.history.end());
		return *this;
	}
	
	Complexity& operator*=(const Complexity& rhs) {
		value *= rhs.value;
		nestedData += rhs.nestedData;
		history.insert(history.end(), rhs.history.begin(), rhs.history.end());
		return *this;
	}
	
    static uint64_t stateMachineComplexity(const Interpreter& interpreter, Complexity::Variant variant = IGNORE_NOTHING) {
        return stateMachineComplexity(interpreter.getImpl().get());
    }
    static uint64_t stateMachineComplexity(InterpreterImpl* interpreter, Complexity::Variant variant = IGNORE_NOTHING);

	static std::list<std::set<Arabica::DOM::Element<std::string> > > getAllConfigurations(const Arabica::DOM::Element<std::string>& root);
	static std::map<size_t, size_t> getTransitionHistogramm(const Arabica::DOM::Element<std::string>& root);

protected:
	static Complexity calculateStateMachineComplexity(const Arabica::DOM::Element<std::string>& root, const Arabica::XPath::NodeSet<std::string>& reachable);

	uint64_t value;
	uint64_t nestedData;
	std::list<uint64_t> history;
};

inline Complexity::Variant operator | ( Complexity::Variant lhs, Complexity::Variant rhs ) {
    // Cast to int first otherwise we'll just end up recursing
    return static_cast< Complexity::Variant >( static_cast< int >( lhs ) | static_cast< int >( rhs ) );
}

}

#endif /* end of include guard: COMPLEXITY_H_F972C065 */