# Buffers

Functions that provide dynamically buffered stream-like data structures.

  Typedefs

  typedef struct vrna_cstr_s *vrna_cstr_t
    #include <ViennaRNA/datastructures/char_stream.h>
  typedef struct vrna_ordered_stream_s *vrna_ostream_t
    #include <ViennaRNA/datastructures/stream_output.h>

    An ordered output stream structure with unordered insert capabilities.

  typedef void (*vrna_stream_output_f)(void *auxdata, unsigned int i, void *data)
    #include <ViennaRNA/datastructures/stream_output.h>

    Ordered stream processing callback.

    This callback will be processed in sequential order as soon as sequential data in the output stream becomes available.

    Note

    The callback must also release the memory occupied by the data passed since the stream will lose any reference to it after the callback has been executed.

    Param auxdata:

      A shared pointer for all calls, as provided by the second argument to vrna_ostream_init()

    Param i:

      The index number of the data passed to `data`

    Param data:

      A block of data ready for processing

  typedef void vrna_callback_stream_output(void *auxdata, unsigned int i, void *data)
    #include <ViennaRNA/datastructures/stream_output.h>

  Functions

  vrna_cstr_t vrna_cstr(size_t size, FILE *output)
    #include <ViennaRNA/datastructures/char_stream.h>

    Create a dynamic char * stream data structure.

    See also

    vrna_cstr_free(), vrna_cstr_close(), vrna_cstr_fflush(), vrna_cstr_discard(), vrna_cstr_printf()

    Parameters:

      - size – The initial size of the buffer in characters

      - output – An optional output file stream handle that is used to write the collected data to (defaults to stdout if NULL)

  void vrna_cstr_discard(struct vrna_cstr_s *buf)
    #include <ViennaRNA/datastructures/char_stream.h>

    Discard the current content of the dynamic char * stream data structure.

    See also

    vrna_cstr_free(), vrna_cstr_close(), vrna_cstr_fflush(), vrna_cstr_printf()

    Parameters:

      - buf – The dynamic char * stream data structure to free

  void vrna_cstr_free(vrna_cstr_t buf)
    #include <ViennaRNA/datastructures/char_stream.h>

    Free the memory occupied by a dynamic char * stream data structure.

    This function first flushes any remaining character data within the stream and then free’s the memory occupied by the data structure.

    See also

    vrna_cstr_close(), vrna_cstr_fflush(), vrna_cstr()

    Parameters:

      - buf – The dynamic char * stream data structure to free

  void vrna_cstr_close(vrna_cstr_t buf)
    #include <ViennaRNA/datastructures/char_stream.h>

    Free the memory occupied by a dynamic char * stream and close the output stream.

    This function first flushes any remaining character data within the stream then closes the attached output file stream (if any), and finally free’s the memory occupied by the data structure.

    See also

    vrna_cstr_free(), vrna_cstr_fflush(), vrna_cstr()

    Parameters:

      - buf – The dynamic char * stream data structure to free

  void vrna_cstr_fflush(struct vrna_cstr_s *buf)
    #include <ViennaRNA/datastructures/char_stream.h>

    Flush the dynamic char * output stream.

    This function flushes the collected char * stream, either by writing to the attached file handle, or simply by writing to stdout if no file handle has been attached upon construction using vrna_cstr().

    See also

    vrna_cstr(), vrna_cstr_close(), vrna_cstr_free()

    Parameters:

      - buf – The dynamic char * stream data structure to flush

    Post:

      The stream buffer is empty after execution of this function

  const char *vrna_cstr_string(vrna_cstr_t buf)
    #include <ViennaRNA/datastructures/char_stream.h>
  int vrna_cstr_vprintf(vrna_cstr_t buf, const char *format, va_list args)
    #include <ViennaRNA/datastructures/char_stream.h>
  int vrna_cstr_printf(vrna_cstr_t buf, const char *format, ...)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_message_info(vrna_cstr_t buf, const char *format, ...)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_message_vinfo(vrna_cstr_t buf, const char *format, va_list args)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_message_warning(struct vrna_cstr_s *buf, const char *format, ...)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_message_vwarning(struct vrna_cstr_s *buf, const char *format, va_list args)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_fasta_header(vrna_cstr_t buf, const char *head)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_printf_structure(struct vrna_cstr_s *buf, const char *structure, const char *format, ...)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_vprintf_structure(struct vrna_cstr_s *buf, const char *structure, const char *format, va_list args)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_printf_comment(struct vrna_cstr_s *buf, const char *format, ...)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_vprintf_comment(struct vrna_cstr_s *buf, const char *format, va_list args)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_printf_thead(struct vrna_cstr_s *buf, const char *format, ...)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_vprintf_thead(struct vrna_cstr_s *buf, const char *format, va_list args)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_printf_tbody(struct vrna_cstr_s *buf, const char *format, ...)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_vprintf_tbody(struct vrna_cstr_s *buf, const char *format, va_list args)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_eval_sd_corr(struct vrna_cstr_s *buf)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_eval_ext_loop(struct vrna_cstr_s *buf, int energy)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_eval_ext_loop_revert(struct vrna_cstr_s *buf, int energy)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_eval_hp_loop(struct vrna_cstr_s *buf, int i, int j, char si, char sj, int energy)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_eval_hp_loop_revert(struct vrna_cstr_s *buf, int i, int j, char si, char sj, int energy)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_eval_int_loop(struct vrna_cstr_s *buf, int i, int j, char si, char sj, int k, int l, char sk, char sl, int energy)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_eval_int_loop_revert(struct vrna_cstr_s *buf, int i, int j, char si, char sj, int k, int l, char sk, char sl, int energy)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_eval_mb_loop(struct vrna_cstr_s *buf, int i, int j, char si, char sj, int energy)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_eval_mb_loop_revert(struct vrna_cstr_s *buf, int i, int j, char si, char sj, int energy)
    #include <ViennaRNA/datastructures/char_stream.h>
  void vrna_cstr_print_eval_gquad(struct vrna_cstr_s *buf, unsigned int i, unsigned int j, unsigned int L, unsigned int l[3], int energy)
    #include <ViennaRNA/datastructures/char_stream.h>
  vrna_ostream_t vrna_ostream_init(vrna_stream_output_f output, void *auxdata)
    #include <ViennaRNA/datastructures/stream_output.h>

    Get an initialized ordered output stream.

    See also

    vrna_ostream_free(), vrna_ostream_request(), vrna_ostream_provide()

    Parameters:

      - output – A callback function that processes and releases data in the stream

      - auxdata – A pointer to auxiliary data passed as first argument to the `output` callback

    Returns:

      An initialized ordered output stream

  void vrna_ostream_free(vrna_ostream_t dat)
    #include <ViennaRNA/datastructures/stream_output.h>

    Free an initialized ordered output stream.

    See also

    vrna_ostream_init()

    Parameters:

      - dat – The output stream for which occupied memory should be free’d

  int vrna_ostream_threadsafe(void)
    #include <ViennaRNA/datastructures/stream_output.h>
  void vrna_ostream_request(vrna_ostream_t dat, unsigned int num)
    #include <ViennaRNA/datastructures/stream_output.h>

    Request index in ordered output stream.

    This function must be called prior to vrna_ostream_provide() to indicate that data associted with a certain index number is expected to be inserted into the stream in the future.

    See also

    vrna_ostream_init(), vrna_ostream_provide(), vrna_ostream_free()

    Parameters:

      - dat – The output stream for which the index is requested

      - num – The index to request data for

  void vrna_ostream_provide(vrna_ostream_t dat, unsigned int i, void *data)
    #include <ViennaRNA/datastructures/stream_output.h>

    Provide output stream data for a particular index.

    See also

    vrna_ostream_request()

    Parameters:

      - dat – The output stream for which data is provided

      - i – The index of the provided data

      - data – The data provided

    Pre:

      The index data is provided for must have been requested using vrna_ostream_request() beforehand.