2. write the specification for the \"APIGateway\" class, which is in namespace c
ID: 3808964 • Letter: 2
Question
2. write the specification for the "APIGateway" class, which is in namespace csci2312 and has the following attributes: gatewayCounter, which keeps track of all the APIGateway objects created various network nodes (class level) gatewaylD to store a numeric APIGateway instance identifier gatewayName to store the name/title of the APIGateway instance domains, a static array which stores the names of business domains served a given gateway MAY DOMAINS set to some number, indicating the maximum number o domains a gateway can handle (used as a default) api List a handle to dynamic array of REST API specs MAX APIs set to some number, indicating the maximum number of API gateway can manage (used a default) api Count to hold the number of expected APIs at the time of constructin gateway object response Rate to store the average API response rate The class will also need several standard methods, such as Default constructorExplanation / Answer
#include<iostream>
#include<string.h>
#include <list>
#include <array>
using namespace csci2312;
class APIGateway
{
private:
const int MAX_DOMAINS = 50;
const int MAX_APIs = 50;
static int gatewayCounter; // its a static variable and will keep incrementing on evvery object creation
static string domains [MAX_DOMAINS];
list<string> *apiList;
int gateWayId;
string gatewayName;
int responseRate;
int apiCount;
public:
APIGateway() // default constructor
{
gatewayCounter++;
apiList = new list<string>[];
gateWayId = gatewayCounter;
gatewayName = "default Gateway";
domains[gatewayCounter-1] = gatewayName;
apiCount = 0;
responseRate = 0;
}
APIGateway(int count) //Custom constructor to indicate how many API specs expected
{
gatewayCounter++;
apiList = new list<string>[count];
gateWayId = gatewayCounter;
gatewayName = "default Gateway";
domains[gatewayCounter-1] = gatewayName;
apiCount = count;
responseRate = 0;
}
APIGateway(int count, string gateWayName) // another constructor for gateway name and API count
{
gatewayCounter++;
apiList = new list<string>[count];
gateWayId = gatewayCounter;
gatewayName = gateWayName;
domains[gatewayCounter-1] = gatewayName;
apiCount = count;
responseRate = 0;
}
void APIGateway:: passResponseRate(int r)
{
responseRate = r;
}
int APIGateway:: getResponseRate()
{
return responseRate;
}
void APIGateway:: setDomain(int index, string domain)
{
if(index >= sizeof(domains)/sizeof(domains[0]) || index < 0)
{
cout << "Bad Allocation";
}
else
{
domains[index] = domain;
}
}
string APIGateway:: getDomain(int index)
{
if(index >= sizeof(domains)/sizeof(domains[0]) || index < 0)
{
cout << "Bad Index";
return "";
}
else
{
return domains[index];
}
}
//mutator
void APIGateway:: setAPI(int index, list<string> *api)
{
if(index >= sizeof(apiList)/sizeof(apiList[0]) || index < 0)
{
cout << "Bad Allocation";
}
else
{
apiList[index] = *api;
}
}
//accessor
list<string> APIGateway:: getAPI(int index)
{
if(index >= sizeof(apiList)/sizeof(apiList[0]) || index < 0)
{
cout << "Bad Index";
list<string> *a = new list<string>();
return *a;
}
else
{
return apiList[index];
}
}
bool APIGateway:: runAPI(int index)
{
if(index >= sizeof(apiList)/sizeof(apiList[0]) || index < 0)
{
cout << "Bad Index";
return false;
}
else
{
// do some operation
return true; // if it is as expected or return falase.
}
}
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.