idaeim studio
 Strings

Classes | Public Types | Public Member Functions | Static Public Attributes
Line_Count_Filter Class Reference

Line counting for a Sliding_String. More...

#include <Line_Count_Filter.hh>

Inheritance diagram for Line_Count_Filter:
Inheritance graph
[legend]
Collaboration diagram for Line_Count_Filter:
Collaboration graph
[legend]

List of all members.

Classes

struct  Position
 A line count and character offset Position. More...

Public Types

typedef Sliding_String::Location Location
 A virtual location in a Sliding_String.

Public Member Functions

bool enabled (const Position &position)
 Enables the line counter with a new initial Position.
bool enabled () const
 Tests if the filter is enabled or disabled.
bool enabled (bool enable)
 Enables or disables filtering.
void filter (std::string &a_string, Index start=0, Index end=std::string::npos)
 The line counters are updated based on the contents of a string.
std::string identification () const
 Gets the class ID string.
 Line_Count_Filter (const Position &position=Position(1, 0))
 Constructs a Line_Count_Filter in a newly enabled condition.
Position position (Location location) const
 Returns the Position corresponding to the Index in the last string filtered.

Static Public Attributes

static const char *const ID
 Class identification.

Detailed Description

Line counting for a Sliding_String.

As a Sliding_String is extended during a Sliding_String::slide, this filter keeps track of the Location of the beginning of each line in the cumulative string. A Location is the cumulative index of all sequential strings that are filtered. Lines are counted at each occurance of a new-line ('
') character in the string. The first line (line 1) is the portion of the string up to and including the first new-line. A line begins with the next character after the new-line.

When a Line_Count_Filter is created it is initialized with the beginning Position of the first string to be filtered. A Position contains line count and character offset members. By default the initial Position is line 1, character 0. The filter records the Location of the beginning of each line after the first line.

At any time the Position of any Location in the cumulative string may be found.

N.B.: The Location of a character in the cumulative string is equivalent, but not necessarily identical, to the Location of the same character in the corresponding Sliding_String. Locations of the Line_Count_Filter are for the string at the time it was presented for filtering. Locations of the Sliding_String may be affected by application changes to the contents of the string. If the relative location of characters in the Sliding_String do not change, then both Location concepts are identical. Changes of new-line characters in the Sliding_String may, of course, affect the validity of line counts if the changes happen after the Line_Count_Filter has been applied.

See also:
String_Filter
Sliding_String
Author:
Bradford Castalia 1.12

Member Typedef Documentation

A virtual location in a Sliding_String.


Constructor & Destructor Documentation

Line_Count_Filter ( const Position position = Position(1, 0))

Constructs a Line_Count_Filter in a newly enabled condition.

An initial Position may be specified.

Parameters:
positionThe initial Position of the line counter. [Default: line 1, character offset 0]

Member Function Documentation

std::string identification ( ) const [virtual]

Gets the class ID string.

Reimplemented from String_Filter.

void filter ( std::string &  a_string,
Index  start = 0,
Index  end = std::string::npos 
) [virtual]

The line counters are updated based on the contents of a string.

The Position of the start and end indices in the string are determined. The Position of the start index is the Position of the end index from the previous filter operation (when an initial Position is set, it is the end index Position that is set). To determine the new end index Position the character offset counter is incremented until a new-line character ('\n') is encountered, which increments the line counter and resets the character offset counter. The search for new-lines is over the Index range (start, end] within the string. The end Index is always set to the length of the string. It is assumed that the start Index corresponds to the same character as the end Index of the previous filter operation (as is the case for a Sliding_String::slide), otherwise the Position values are likely to be invalid.

Parameters:
a_stringThe string to be examined.
startThe starting Index in the string from which to search for new-line deliminters.
endThe end of the range over which to search.

Reimplemented from String_Filter.

Position position ( Location  location) const

Returns the Position corresponding to the Index in the last string filtered.

If the Index is beyond the end of the last string, the value returned is the end Position with a character offset of std::string::npos. If the string has been altered since the last filter operation, the Position may not be valid.

Note: A Position can be determined even if the filter has been disabled. But the caveat about modifiying the last filtered string apply.

Parameters:
locationThe Index for which to find a Position.
Returns:
The Position of the index.
See also:
filter(std::string&, Index, Index)
bool enabled ( const Position position)

Enables the line counter with a new initial Position.

Parameters:
positionThe initial Position of the line counter.
Returns:
The previous state of the filter.
bool enabled ( bool  enable) [virtual]

Enables or disables filtering.

If the filter is being re-enabled after being disabled then the initial Position will reset to (0, 0). If the filter is currently in the same state as the enable argument, nothing is changed. Using

filter.enabled (filter.enabled (false))

will not change the current enabled state of the filter, but will reset the line counter if the filter is enabled.

Parameters:
enableIf true filtering will be enabled; otherwise it is disabled.
Returns:
The previous state of the filter.

Reimplemented from String_Filter.

bool enabled ( ) const [virtual]

Tests if the filter is enabled or disabled.

Returns:
The current state of the filter.

Reimplemented from String_Filter.


Member Data Documentation

const char* const ID [static]

Class identification.


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