set base sdk to 10.9
[wdl/wdl-ol.git] / WDL / projectcontext.h
blobfdc0ca4525f330d86eb60653e1efbbd357394640
1 #ifndef _PROJECTCONTEXT_H_
2 #define _PROJECTCONTEXT_H_
4 #include "wdltypes.h"
6 class WDL_String;
7 class WDL_FastString;
8 class WDL_HeapBuf;
9 class WDL_FastQueue;
11 #ifndef _REAPER_PLUGIN_PROJECTSTATECONTEXT_DEFINED_
12 #define _WDL_PROJECTSTATECONTEXT_DEFINED_
14 class ProjectStateContext // this is also defined in reaper_plugin.h (keep them identical, thx)
16 public:
17 virtual ~ProjectStateContext(){};
19 virtual void WDL_VARARG_WARN(printf,2,3) AddLine(const char *fmt, ...) = 0;
20 virtual int GetLine(char *buf, int buflen)=0; // returns -1 on eof
22 virtual WDL_INT64 GetOutputSize()=0;
24 virtual int GetTempFlag()=0;
25 virtual void SetTempFlag(int flag)=0;
28 #endif
30 ProjectStateContext *ProjectCreateFileRead(const char *fn);
31 ProjectStateContext *ProjectCreateFileWrite(const char *fn);
32 ProjectStateContext *ProjectCreateMemCtx(WDL_HeapBuf *hb); // read or write (ugh, deprecated), be sure to delete it before accessing hb
33 ProjectStateContext *ProjectCreateMemCtx_Read(const WDL_HeapBuf *hb); // read only
34 ProjectStateContext *ProjectCreateMemCtx_Write(WDL_HeapBuf *hb); // write only, be sure to delete it before accessing hb
35 ProjectStateContext *ProjectCreateMemWriteFastQueue(WDL_FastQueue *fq); // only write! no need to do anything at all before accessing (can clear/reuse as necessary)
38 // helper functions
39 class LineParser;
40 bool ProjectContext_EatCurrentBlock(ProjectStateContext *ctx,
41 ProjectStateContext *ctxOut=NULL); // returns TRUE if got valid >, otherwise it means eof...
42 // writes to ctxOut if specified, will not write final >
44 bool ProjectContext_GetNextLine(ProjectStateContext *ctx, LineParser *lpOut); // true if lpOut is valid
46 char *projectcontext_fastDoubleToString(double value, char *bufOut, int prec_digits); // returns pointer to end of encoded string. prec_digits 0..18.
47 int ProjectContextFormatString(char *outbuf, size_t outbuf_size, const char *fmt, va_list va); // returns bytes used
49 int cfg_decode_binary(ProjectStateContext *ctx, WDL_HeapBuf *hb); // 0 on success, doesnt clear hb
50 void cfg_encode_binary(ProjectStateContext *ctx, const void *ptr, int len);
52 int cfg_decode_textblock(ProjectStateContext *ctx, WDL_String *str); // 0 on success, appends to str
53 int cfg_decode_textblock(ProjectStateContext *ctx, WDL_FastString *str); // 0 on success, appends to str
54 void cfg_encode_textblock(ProjectStateContext *ctx, const char *text);
56 char getConfigStringQuoteChar(const char *in); // returns 0 if no quote char available!
57 void makeEscapedConfigString(const char *in, WDL_String *out);
58 void makeEscapedConfigString(const char *in, WDL_FastString *out);
61 class ProjectStateContext_GenericRead : public ProjectStateContext
63 const char *m_ptr;
64 const char *m_endptr;
65 int m_tmpflag;
67 public:
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++;
82 if (p >= ep)
84 m_ptr=p;
85 return -1;
88 if (buflen > 0)
90 while (--buflen > 0 && *p) *buf++ = *p++;
91 *buf=0;
94 while (*p) p++;
95 m_ptr=p+1; // skip NUL
97 return 0;
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_