1 #ifndef _PROJECTCONTEXT_H_
2 #define _PROJECTCONTEXT_H_
10 #ifndef _REAPER_PLUGIN_PROJECTSTATECONTEXT_DEFINED_
11 #define _WDL_PROJECTSTATECONTEXT_DEFINED_
13 class ProjectStateContext
// this is also defined in reaper_plugin.h (keep them identical, thx)
16 virtual ~ProjectStateContext(){};
18 virtual void WDL_VARARG_WARN(printf
,2,3) AddLine(const char *fmt
, ...) = 0;
19 virtual int GetLine(char *buf
, int buflen
)=0; // returns -1 on eof
21 virtual WDL_INT64
GetOutputSize()=0;
23 virtual int GetTempFlag()=0;
24 virtual void SetTempFlag(int flag
)=0;
29 ProjectStateContext
*ProjectCreateFileRead(const char *fn
);
30 ProjectStateContext
*ProjectCreateFileWrite(const char *fn
);
31 ProjectStateContext
*ProjectCreateMemCtx(WDL_HeapBuf
*hb
); // read or write (ugh, deprecated), be sure to delete it before accessing hb
32 ProjectStateContext
*ProjectCreateMemCtx_Read(const WDL_HeapBuf
*hb
); // read only
33 ProjectStateContext
*ProjectCreateMemCtx_Write(WDL_HeapBuf
*hb
); // write only, be sure to delete it before accessing hb
34 ProjectStateContext
*ProjectCreateMemWriteFastQueue(WDL_FastQueue
*fq
); // only write! no need to do anything at all before accessing (can clear/reuse as necessary)
39 bool ProjectContext_EatCurrentBlock(ProjectStateContext
*ctx
,
40 ProjectStateContext
*ctxOut
=NULL
); // returns TRUE if got valid >, otherwise it means eof...
41 // writes to ctxOut if specified, will not write final >
43 bool ProjectContext_GetNextLine(ProjectStateContext
*ctx
, LineParser
*lpOut
); // true if lpOut is valid
45 char *projectcontext_fastDoubleToString(double value
, char *bufOut
, int prec_digits
); // returns pointer to end of encoded string. prec_digits 0..18.
46 int ProjectContextFormatString(char *outbuf
, size_t outbuf_size
, const char *fmt
, va_list va
); // returns bytes used
48 int cfg_decode_binary(ProjectStateContext
*ctx
, WDL_HeapBuf
*hb
); // 0 on success, doesnt clear hb
49 void cfg_encode_binary(ProjectStateContext
*ctx
, const void *ptr
, int len
);
51 int cfg_decode_textblock(ProjectStateContext
*ctx
, WDL_FastString
*str
); // 0 on success, appends to str
52 void cfg_encode_textblock(ProjectStateContext
*ctx
, const char *text
); // long lines get split by newlines
53 void cfg_encode_textblock2(ProjectStateContext
*ctx
, const char *text
); // preserves newlines/long lines/etc (requires recent cfg_decode_textblock())
55 char getConfigStringQuoteChar(const char *in
, bool prefer_quoteless
=true); // returns 0 if no quote char available!
56 bool configStringWantsBlockEncoding(const char *in
); // returns true if over 1k long, has newlines, or contains all quote chars
57 void makeEscapedConfigString(const char *in
, WDL_FastString
*out
);
60 class ProjectStateContext_GenericRead
: public ProjectStateContext
68 ProjectStateContext_GenericRead(const void *buf
, int sz
) : m_tmpflag(0)
70 m_ptr
= (const char *)buf
;
71 m_endptr
= m_ptr
? m_ptr
+sz
: NULL
;
73 virtual ~ProjectStateContext_GenericRead() {}
75 virtual void WDL_VARARG_WARN(printf
,2,3) AddLine(const char *fmt
, ...) { }
76 virtual int GetLine(char *buf
, int buflen
) // returns -1 on eof
78 const char *p
= m_ptr
;
79 const char *ep
= m_endptr
;
81 while (p
< ep
&& (!*p
|| *p
== '\t' || *p
== '\r' || *p
== '\n' || *p
== ' ')) p
++;
90 while (--buflen
> 0 && *p
) *buf
++ = *p
++;
95 m_ptr
=p
+1; // skip NUL
99 virtual int GetTempFlag() { return m_tmpflag
; }
100 virtual void SetTempFlag(int flag
) { m_tmpflag
=flag
; }
101 virtual WDL_INT64
GetOutputSize() { return 0; }
105 #endif//_PROJECTCONTEXT_H_