1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_core_util_MultiRangeExpression_hpp
10 #define anna_core_util_MultiRangeExpression_hpp
21 * Class helper to manage multi-range expression like '1-4,23,45-46' (1,2,3,4,23,45,46)
23 class MultiRangeExpression {
25 std::string a_literal;
26 std::map < unsigned int, int/*dummy*/ > a_data; // expands literal
29 void refresh(void) throw(); // keep coherence between 'a_data' and 'a_literal'
34 MultiRangeExpression() {};
35 ~MultiRangeExpression() {};
39 * Gets the configured literal by mean #setLiteral or #addLiteral
43 const char * getLiteral(void) const throw() { return a_literal.c_str(); }
46 * Gets expanded representation for stored literal. E.g.: '1-3,8,10' => '1,2,3,7,8,10'
48 * @return Expanded literal
50 std::string getExpandedLiteral(void) const throw();
53 * Simplify stored literal. E.g.: '1,1,1,2,3,7,8,10' => '1-3,8,10' and returns it.
55 * @return Simplified literal
57 const char * simplifyLiteral(void) throw();
62 * Returns true if the value provided is contained in the multirange expression literal
64 * @param value Value to be tested
65 * @return True or false
67 bool contain(const unsigned int & value) const throw() { return (a_data.find(value) != a_data.end()); }
72 * Configures a new literal
74 * @param l Literal to be stored
76 void setLiteral(const char * l) throw() {
77 a_literal = l ? l : "";
82 * Accumulates the provided literal over the stored literal
83 * You could simplify with #simplifyLiteral, because perhaps there is overlapping between current literal and provided one.
85 * @param l Literal to be added
87 void addLiteral(const char * l) throw() {
90 if(std::string(l) != "") {