-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.h
96 lines (76 loc) · 2.55 KB
/
utils.h
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
#define charKeyMatrix std::map<char, std::vector<int>*>
#define normalizedString std::vector<std::string>
#ifndef UTILS_H
#define UTILS_H
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <vector>
#include <stdio.h>
#include <bitset>
#include <cmath>
#include "coveredBool.h"
/// <summary>
/// utilities class holding independent functions
/// </summary>
class utils
{
public:
///checkers///
/// <summary>
/// contains all checkers for a boolean SoP expression
/// </summary>
/// <param name="Expression"></param>
/// <returns></returns>
static int verify_expression_syntax(std::string* Expression);
/// <summary>
/// checks if string characters are within correct ASCII codes
/// </summary>
/// <param name="Expression">Expression given from user</param>
/// <returns>boolean</returns>
static bool check_characters_within_range(std::string* Expression);
/// <summary>
/// checks open and empty parentheses
/// </summary>
/// <param name="Expression">Expression given from user</param>
/// <returns>boolean</returns>
static bool check_parentheses(std::string* Expression);
///misc utilities///
/// <summary>
/// converts from decimal to binary with zero padding for ease of printing
/// </summary>
/// <param name="Dec">decimal value</param>
/// <param name="Bits">number of bits for padding</param>
/// <returns>pointer to resulting string</returns>
static std::string* decimal_to_binary(int Dec, int Bits);
/// <summary>
/// converts a minterm to its binary value (used to store expression as binary values for to operate upon)
/// </summary>
/// <param name="Minterm">the Minterm</param>
/// <returns>binary value</returns>
static int minterm_to_binary(std::string Minterm);
/// <summary>
/// counts number of set bits in a given value
/// </summary>
/// <param name="x">value</param>
/// <returns>integer</returns>
static int count_bits(int x);
/// <summary>
/// loops over given string to extract unique literals given
/// </summary>
/// <param name="Expression">string given by user</param>
/// <returns>set of unique literals</returns>
static std::set<char>* unique_literals(std::string* Expression);
/// <summary>
/// parses given string into a vector of strings that separates expression and operations
/// </summary>
/// <param name="Expression">string given by user</param>
/// <returns>vector of string (normalized string)</returns>
static normalizedString* parse_string(std::string* Expression);
static int get_bit_position(int);
};
#endif