accum-number-to-string

nazarijtipusak080/accumulate-and-read-character-string/accum-number-to-string

Accumulates a string of characters (numbers) supplied to the CHAR input.
accum-number-to-string
@/accum-number-to-string
Accumulates a string of characters (numbers) supplied to the CHAR input.
CAPnumber
The capacity of the string buffer. Defines the maximum length. Must be a constant value. Any changes during program execution will be ignored.
CHARnumber
PUSHpulse
Push new character
RSTpulse
Empty the accumulated string and start over
accum-number-to-string
CAP
CHAR
PUSH
RST
STR
UPD
FULL
FULLpulse
Pulses when string reached maximum length and pushed character was ignored
UPDpulse
Pulses when resulting string is updated
STRstring
String that is accumulated so far
To use the node in your project you should have the nazarijtipusak080/accumulate-and-read-character-string library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

node {
    char* buff;
    char* cursor;
    size_t cap;
    CStringView view;

    void evaluate(Context ctx) {
        if (isSettingUp()) {
            // save initial cap to ignore possiple input changes during program execution
            cap = getValue<input_CAP>(ctx);
            buff = new char[cap + 1]; // +1 to make room for terminal '\0'
            view = CStringView(buff);
        }

        if (isSettingUp() || isInputDirty<input_RST>(ctx)) {
            memset(buff, '\0', cap + 1);
            cursor = buff;
        }

        if (isInputDirty<input_PUSH>(ctx)) {
            if (cursor >= &buff[cap]) {
                emitValue<output_FULL>(ctx, 1);
                return;
            }

            *cursor = getValue<input_CHAR>(ctx);
            cursor++;
            emitValue<output_STR>(ctx, XString(&view));
            emitValue<output_UPD>(ctx, 1);
        }
    }
}