Frobby  0.9.5
Public Member Functions | Static Public Attributes | Private Types | Static Private Member Functions | Private Attributes | List of all members
VarNames Class Reference

Defines the variables of a polynomial ring and facilities IO involving them. More...

#include <VarNames.h>

Public Member Functions

 VarNames ()
 
 VarNames (size_t varCount)
 
 VarNames (const VarNames &names)
 
 ~VarNames ()
 
bool addVar (const string &name)
 Adds the variable and returns true if name is not already a variable. More...
 
void addVarSyntaxCheckUnique (const Scanner &in, const string &name)
 As addvar, except it reports a syntax error if name is already a variable. More...
 
bool operator< (const VarNames &names) const
 This also depends on the order of the names. More...
 
size_t getIndex (const string &name) const
 Returns VarNames::invalidIndex() if name is not known. More...
 
bool contains (const string &name) const
 Returns true if name is the name of a variable. More...
 
bool namesAreDefault () const
 Returns true if the names are x1, x2 and so on. More...
 
const string & getName (size_t index) const
 The returned reference can become invalid next time addVar is called. More...
 
size_t getVarCount () const
 Returns the current number of variables. More...
 
void clear ()
 Resets the number of variables to zero. More...
 
bool empty () const
 Returns true if the number of variables is zero. More...
 
VarNamesoperator= (const VarNames &names)
 
bool operator== (const VarNames &names) const
 
bool operator!= (const VarNames &names) const
 
void swapVariables (size_t a, size_t b)
 Swaps the variables with indexes a and b. More...
 
void projectVar (size_t index)
 
void toString (string &str) const
 
void print (FILE *file) const
 
void swap (VarNames &names)
 

Static Public Attributes

static const size_t invalidIndex = static_cast<size_t>(-1)
 Returns a fixed variable offset that is always invalid. More...
 

Private Types

typedef unordered_map< string, size_t > VarNameMap
 

Static Private Member Functions

static bool compareNames (const string *a, const string *b)
 

Private Attributes

VarNameMap _nameToIndex
 
vector< const string * > _indexToName
 

Detailed Description

Defines the variables of a polynomial ring and facilities IO involving them.

Todo:
Rename to Ring or a similar name.
Todo:
make this class immutable and make a VarNamesBuilder.
Todo:
make copies share the same memory and use reference counting to deallocate the shared memory.
Todo:
make equality check for the same memory and thus return true very quickly if that is the case.

Definition at line 40 of file VarNames.h.

Member Typedef Documentation

◆ VarNameMap

typedef unordered_map<string, size_t> VarNames::VarNameMap
private

Definition at line 105 of file VarNames.h.

Constructor & Destructor Documentation

◆ VarNames() [1/3]

VarNames::VarNames ( )

Definition at line 25 of file VarNames.cpp.

◆ VarNames() [2/3]

VarNames::VarNames ( size_t  varCount)

Definition at line 28 of file VarNames.cpp.

◆ VarNames() [3/3]

VarNames::VarNames ( const VarNames names)

Definition at line 36 of file VarNames.cpp.

◆ ~VarNames()

VarNames::~VarNames ( )

Definition at line 40 of file VarNames.cpp.

Member Function Documentation

◆ addVar()

bool VarNames::addVar ( const string &  name)

Adds the variable and returns true if name is not already a variable.

Otherwise it returns false without adding the variable (again).

Definition at line 44 of file VarNames.cpp.

◆ addVarSyntaxCheckUnique()

void VarNames::addVarSyntaxCheckUnique ( const Scanner in,
const string &  name 
)

As addvar, except it reports a syntax error if name is already a variable.

Todo:
Move this somewhere more appropriate.

Definition at line 68 of file VarNames.cpp.

◆ clear()

void VarNames::clear ( )

Resets the number of variables to zero.

Definition at line 106 of file VarNames.cpp.

◆ compareNames()

bool VarNames::compareNames ( const string *  a,
const string *  b 
)
staticprivate

Definition at line 195 of file VarNames.cpp.

◆ contains()

bool VarNames::contains ( const string &  name) const

Returns true if name is the name of a variable.

Definition at line 91 of file VarNames.cpp.

◆ empty()

bool VarNames::empty ( ) const

Returns true if the number of variables is zero.

Definition at line 111 of file VarNames.cpp.

◆ getIndex()

size_t VarNames::getIndex ( const string &  name) const

Returns VarNames::invalidIndex() if name is not known.

Definition at line 83 of file VarNames.cpp.

◆ getName()

const string & VarNames::getName ( size_t  index) const

The returned reference can become invalid next time addVar is called.

Definition at line 100 of file VarNames.cpp.

◆ getVarCount()

size_t VarNames::getVarCount ( ) const
inline

Returns the current number of variables.

Definition at line 113 of file VarNames.h.

◆ namesAreDefault()

bool VarNames::namesAreDefault ( ) const

Returns true if the names are x1, x2 and so on.

Definition at line 95 of file VarNames.cpp.

◆ operator!=()

bool VarNames::operator!= ( const VarNames names) const

Definition at line 139 of file VarNames.cpp.

◆ operator<()

bool VarNames::operator< ( const VarNames names) const

This also depends on the order of the names.

Definition at line 75 of file VarNames.cpp.

◆ operator=()

VarNames & VarNames::operator= ( const VarNames names)

Definition at line 115 of file VarNames.cpp.

◆ operator==()

bool VarNames::operator== ( const VarNames names) const

Definition at line 128 of file VarNames.cpp.

◆ print()

void VarNames::print ( FILE *  file) const

Definition at line 180 of file VarNames.cpp.

◆ projectVar()

void VarNames::projectVar ( size_t  index)

Definition at line 161 of file VarNames.cpp.

◆ swap()

void VarNames::swap ( VarNames names)

Definition at line 190 of file VarNames.cpp.

◆ swapVariables()

void VarNames::swapVariables ( size_t  a,
size_t  b 
)

Swaps the variables with indexes a and b.

Definition at line 143 of file VarNames.cpp.

◆ toString()

void VarNames::toString ( string &  str) const

Definition at line 171 of file VarNames.cpp.

Member Data Documentation

◆ _indexToName

vector<const string*> VarNames::_indexToName
private

Definition at line 108 of file VarNames.h.

◆ _nameToIndex

VarNameMap VarNames::_nameToIndex
private

Definition at line 107 of file VarNames.h.

◆ invalidIndex

const size_t VarNames::invalidIndex = static_cast<size_t>(-1)
static

Returns a fixed variable offset that is always invalid.

Definition at line 100 of file VarNames.h.


The documentation for this class was generated from the following files: