Skip to content
Snippets Groups Projects
Commit f1158e4a authored by Jan Trávníček's avatar Jan Trávníček
Browse files

implement substring generation

parent 475037e7
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
   
#include <algorithm> #include <algorithm>
#include <random> #include <random>
#include <vector>
#include <exception/AlibException.h>
   
namespace string { namespace string {
   
......
/* /*
* RandomAutomatonFactory.h * RandomStringFactory.h
* *
* Created on: 27. 3. 2014 * Created on: 27. 3. 2014
* Author: Jan Travnicek * Author: Jan Travnicek
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
#define RANDOM_STRING_FACTORY_H_ #define RANDOM_STRING_FACTORY_H_
   
#include <set> #include <set>
#include <vector>
#include <exception/AlibException.h>
#include <string/LinearString.h> #include <string/LinearString.h>
   
namespace string { namespace string {
......
/*
* RandomSubstringFactory.cpp
*
* Created on: 27. 3. 2014
* Author: Jan Travnicek
*/
#include "RandomSubstringFactory.h"
#include <algorithm>
#include <random>
#include <exception/AlibException.h>
#include <string/LinearString.h>
namespace string {
namespace generate {
string::LinearString RandomSubstringFactory::generateSubstring( size_t size, const string::LinearString & string) {
if(size > string.getContent().size())
throw exception::AlibException("String not long enough");
srand( time( NULL ) );
size_t begin = std::random_devices::semirandom() % (string.getContent().size() - size + 1);
std::vector<alphabet::Symbol> data(string.getContent().begin() + begin, string.getContent().begin() + begin + size);
return LinearString {string.getAlphabet(), data};
}
auto RandomSubstringFactoryLinearString = RandomSubstringFactory::RegistratorWrapper < string::LinearString, string::LinearString > ( RandomSubstringFactory::getInstance ( ), RandomSubstringFactory::generateSubstring );
} /* namespace generate */
} /* namespace string */
/*
* RandomSubstringFactory.h
*
* Created on: 27. 3. 2014
* Author: Jan Travnicek
*/
#ifndef RANDOM_SUBSTRING_FACTORY_H_
#define RANDOM_SUBSTRING_FACTORY_H_
#include <core/multipleDispatch.hpp>
#include <string/String.h>
#include <string/StringFeatures.h>
namespace string {
namespace generate {
class RandomSubstringFactory : public std::SingleDispatchFirstStaticParam < string::LinearString, size_t, string::StringBase > {
public:
static string::LinearString generateSubstring( size_t size, const string::LinearString & );
static RandomSubstringFactory& getInstance() {
static RandomSubstringFactory res;
return res;
}
};
} /* namespace generate */
} /* namespace string */
#endif /* RANDOM_SUBSTRING_FACTORY_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment