\ Preprocessor String Class - Copyright 2022 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

[UNDEFINED] DStr    [IF]
[UNDEFINED] ds.init [IF] include lib/dstringt.4th [THEN]

:class DStr                            \ OO wrapper for DSTRINGT.4TH
  extends Object
    field: (dstr)                      \ actual dynamic string
    method: get$                       \ get a string
    method: set$                       \ set a string
    method: add$                       \ add string to the current one
    method: print$                     \ print a string
  end-extends
                                       \ note "len = 0" is a valid string!
  :new                                 ( Nothing | a n -- obj)
    this -> (dstr) ds.init dup 0< if drop else this -> (dstr) ds.place then
  ;method
                                       ( a n obj --)
  :delete this -> (dstr) ds.free       ;method
  :method set$ this -> (dstr) ds.place ;method
  :method add$ this -> (dstr) ds+place ;method  
  :method get$ this -> (dstr) ds.count ;method
  :method print$ this -> get$ type     ;method
                                       ( obj -- a n)
  private{ (dstr) }                    \ that's encapsulation for you
;class
[THEN]

