-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTRING.cpp
More file actions
81 lines (68 loc) · 1.92 KB
/
STRING.cpp
File metadata and controls
81 lines (68 loc) · 1.92 KB
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
#include "STRING.h"
VAR* STRING::clone(){ // cloner to copy variable content into other
VAR* temp =new STRING(name,val); // creating new variable
return temp;
}
STRING::STRING(string nm, string data){ // constructor
if(data.length()<=255)val=data;
name=nm;
type="STRING";
}
void STRING::SET_STR_CHAR(int indx,char data){ // getting a char from string
pthread_mutex_lock(&mutex);
if(indx<val.length())val[indx]=data;
pthread_mutex_unlock(&mutex);
pthread_cond_signal(&lockCondition);
}
STRING::operator string() const{return val;}
//void STRING::SET_STR_CHAR(int indx,STRING other){
// name[indx]=other.get_val_of(indx);
//}
//virtual auto getValue()->string{return get_val_str();}
string STRING::get_val_str(){ // getting the value of string
pthread_mutex_lock(&mutex);
while (lock == 1) {
pthread_cond_wait(&lockCondition, &mutex);
}
lock = 1;
string returnVal = val;
pthread_mutex_unlock(&mutex);
lock = 0;
pthread_cond_signal(&lockCondition);
return returnVal;
}
void STRING::set_val(string data){ // setting values for string
pthread_mutex_lock(&mutex);
while (lock == 1) {
pthread_cond_wait(&lockCondition, &mutex);
}
lock = 1;
val=data;
pthread_mutex_unlock(&mutex);
lock = 0;
pthread_cond_signal(&lockCondition);
}
char STRING::get_val_of(int indx){ // getting value of string
pthread_mutex_lock(&mutex);
while (lock == 1) {
pthread_cond_wait(&lockCondition, &mutex);
}
lock = 1;
char myReturn = val[indx];
pthread_mutex_unlock(&mutex);
lock = 0;
pthread_cond_signal(&lockCondition);
return myReturn;
}
void STRING::ASSGN(string data){ // assigning string value into other
pthread_mutex_lock(&mutex);
while (lock == 1) {
pthread_cond_wait(&lockCondition, &mutex);
}
lock = 1;
val = data;
pthread_mutex_unlock(&mutex);
lock = 0;
pthread_cond_signal(&lockCondition);
}
STRING::~STRING(){}