Numworks Epsilon  1.4.1
Graphing Calculator Operating System
script.cpp
Go to the documentation of this file.
1 #include "script.h"
2 
3 namespace Code {
4 
5 Script::Script(Record f) :
6  Record(f)
7 {
8 }
9 
11  assert(!isNull());
12  Data d = value();
13  return (((char *)d.buffer)[0] == 1);
14 }
15 
17  Data d = value();
18  ((char *)d.buffer)[0] = (((char *)d.buffer)[0] == 1 ? 0 : 1);
19  setValue(d);
20 }
21 
22 const char * Script::readContent() const {
23  assert(!isNull());
24  Data d = value();
25  return (const char *)d.buffer+k_importationStatusSize;
26 }
27 
29  // TODO: could we avoid this useless allocation?
30  char * buffer = new char[size+k_importationStatusSize];
31  strlcpy(buffer+1, data, size);
32  buffer[0] = importationStatus() ? 1 : 0;
33  ErrorStatus e = setValue({.buffer= buffer, .size = size+k_importationStatusSize});
34  delete[] buffer;
35  return e;
36 }
37 
38 }
#define assert(e)
Definition: assert.h:9
def data
Definition: i18n.py:176
bool isNull() const
Definition: storage.h:38
size_t strlcpy(char *dst, const char *src, size_t len)
Definition: strlcpy.c:3
const char * readContent() const
Definition: script.cpp:22
const void * buffer
Definition: storage.h:31
Definition: app.cpp:7
Data value() const
Definition: storage.h:47
void toggleImportationStatus()
Definition: script.cpp:16
bool importationStatus() const
Definition: script.cpp:10
Script(Ion::Storage::Record r)
Definition: script.cpp:5
ErrorStatus setValue(Data data)
Definition: storage.h:50
ErrorStatus writeContent(const char *data, size_t size)
Definition: script.cpp:28
static constexpr size_t k_importationStatusSize
Definition: script.h:21