Skip to content
seyyed hossein mousavi edited this page Dec 31, 2016 · 2 revisions

Table of Contents

1 SParam

1.1 UUIDParam

A universally unique identifier (UUID) is an identifier standard used in software construction. A UUID is simply a 128-bit value. The meaning of each bit is defined by any of several variants. The UUIDParam class defines UUID parameter and inherit from XSingleParam class. This class constructor get name in type of string and construct class with UUID generation. This class functions defined as:

  • To generate UUID parameter call reset() or regenerate() functions.
  • If you want to set or get value of UUID call set_value() and value() functions.
  • By assign value to object you can pass the string, XParam and UUIDParam types and modify UUID value.
You can read following example to start with UUIDParam class:
#include <iostream>

include <sparam.hpp>
include <xparam.hpp>


using namespace pparam;
using namespace std;

int main(){
	UUIDParam uuid1("uuid1");
	uuid1.reset();
	uuid1.regenerate();
	cout << uuid1.value() << endl;
	cout << uuid1.xml() << endl;
	UUIDParam uuid2("uuid2");
	uuid2.set_value("13f8a604-d4de-46f3-a053-691f311196db");
	cout << uuid2.value() << endl;
	cout << uuid2.xml() << endl;
}

The output of the program is:

02d1cfd9-1f38-426e-97c8-e1dc238c8c09
<uuid1>02d1cfd9-1f38-426e-97c8-e1dc238c8c09</uuid1>
13f8a604-d4de-46f3-a053-691f311196db
<uuid2>13f8a604-d4de-46f3-a053-691f311196db</uuid2>

1.2 CryptoParam

This class defines cryptography parameter and use hash function to encrypt value and inherit from XTextParam class. This class constructor gets parameter name in type of string and construct it. By call encrypt_md5() function the value would be converted to the 128-bit hash value. Also this class has two address operator overloaded by char and string type that returns XParam value. You can read following example to start with CryptoParam class:

#include <iostream>

include <sparam.hpp>
include <xparam.hpp>


using namespace pparam;
using namespace std;

int main(){
	CryptoParam crparam("crparam1");
	crparam.operator=("12345qwert");
	cout << crparam.xml() << endl;
	crparam.encrypt_md5();
	cout << crparam.xml() << endl;
	return 0;
}

The output of program is:

<crparam1>12345qwert</crparam1>
<crparam1>b1ef741bee14a29acbe5686f59b62569</crparam1>

1.3 BoolParam

This class has some kind of Boolean values like yes, no, disable, enable, on, off, up, down, set and unset. This class inherit from XEnumParam class

1.4 DateParam

If you want to define date you can use DateParam class. This class inherit from XSingleParam class. The constructor of this class get name of date in string type. This class has a set of function to interact with it:

  • To set date variables like year, month and day you can call set_year(short), set_month(short) and set_day(short) functions. if you want to set the current day call now() function.
  • If you set this class member, by call isValid() function find out that the user input date is true or no.
  • For converting date to string type in default format like yyyy/mm/dd call value() function, but if you want to change date format call formattedValue(string) function.
  • To get date variables like year, month and day you can call get_year(), get_month() and get_day() functions. These functions returns short type.
  • To reset class member like year, month and day call reset() function.
  • This class supports operators like(>=, <= , >, <, =, !=, ==, +, -). The assign operator support string, XParam and DateParam types. It means you can pass date format like "2016/02/12" as string type. the minus(-) operator return difference days between two dates.
You can read following example to start with DateParam class:
#include <iostream>

include <sparam.hpp>
include <xparam.hpp>


using namespace pparam;
using namespace std;

int main(){
	DateParam date1("user date");
	date1.set_year(2016);
	date1.set_month(06);
	date1.set_day(12);
	if(date1.isValid()){
		cout << date1.value() << endl;
		cout << "change date format" << endl;
		cout << date1.formattedValue("%04d-%02d-%02d") << endl;
	}

	DateParam date2("today");
	date2.now();
	if (date2.operator>(date1)) {
		cout << "days passed";
		cout << date2.operator-(date1) << endl;
	} else if (date2.operator<(date1)){
		cout << "days remaning";
		cout << date1.operator-(date2) << endl;
	} else if (date2.operator==(date1)) {
		cout << "Date is today" << endl;
	}

	DateParam date3(move(date2));
	cout << date3.xml(true, 8, true) << endl;
        date3.operator=(date2.operator+(date1));
	cout << "the added dates are:" << date3.value() << endl;
	cout << "days remaining to weekend:" << date3.get_weekday() << endl;

	return 0;
}

The output of program is:

2016/06/12
change date format
2016-06-12
days passed172
        <today>2016/12/01</today>

the added dates are:4033/06/13
days remaining to weekend:5

1.5 TimeParam

This class defines time parameters and operations using use time. Actually this class inherit from XSingleParam class. You can construct this class by passing time parameter name as string type. The functions of this class listed as bellow:

  • To set hour, minute and second of time you can call set_hour(short), set_minute(short), set_second(short) functions. If you want to set current time just call now() function.
  • To get hour, minute and second of time you can call get_hour(), get_minute(), get_second() functions.
  • To be sure that your time is valid or no call isValid() function.
  • To get time value in type of string call value() function and it returns in default format like hh:mm:ss. if you want to change this format call formattedValue(string) function.
  • To reset class member like hour, minute and second call reset() function.
  • This class supports operators like(>=, <= , >, <, =, !=, ==, +, -). The assign operator support string, XParam and DateParam types. It means you can pass time format like "12:25:14" as string type. In the minus(-) operator if this time is less than or equal to pass time, function just calculate the difference of them, otherwise, it calculate the difference of this time and midnight and difference of time and midnight and then sum these two differences.
You can read following example to start with TimeParam class:
#include <iostream>

include <sparam.hpp>
include <xparam.hpp>


using namespace pparam;
using namespace std;

int main(){
	TimeParam time1("time1");
	time1.set_hour(8);
	time1.set_minute(25);
	time1.set_second(12);
	if(time1.isValid()){
		cout << time1.value() << endl;
		cout << "change time format without seconds" << endl;
		cout << time1.formattedValue("%02d:%02d") << endl;
	}
	
	TimeParam time2("current time");
	TimeParam time3("temp time");
	unsigned char day;
	time2.now();
	cout << time2.value() << endl;
	if(time2.operator>(time1)){
		cout << "the current time is bigger than enter time" << endl;
		time3 = time2.add(time1, day);
		cout << "remaing time is " << time3.get_hour() << " hours " << time3.get_minute() << 
			" minute " << time3.get_second() << " second " << (int)day  << " days" << endl;
	} else if (time2.operator<(time1)){
		cout << "the current time is less than enter time" << endl;
		cout << "the diffrence between them is " << time2.operator-(time1) << " seconds" <<endl;
	} else if (time2.operator==(time1)){
	}

	TimeParam time4(move(time2));
	cout << time4.xml(true, 8, true);
	return 0;
}

the output of this program is:

08:25:12
change time format without seconds
08:25
10:26:29
the current time is bigger than enter time
remaing time is 18 hours 51 minute 41 second 0 days
        <current time>10:26:29</current>time>

1.6 DateTime

This class combines time and date and define their parameters and inherit from XSingleParam class. The constructor of this class accepts string type as parameter name and construct it. The function of this class are:

  • To set date parameters call set_date(DateParam), set_year(short), set_month(short) and set_day(short) functions and to set time parameters call set_time(TimeParam), set_hour(short), set_minut(short) and set_second(short) functions. To set current time and date call now() function.
  • To get date parameters call get_date(), get_year(), get_month() and get_day() functions and to set time parameters call get_time(), get_hour(), get_minut() and get_second() functions.
  • To be sure that enter date and time is valid or no call isValid() function.
  • To get time and date value in type of string call value() function and it returns in default format like yyyy/mm/dd hh:mm:ss. If you want to change this format call formattedValue(string) function.
  • To get data type call getDataType() function that returns database field type.
  • To reset class member like hour, minute and second call reset() function.
  • This class supports operators like(>, <, =). The assign operator support string, XParam and DateParam value types. It means you can pass day and time format like "2016/02/12 12:32:52" as string type.

1.7 IPParam

This class represent IP (Internet Protocol) address. Its only a base for IPv4Param and IPv6Param classes. Actually this class inherit from XSingleParam class. This class has two constructor that you can pass any value and it assign default names or pass parameter name as string type. the virtual functions of this class introduced as:

  • By call the getPart(int) function you can get parts of IP address.
  • If you call the getIPVersion() or getFamily() functions respectively returns IPType::Version and string types.
  • The key() function set value() as key for search.
  • The assign operator accepts string, char and XParam types and after assignment it returns XParam object.
  • The value(), reset(), getBroadcast() and getUnicast() functions should be Implement in classes that inherited from this class.
  • This class has two set() function that you can set IP by string type or Set IP address of this instance using a XParam object. Also this class has setAddress(), getAddress(), setNetmask(), getNetmask() and getNetmaskString() functions that in the next classes we explain their operations.

1.8 IPv4Param

This class defines members and functions needs to define IP v4 and inherit from IPParam class. The class construct with the name of ip parameter as string type. The functions of this class defined as:

  • The setAddress(argument) and setNetmask(argument) functions set IP adress and Netmask. These functions overloaded with bellow arguments:
    • unsigned int by calling function with this argument, it set only IP address using its compact form ,32bit numeric.
    • string by calling function with this argument, it set IP part of Address using a string. input string can be in this
      'xxx.xxx.xxx.xxx'
      format or a 32 bit number.
    • int,int,int,int by calling function with these argument, it set only IP Address using its numeric parts. part1, part2, part3, part4 parts of IP
  • The set(arguments) or assign operator(=) functions set IP and Netmask of this class. This function overloaded with these arguments:
    • IPv4Param Set IP address of this instance using another IPv4 object.
    • int Set IP part of Address using a 32-bit number.
    • string by this type of argument you can set IP by passing bellow string format:
      • "192.168.0.1"
      • "3232235521"
        in case of define netmask pass string as:
      • "192.168.0.1/24"
      • "192.168.0.1/255.255.255.0"
      • "3232235521/4294967040"
    • xparam set IP address of this instance using a XParam object.
    • int, int, int, int, int you can set IP address and netmask by pass argument in this format. set IP using seprated numeric parts and netmask using its simple form (0~32)
    • int, int, int, int, int, int, int, int these argument are seprated numric part of IP and Netmask that respectively set addresspart1, addresspart2, addresspart3, addresspart4, netmaskpart1, netmaskpart2, netmaskpart3, netmaskpart4.
  • The getNetmask() , getAddress() functions returns IP Address or Netmask as string type.
  • the getAddressCompact() and getNetmaskCompact() functions returns IP Address or Netmask as a compact 32 bit number.
  • the getAddressParts(int *parts) and getNetmaskExtended() functions returns IP Address or Netmask as a string in form of "xxx.xxx.xxx.xxx". the value() function return both of IP and Netmask.
  • the checkNetworkAvailability() function check if the given IP is accessible through this IP that will check accessibility for. return true if given IP is accessible through this IP.
You can read following example to start with IPv4Param class:
#include <iostream>

include <sparam.hpp>
include <xparam.hpp>


using namespace pparam;
using namespace std;

int main(){
	int operation;
	IPv4Param ip("first IP");
	cout << "ip initialized and its version is" << ip.getIPVersion() << endl;
	cin >> operation;
	switch(operation){
		case 0:
			cout << "set ip" << endl;
			ip.setAddress("192.168.0.1");
			cout << ip.xml(true, 8, true) << endl;
			break;
		case 1:
			cout << "set compact ip" << endl;
			ip.setAddress(3232235521);
			cout << ip.xml(true, 8, true) << endl;
			break;
		case 2:
			cout << "set part of ip" << endl;
			ip.setAddress(192, 168, 0, 1);
			cout << ip.xml(true, 8, true);
			break;
		case 3:
			cout << "set Netmask" << endl;
			ip.setNetmask("255.255.255.0");
			cout << ip.xml(true, 8, true);
			break;
		case 4:
			cout << "set compact Netmask" << endl;
			ip.setNetmask(4294967040);
			cout << ip.xml(true, 8, true);
			break;
		case 5:
			cout << "set part of Netmask" << endl;
			ip.setNetmask(255, 255, 255, 0);
			break;
		case 6:
			cout << "set IP and Netmask" << endl;
			ip.set("192.168.0.1/24");
			cout << ip.xml(true, 8, true);
			break;
		case 7:
			cout << "set compact IP and Netmask" << endl;
			ip.set("3232235521/4294967040");
			cout << ip.xml(true, 8, true);
			break;
		case 8:
			cout << "set part IP and Netmask" << endl;
			ip.set(192, 168, 0, 1, 255, 255, 255, 0);
			cout << ip.xml(true, 8, true);
			break;
	}
	if(ip.checkNetworkAvailability("192.168.0.1/12")){
		cout << "given IP is accessible through this IP" << endl;
	} else {
		cout << "given IP is not accessible through this IP" << endl;
	}
}

The output of program is:

ip initialized and its version is4
8
set part IP and Netmask
        <first IP>192.168.0.1/24</first>IP>
given IP is accessible through this IP

1.9 IPv6Param

This class defines members and functions needs to define IP v6 and inherit from IPParam class. the class construct with the name of ip parameter as string type. The functions of this class are:

  • The setNetmask(argument) function set Netmask. this function accepts int and string types in range of (0-128).
  • The setAddress(argument) function set IP adress. this function overloaded with bellow arguments:
    • string by calling function with this argument, it set IP part of Address using a string. input string can be in this
      "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx"
      format.
    • int,int,int,int,int,int,int,int by calling function with these argument, it set only IP Address using its numeric parts. part1, part2, part3, part4, part5, part6, part7, part8 parts of IP
  • The set(arguments) or assign operator(=) functions set IP and Netmask of this class. this function overloaded with these arguments:
    • IPv6Param Set IP address of this instance using another IPv6 object.
    • IPv4Param Set IP address of this instance using an IPv4 object by Stateless IP/ICMP Translation method.
    • string by this type of argument you can set IP by passing bellow string format or a valid ip4 string.
      • "2001:0db8:0000:0000:0000:ff00:0042:8329"
      • "2001:db8::ff00:42:8329"
        in case of define netmask pass string as:
      • "::1"
      • "::/128"
      • "fe80::a0::502/64"
    • xparam set IP address of this instance using a XParam object.
    • int, int, int, int, int, int, int, int, int these argument are seprated numric part of IP and Netmask that respectively set addresspart1, addresspart2, addresspart3, addresspart4, addresspart5, addresspart6, addresspart7, addresspart8 and netmaskpart1.
  • The getNetmask() , getAddress() functions get only IP Address part of this address and Netmask as string type.
  • the getAddressComlete() function get only IP Address part of this address, in standard 8 part mode.
  • the getAddressParts(int *parts) function get parts of IP address as an Array. The value() function return both of IP and Netmask.
  • the checkNetworkAvailability() function check if the given IP is accessible through this IP that will check accessibility for. return true if given IP is accessible through this IP.

1.10 IPxParam

This class contains function and member that both IPv4 and IPv6 needs and inherit from IPParam class. By pass the name of IP to constructor the class is ready and you can use functions. This class look at your IP address and detect the version of this. The class functions defines as:

  • The set() function overloaded with string and XParam types and set your IP and Netmask to class member.
  • The setAddress() function accept IP in type of string and set only IP address.
  • The getAddress() function return IP address in type of string.
  • The setNetmask() function set Netmask, it accepts int and string type and finally set class member with this value.
  • The getNetmask() and getNetmaskString() functions returns Netmask, respectively these functions returns integer and string type.
  • To findout the version of your IP address call getIPVersion() function that returns IPType::Version type.
You can read following example to start with IPxParam class:
#include <iostream>

include <sparam.hpp>
include <xparam.hpp>


using namespace pparam;
using namespace std;

int main(){
	IPxParam ip("pdn1");
	ip.setAddress("192.168.0.1");
	ip.setNetmask("24");
	cout << "IP Address " << ip.getAddress() << endl;
	cout << "Netmask " << ip.getNetmask() << endl;
	cout << "IP Version " << ip.getIPVersion() << endl;
	ip.setAddress("2001:0db8:0000:0000:0000:ff00:0042:8329");
        ip.setNetmask("128");
        cout << "IP Address " << ip.getAddress() << endl;
	cout << "Netmask " << ip.getNetmask() << endl;
	cout << "IP Version " << ip.getIPVersion() << endl;
	return 0;
}

the output of program is:

IP Address 192.168.0.1
Netmask 24
IP Version 4
IP Address 2001:db8::ff00:42:8329
Netmask 128
IP Version 6

1.11 IPxRangeParam

If you want to define IP range in both version the IPxRangeParam class help you to reach your goal. Actually this function inherit from XMixParam class. The class constructor get IP name in type of string that you can construct it. The class functions defined as:

  • The setFrom() function sets IP address and netmask for "from" part of IP address. If "to" part was already set and its'version is different with given IP address, "to" part will be emptied. this function overloaded with string and XParam type that you can initialize parameters with these types.
  • The setTo() function sets IP address and netmask for "to" part. an exception will be thrown, if either "from" part was not set or version of given IP address is different with "from" part. this function overloaded with string and XParam type that you can initialize parameters with these types.
  • The setAddressFrom() functionality is like the setFrom() function, but only set IP Address. This function accepts string type of parameter for "From" part of IP address.
  • The setAddressTo() functionality is like the setTo() function, but only set IP Address. This function accepts string type of parameter for "To" part of IP Address.
  • The setNetmaskFrom() functionality is like the setFrom() function, but only set Netmask parameter. This function accepts integer and string type for "From" part of Netmask.
  • The setNetmaskTo() functionality is like The setTo() function, but only set Netmask parameter. This function accepts integer and string type parameter for "To" part of Netmask.
  • You can get "To" and "From" of IP Address and Netmask by calling the getAddressFrom(), getAddressTo(), getNetmaskFrom(), getNetmaskTo(), getFrom() and getTo() functions. All of these functions returns value in string type. Also the get_from() and get_to() functions returns "To" and "From" value in type of IPxRangeParam.
  • This class has not member that means not of this range to set, unset and get status of this parameter call the set_not(), unset_not() and is_not() functions.
  • The has_from() and has_to() functions shows that the "To" and "From" range defined or no.
  • The key(string &) and get_key() functions respectively returns bool and string value of the IP range. The key(string &) passing argument by reference.
You can read following example to start with IPxRangeParam class:
#include <iostream>

include <sparam.hpp>
include <xparam.hpp>


using namespace pparam;
using namespace std;

int main(){
	IPxRangeParam iprange("IP_range");
	switch(getchar()){
		case '1':
			iprange.setFrom("192.168.0.1/1");
			iprange.setTo("192.168.0.128/24");
			break;
		case '2':
			iprange.setAddressFrom("192.168.0.1");
			iprange.setAddressTo("192.168.0.128");
			break;
		case '3':
			iprange.setNetmaskFrom("1");
			iprange.setNetmaskTo("24");
			break;
	}
	if(iprange.has_from() && iprange.has_to()){
		cout << iprange.value() << endl;
		cout << iprange.xml(true, 8, true);
	}
	if(!iprange.is_not()){
		iprange.set_not();
		cout << iprange.xml(true, 8, true);
	}
	return 0;
}

The output of the up code is as bellow:

1
192.168.0.1-192.168.0.128
        <IP_range>
            <from>192.168.0.1/1</from>
            <to>192.168.0.128/24</to>
            <not>no</not>
        </ip_range>
        <IP_range>
            <from>192.168.0.1/1</from>
            <to>192.168.0.128/24</to>
            <not>yes</not>
        </ip_range>

1.12 IPList

This class includes list of IPs and gets an IP address to check whether it is available or not. In fact this class inherit from XISetParam class. This class constructor accepts parameter name in type of string. The class functions defined as:

  • The setSurroundedCharacters(char, char) function get two character that surround the list. By defualt it is '[']' and if you want to change it call this function.
  • The value() function return the list of IP Address in type of string.
  • The checkNetworkAvailability() function get IP address and check network availability with IP Address list.

1.13 IPxList

The IPxList class defines list of IPxParam objects and inherit from XSetParam class. The constrcutor of class gets IP Address list name as string type and then you can call functions like:

  • The setSurroundedCharacters(char, char) function get two character that surround the list. By defualt it is '[']' and if you want to change it call this function.
  • The value() function return the list of IP Address in type of string.
  • The checkNetworkAvailability() function get IP address and check network availability with IP Address list.
You can read following example to start with IPxList class:
#include <iostream>

include <sparam.hpp>
include <xparam.hpp>


using namespace pparam;
using namespace std;

int main(){
        IPxParam ip("first IP");
        IPxList ipxlist("IPx_list");
        ip.setAddress("192.168.0.1");
        ipxlist.addT(ip);
        ip.setAddress("192.168.0.2");
        ipxlist.addT(ip);
        ip.setAddress("192.168.0.3");
        ipxlist.addT(ip);
        ip.setAddress("192.168.0.4");
        ipxlist.addT(ip);

        ipxlist.setSurroundedCharacters('#', '#');
        cout << ipxlist.value() << endl;
        cout << ipxlist.xml(true, 8, true);
        if(ipxlist.checkNetworkAvailability("192.168.0.1")){
                cout << "Network Available" << endl;
        } else {
                cout << "Network not Available" << endl;
        }
        return 0;
}

The program output is:

#192.168.0.1,192.168.0.2,192.168.0.3,192.168.0.4#
	    <IPx_list>
            <ipx>192.168.0.1</ipx>
            <ipx>192.168.0.2</ipx>
            <ipx>192.168.0.3</ipx>
            <ipx>192.168.0.4</ipx>
        </ipx_list>
Network not Available

1.14 PortParam

To define port and port range use PortParam class and inherit from XSingleParam class. this class includes single port and port range at following formats:

  1. [!][[N]:]N
  2. [!]N[:[N]]
Which N is a unsigned interger between 1 to 65536. if you enter '!' at first of port range the it will be reverse port range. The class constructor accept port name in type of string. The class functions define as:
  • The assign operator (operator=()) is defined and it supports integer, string, XParam and PortParam types. If you want to set single port pass a number in defined type. But if you want to set port range you can insert in defined template.
  • The isPortRange() function says that user insert a single port or port range by returning true or false.
  • If user define port range, you can get "from" and "to" of it by call get_from() and get_to() functions. it returns XInt type.
  • The value() function return value of port in type of string.
You can read following example to start with PortParam class:
#include <iostream>

include <sparam.hpp>
include <xparam.hpp>


using namespace pparam;
using namespace std;

int main(){
        PortParam portparam("my Port");
        portparam.reset();
        portparam.operator=(12);
        cout << portparam.value() << endl;
        cout << portparam.xml(true, 8, true);
        if(!portparam.isPortRange()){
                cout << "Single port" << endl;
        }
        portparam.operator=("!21:29");
        cout << "the port is from: " << portparam.get_from() << " to: " << portparam.get_to() << endl;
        cout << portparam.xml(true, 8, true);
        if(portparam.isPortRange()){
                cout << "Port range" << endl;
        }

}

The output of this program is as bellow:

12
        <my Port>12</my>Port>
Single port
the port is from: 21 to: 29
        <my Port>!21:29</my>Port>
Port range

1.15 PortList

If you want to create list of ports use PortList class and inherit from XSetParam class. This class can constrcut by passing the list name as string type. The class functions defined as:

  • To add or remove port from list you can call addPort() and deletePort() functions. In case of add you should pass port in type of string and in case of remove the value of removed passing by reference in type of string.
  • The value() function returns the content of list in type of string.
  • You can change the begin and end character of list by call setSurroundedCharacters(char, char) function. You should pass two charater that first is for begin of list and second for end of it.
You can read following example to start with PortList class:
#include <iostream>

include <sparam.hpp>
include <xparam.hpp>


using namespace pparam;
using namespace std;

int main(){
        PortList portlist("my_port_list");
        portlist.addPort("68");
        portlist.addPort("128:259");
        portlist.addPort("!174:212");
        cout << portlist.value() << endl;
        cout << portlist.xml(true, 8, true);
        portlist.deletePort("68");
        portlist.deletePort("128:259");
        cout << portlist.value() << endl;
        cout << portlist.xml(true, 8, true);
        return 0;
}

The output of program is:

[68,128:259,!174:212]
        <my_port_list>
            <port>68</port>
            <port>128:259</port>
            <port>!174:212</port>
        </my_port_list>
!174:212
        <my_port_list>
            <port>!174:212</port>
        </my_port_list>

1.16 MACAddressParam

To define the MAC Address you can use MACAddressParam and inherit from XTextParam class. This class get MAC Address name as string type and construct it. The class functions are:

  • The key() function set MAC Address in type of string.
  • The get_key() function get back you the MAC Address.
  • The assign operator (operator=()) accept string and char types that set MAC Address value.