Skip to content

Commit 094e16f

Browse files
author
ie
committed
Types: date. Filters: date, email, telephone
0 parents  commit 094e16f

17 files changed

+630
-0
lines changed

.gitignore

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# This file is used to ignore files which are generated
2+
# ----------------------------------------------------------------------------
3+
4+
*~
5+
*.autosave
6+
*.a
7+
*.core
8+
*.moc
9+
*.o
10+
*.obj
11+
*.orig
12+
*.rej
13+
*.so
14+
*.so.*
15+
*_pch.h.cpp
16+
*_resource.rc
17+
*.qm
18+
.#*
19+
*.*#
20+
core
21+
!core/
22+
tags
23+
.DS_Store
24+
.directory
25+
*.debug
26+
Makefile*
27+
*.prl
28+
*.app
29+
moc_*.cpp
30+
ui_*.h
31+
qrc_*.cpp
32+
Thumbs.db
33+
*.res
34+
*.rc
35+
/.qmake.cache
36+
/.qmake.stash
37+
38+
# qtcreator generated files
39+
*.pro.user*
40+
41+
# xemacs temporary files
42+
*.flc
43+
44+
# Vim temporary files
45+
.*.swp
46+
47+
# Visual Studio generated files
48+
*.ib_pdb_index
49+
*.idb
50+
*.ilk
51+
*.pdb
52+
*.sln
53+
*.suo
54+
*.vcproj
55+
*vcproj.*.*.user
56+
*.ncb
57+
*.sdf
58+
*.opensdf
59+
*.vcxproj
60+
*vcxproj.*
61+
62+
# MinGW generated files
63+
*.Debug
64+
*.Release
65+
66+
# Python byte code
67+
*.pyc
68+
69+
# Binaries
70+
# --------
71+
*.dll
72+
*.exe
73+

DBsource/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
add_library(dblib "")
2+
3+
target_sources(dblib
4+
PRIVATE
5+
#${CMAKE_CURRENT_LIST_DIR}/DBAttribute.cpp
6+
#${CMAKE_CURRENT_LIST_DIR}/DBDatabase.cpp
7+
${CMAKE_CURRENT_LIST_DIR}/DBIFilters.cpp
8+
#${CMAKE_CURRENT_LIST_DIR}/DBTable.cpp
9+
${CMAKE_CURRENT_LIST_DIR}/DBTypes.cpp
10+
PUBLIC
11+
${CMAKE_CURRENT_LIST_DIR}/DBAttribute.hpp
12+
${CMAKE_CURRENT_LIST_DIR}/DBDatabase.hpp
13+
${CMAKE_CURRENT_LIST_DIR}/DBIFilters.hpp
14+
${CMAKE_CURRENT_LIST_DIR}/DBTable.hpp
15+
${CMAKE_CURRENT_LIST_DIR}/DBTypes.hpp
16+
)
17+
18+
target_include_directories(dblib
19+
PUBLIC
20+
${CMAKE_CURRENT_LIST_DIR}
21+
)
22+

DBsource/DBAttribute.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef _DBATTRIBUTE_
2+
#define _DBATTRIBUTE_
3+
4+
#include <string>
5+
6+
template<class T>
7+
class DBAttribute {
8+
std::string _name;
9+
10+
protected:
11+
//T _value;
12+
13+
public:
14+
DBAttribute(std::string name);
15+
~DBAttribute();
16+
17+
std::string GetName();
18+
void SetName(std::string name);
19+
};
20+
21+
#endif

DBsource/DBDatabase.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef _DBDATABASE_
2+
#define _DBDATABASE_
3+
4+
#include <set>
5+
#include <map>
6+
#include <string>
7+
8+
class Database {
9+
std::string _name;
10+
//std::map<std::string> _tables;
11+
12+
};
13+
14+
#endif

DBsource/DBIFilters.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#include "DBIFilters.hpp"
2+
3+
#include <cmath>
4+
#include <utility>
5+
6+
#include "../Features/Features.hpp"
7+
8+
//
9+
// IFilterName
10+
//
11+
IFilterName::IFilterName() {}
12+
IFilterName::~IFilterName() {}
13+
14+
bool IFilterName::Filter(QString name) {
15+
if(name.size() > NAME_MAX_SIZE || name.size() < NAME_MIN_SIZE)
16+
return false;
17+
18+
return true;
19+
}
20+
21+
//
22+
// IFilterTelephone
23+
//
24+
DBIFilterTelephone::DBIFilterTelephone() {}
25+
DBIFilterTelephone::~DBIFilterTelephone() {}
26+
27+
bool DBIFilterTelephone::Filter(QString telephone) {
28+
if(telephone.size() > TELEPHONE_MAX_SIZE || telephone.size() < TELEPHONE_MIN_SIZE)
29+
return false;
30+
31+
for(auto c: telephone)
32+
if(!c.isDigit())
33+
return false;
34+
35+
return true;
36+
}
37+
38+
//
39+
// IFilterTelephone
40+
//
41+
DBIFilterEmail::DBIFilterEmail() {}
42+
DBIFilterEmail::~DBIFilterEmail() {}
43+
44+
bool DBIFilterEmail::Filter(QString _email) {
45+
if(_email.size() > EMAIL_MAX_SIZE || _email.size() < EMAIL_MIN_SIZE)
46+
return false;
47+
48+
u_int16_t name_counter = 0;
49+
u_int16_t domain_counter = 0;
50+
bool at_sign_contain = false;
51+
for(int i = 0; i < _email.size(); i++) {
52+
// checks at-sign and return false if its first
53+
if(_email[i] == '@') {
54+
at_sign_contain = true;
55+
if(name_counter > EMAIL_USERNAME_MAX_SIZE || name_counter < EMAIL_USERNAME_MIN_SIZE)
56+
return false;
57+
}
58+
59+
// inc name if we didnt meet '@' otherwise inc domain
60+
if(!at_sign_contain)
61+
name_counter++;
62+
else
63+
domain_counter++;
64+
65+
// domain chars check
66+
if(domain_counter > EMAIL_DOMAIN_MAX_SIZE || domain_counter < EMAIL_DOMAIN_MIN_SIZE)
67+
return false;
68+
}
69+
70+
return true;
71+
}
72+
73+
//
74+
// IFilterDate
75+
//
76+
DBIFilterDate::DBIFilterDate() { }
77+
DBIFilterDate::~DBIFilterDate() {}
78+
79+
bool DBIFilterDate::Filter(QString date) {
80+
if(date.size() != DATE_SIZE)
81+
return false;
82+
83+
if(date[DATE_1_SPLIT] != DATE_SPLIT_CHAR || date[DATE_2_SPLIT] != DATE_SPLIT_CHAR)
84+
return false;
85+
86+
int i = 0;
87+
std::pair<int, int> m[3] = {
88+
{DATE_MIN_YEAR, DATE_MAX_YEAR},
89+
{DATE_MIN_MONTH, DATE_MAX_MONTH},
90+
{DATE_MIN_DAY, DATE_MAX_DAY} };
91+
int num = 0;
92+
93+
for(auto elem: date.split(QChar(DATE_SPLIT_CHAR))) {
94+
if((num = Features::StringToNumber(elem)) == 0) {
95+
return false;
96+
}
97+
if(num < m[i].first || num > m[i].second) {
98+
return false;
99+
}
100+
101+
num = 0;
102+
i++;
103+
}
104+
105+
return true;
106+
}

DBsource/DBIFilters.hpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#ifndef _DBIFILTERS_
2+
#define _DBIFILTERS_
3+
4+
#include <QString>
5+
#include <QStringList>
6+
7+
#define TELEPHONE_FORMAT "89997771111"
8+
#define TELEPHONE_MAX_SIZE 15
9+
#define TELEPHONE_MIN_SIZE 8
10+
11+
#define EMAIL_FORMAT "name@domain"
12+
#define EMAIL_MAX_SIZE 320
13+
#define EMAIL_MIN_SIZE 3
14+
#define EMAIL_USERNAME_MAX_SIZE 64
15+
#define EMAIL_USERNAME_MIN_SIZE 1
16+
#define EMAIL_DOMAIN_MAX_SIZE 255
17+
#define EMAIL_DOMAIN_MIN_SIZE 1
18+
19+
#define DATE_FORMAT "YYYY-MM-DD"
20+
#define DATE_SIZE 10
21+
#define DATE_1_SPLIT 4
22+
#define DATE_2_SPLIT 7
23+
#define DATE_SPLIT_CHAR '-'
24+
#define DATE_MAX_YEAR 2030
25+
#define DATE_MIN_YEAR 1880
26+
#define DATE_MAX_MONTH 12
27+
#define DATE_MIN_MONTH 1
28+
#define DATE_MAX_DAY 31
29+
#define DATE_MIN_DAY 1
30+
31+
// Users defines
32+
#define NAME_MAX_SIZE 150
33+
#define NAME_MIN_SIZE 3
34+
35+
36+
//
37+
// DBs filters
38+
//
39+
template<class T>
40+
class DBIFilter {
41+
protected:
42+
virtual bool Filter(T) = 0;
43+
};
44+
45+
class DBIFilterTelephone : DBIFilter<QString> {
46+
protected:
47+
48+
bool Filter(QString telephone) override;
49+
50+
public:
51+
DBIFilterTelephone();
52+
~DBIFilterTelephone();
53+
};
54+
55+
class DBIFilterEmail : DBIFilter<QString> {
56+
protected:
57+
58+
bool Filter(QString email) override;
59+
60+
public:
61+
DBIFilterEmail();
62+
~DBIFilterEmail();
63+
};
64+
65+
class DBIFilterDate : DBIFilter<QString> {
66+
protected:
67+
bool Filter(QString date) override;
68+
69+
public:
70+
DBIFilterDate();
71+
~DBIFilterDate();
72+
};
73+
74+
//
75+
// Users filters
76+
//
77+
class IFilterName : DBIFilter<QString> {
78+
protected:
79+
bool Filter(QString name) override;
80+
81+
public:
82+
IFilterName();
83+
~IFilterName();
84+
};
85+
#endif

DBsource/DBTable.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef _DBTABLE_
2+
#define _DBTABLE_
3+
4+
#include <string>
5+
#include <map>
6+
7+
class Table {
8+
9+
std::string _name;
10+
//std::map<std::string, >
11+
12+
};
13+
14+
#endif

DBsource/DBTypes.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "DBTypes.hpp"
2+
3+
//
4+
// DBType
5+
//
6+
template<class T>
7+
DBType<T>::DBType() {}
8+
template<class T>
9+
DBType<T>::~DBType() {}
10+
template<class T>
11+
DBType<T>::DBType(T value) : _value(value) {}
12+
13+
template<class T>
14+
T DBType<T>::GetValue() { return _value; }
15+
16+
template<class T>
17+
bool DBType<T>::operator==(const DBType<T>& right) { return _value == right._value; }
18+
template<class T>
19+
bool DBType<T>::operator!=(const DBType<T>& right) { return _value != right._value; }
20+
21+
//
22+
// DBDate
23+
//
24+
DBDate::DBDate() { _value = ""; }
25+
DBDate::DBDate(const char *value) : DBType(value) { if(!Filter(value)) _value = ""; }
26+
DBDate::DBDate(const QString value) : DBType(value) { if(!Filter(value)) _value = ""; }
27+
DBDate::DBDate(const DBDate& date) { operator=(date); }
28+
DBDate::~DBDate() {}
29+
30+
DBDate& DBDate::operator=(const QString date) {
31+
if (Filter(date)) {
32+
_value = date;
33+
} else {
34+
_value = "";
35+
}
36+
37+
return *this;
38+
}
39+
DBDate& DBDate::operator=(const DBDate& date) {
40+
if(*this != date)
41+
_value = date._value;
42+
return *this;
43+
}

0 commit comments

Comments
 (0)