-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServerFactory.cpp
More file actions
32 lines (30 loc) · 1 KB
/
ServerFactory.cpp
File metadata and controls
32 lines (30 loc) · 1 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
#include "ServerFactory.hpp"
#include "ThreadPoolServer.hpp"
#include "SemaphoreServer.hpp"
#include "./LRUCache.hpp"
#include "./LFUCache.hpp"
std::unique_ptr<HTTPServer> ServerFactory::createHTTPServer(const std::string &serverType, const std::string &cacheType, int numThreads, int cacheSize)
{
auto cache = createCacheStrategy(cacheType, cacheSize);
if (serverType == "Threadpool")
{
return std::make_unique<ThreadPoolServer>(std::move(cache));
}
else if (serverType == "Semaphore")
{
return std::make_unique<SemaphoreServer>(std::move(cache));
}
throw std::invalid_argument("Invalid server type");
}
std::unique_ptr<CacheStrategy> ServerFactory::createCacheStrategy(const std::string &cacheType, int cacheSize)
{
if (cacheType == "LRUCache")
{
return std::make_unique<LRUCache>(cacheSize);
}
else if (cacheType == "LFUCache")
{
return std::make_unique<LFUCache>(cacheSize);
}
throw std::invalid_argument("Invalid cache type");
}