tgen
Loading...
Searching...
No Matches

String instance. More...

Inheritance diagram for tgen::str::instance:

Public Member Functions

 instance (const std::string &str)
 Creates a string instance from a std::string.
int size () const
 Returns the size of the string instance.
char & operator[] (int idx)
 Accesses the character at some position of the instance.
instancesort ()
 Sorts the characters in non-decreasing order.
instancereverse ()
 Reverses the instance.
instancelowercase ()
 Sets all characters to lowercase.
instanceuppercase ()
 Sets all characters to uppercase.
instance operator+ (const instance &rhs)
 Concatenates two instances.
std::string to_std () const
 Converts the instance to a std::string.
Public Member Functions inherited from tgen::gen_instance_base< instance >
bool operator< (const instance &rhs) const

Friends

std::ostream & operator<< (std::ostream &out, const instance &inst)
 Prints the instance to a std::ostream.

Detailed Description

String instance.

Instance of a string.

It can be deterministically operated upon (see Generator Instance Operations for random operations) and printed through std::cout.

Definition at line 3138 of file tgen.h.

Constructor & Destructor Documentation

◆ instance()

tgen::str::instance::instance ( const std::string & str)
inline

Creates a string instance from a std::string.

Parameters
strThe std::string representing the instance.

Examples

// Creates and prints an instance from a std::string.
std::string s = "aba";
std::cout << inst << std::endl; // Prints "aba".
String instance.
Definition tgen.h:3138

Definition at line 3146 of file tgen.h.

Member Function Documentation

◆ lowercase()

instance & tgen::str::instance::lowercase ( )
inline

Sets all characters to lowercase.

Complexity

O(n).

Examples

// Sets an instance to lowercase and prints it.
std::cout << inst.lowercase() << std::endl; // Prints "ABC".
Sequence instance.
Definition tgen.h:1242

Definition at line 3181 of file tgen.h.

◆ operator+()

instance tgen::str::instance::operator+ ( const instance & rhs)
inline

Concatenates two instances.

Parameters
rhsThe right-hand side.
Returns
The concatenation.

Complexity

Linear.

Examples

// Concatenates and prints two instances.
tgen::str s = tgen::str(5, 'a', 'z').distinct();
std::cout << s.gen() + s.gen() << std::endl;
String generator.
Definition tgen.h:3055
instance gen() const
Generates a random instance from the set of valid strings.
Definition tgen.h:3214
str & distinct(std::set< int > indices)
Restricts generator s.t. all characters in index set are distinct.
Definition tgen.h:3116

Definition at line 3197 of file tgen.h.

◆ operator[]()

char & tgen::str::instance::operator[] ( int idx)
inline

Accesses the character at some position of the instance.

Parameters
idxIndex to be accessed.
Returns
The character at index idx.

Examples

// Changes and prints a position of an instance.
tgen::str::instance inst = "aba";
++inst[1];
std::cout << inst[1] << std::endl; // Prints "c".

Definition at line 3154 of file tgen.h.

◆ reverse()

instance & tgen::str::instance::reverse ( )
inline

Reverses the instance.

Complexity

O(n).

Examples

// Reverses and prints an instance.
tgen::str::instance inst = "bac";
std::cout << inst.reverse() << std::endl; // Prints "cab".
instance & reverse()
Reverses the instance.
Definition tgen.h:3174

Definition at line 3174 of file tgen.h.

◆ size()

int tgen::str::instance::size ( ) const
inline

Returns the size of the string instance.

Returns
The number of characters in the instance.

Examples

// Prints the size of an instance.
tgen::str::instance inst = "aba";
std::cout << inst.size() << std::endl; // Prints "3".
int size() const
Returns the size of the string instance.
Definition tgen.h:3151

Definition at line 3151 of file tgen.h.

◆ sort()

instance & tgen::str::instance::sort ( )
inline

Sorts the characters in non-decreasing order.

Complexity

O(n log n).

Examples

// Sorts and prints an instance.
tgen::str::instance inst = "aba";
std::cout << inst.sort() << std::endl; // Prints "aab".
instance & sort()
Sorts the characters in non-decreasing order.
Definition tgen.h:3167

Definition at line 3167 of file tgen.h.

◆ to_std()

std::string tgen::str::instance::to_std ( ) const
inline

Converts the instance to a std::string.

Returns
A std::string representing the instance.

Examples

// Convoluted way to reverse a string.
std::string s = "bac";
// s = "cab".
std::string to_std() const
Converts the instance to a std::string.
Definition tgen.h:3208

Definition at line 3208 of file tgen.h.

◆ uppercase()

instance & tgen::str::instance::uppercase ( )
inline

Sets all characters to uppercase.

Complexity

O(n).

Examples

// Sets an instance to uppercase and prints it.
std::cout << inst.uppercase() << std::endl; // Prints "abc".

Definition at line 3189 of file tgen.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const instance & inst )
friend

Prints the instance to a std::ostream.

The string is printed with no end of line.

Examples

// Prints an instance.
std::cout << tgen::str::instance("aba") << std::endl; // Prints "aba".

Definition at line 3202 of file tgen.h.


The documentation for this struct was generated from the following files:
  • /home/runner/work/tgen/tgen/single_include/tgen.h
  • str.dox