Merge pull request #83 from eadrkir/master
[deliverable/titan.core.git] / core / TCov.hh
1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Kovacs, Ferenc
11 * Raduly, Csaba
12 *
13 ******************************************************************************/
14 #ifndef TCOV_HH
15 #define TCOV_HH
16
17 #include <sys/types.h> // for pid_t
18 #include "memory.h"
19 #include "Types.h" // for boolean
20
21 #include "Vector.hh"
22
23 class FunctionData
24 {
25 public:
26 explicit FunctionData(const char *name = NULL, int pos = 0, int count = 0)
27 : m_pos(pos), m_count(count) { if (name != NULL) m_name = mcopystr(name); }
28 ~FunctionData() { Free(m_name); }
29 inline const char *get_name() const { return m_name; }
30 inline int get_pos() const { return m_pos; }
31 inline int get_count() const { return m_count; }
32 inline void reset() { m_count = 0; }
33 FunctionData& operator++() { ++m_count; return *this; }
34 private:
35 /// Copy constructor disabled
36 FunctionData(const FunctionData&);
37 /// %Assignment disabled
38 FunctionData& operator=(const FunctionData&);
39 char *m_name;
40 int m_pos; // For later improvement.
41 int m_count;
42 };
43
44 class LineData
45 {
46 public:
47 explicit LineData(int no = 0, int count = 0): m_no(no), m_count(count) { }
48 inline int get_no() const { return m_no; }
49 inline int get_count() const { return m_count; }
50 inline void reset() { m_count = 0; }
51 LineData& operator++() { ++m_count; return *this; }
52 private:
53 /// Copy constructor disabled
54 LineData(const LineData&);
55 /// %Assignment disabled
56 LineData& operator=(const LineData&);
57 int m_no;
58 int m_count;
59 };
60
61 class FileData
62 {
63 public:
64 explicit FileData(const char *file_name);
65 ~FileData();
66 inline const char *get_file_name() const { return m_file_name; }
67 inline const Vector<FunctionData *>& get_function_data() const { return m_function_data; }
68 inline const Vector<LineData *>& get_line_data() const { return m_line_data; }
69 void inc_function(const char *function_name, int line_no);
70 void inc_line(int line_no);
71 void init_function(const char *function_name);
72 void init_line(int line_no);
73 size_t has_line_no(int line_no);
74 size_t has_function_name(const char *function_name);
75 void reset();
76 private:
77 /// Copy constructor disabled
78 FileData(const FileData&);
79 /// %Assignment disabled
80 FileData& operator=(const FileData&);
81 char *m_file_name;
82 Vector<FunctionData *> m_function_data;
83 Vector<LineData *> m_line_data;
84 };
85
86 // We all belong to the _same_ component.
87 class TCov
88 {
89 public:
90 static void hit(const char *file_name, int line_no, const char *function_name = NULL);
91 static void init_file_lines(const char *file_name, const int line_nos[], size_t line_nos_len);
92 static void init_file_functions(const char *file_name, const char *function_names[], size_t function_names_len);
93 static expstring_t comp(boolean withname = FALSE);
94 static void close_file();
95 private:
96 /// Copy constructor disabled
97 TCov(const TCov& tcov);
98 /// %Assignment disabled
99 TCov& operator=(const TCov& tcov);
100 static size_t has_file_name(const char *file_name);
101 static void pid_check();
102
103 static Vector<FileData *> m_file_data;
104 static pid_t mypid;
105 static expstring_t mycomp;
106 static expstring_t mycomp_name;
107 static int ver_major;
108 static int ver_minor;
109 };
110
111 #endif // TCOV_HH
This page took 0.033524 seconds and 5 git commands to generate.