Blame view

Modif/epsilon-master/apps/code/script.cpp 889 Bytes
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #include "script.h"
  
  namespace Code {
  
  Script::Script(Record f) :
    Record(f)
  {
  }
  
  bool Script::importationStatus() const {
    assert(!isNull());
    Data d = value();
    return (((char *)d.buffer)[0] == 1);
  }
  
  void Script::toggleImportationStatus() {
    Data d = value();
    ((char *)d.buffer)[0] = (((char *)d.buffer)[0] == 1 ? 0 : 1);
    setValue(d);
  }
  
  const char * Script::readContent() const {
    assert(!isNull());
    Data d = value();
    return (const char *)d.buffer+k_importationStatusSize;
  }
  
  Ion::Storage::Record::ErrorStatus Script::writeContent(const char * data, size_t size) {
    // TODO: could we avoid this useless allocation?
    char * buffer = new char[size+k_importationStatusSize];
    strlcpy(buffer+1, data, size);
    buffer[0] = importationStatus() ? 1 : 0;
    ErrorStatus e = setValue({.buffer= buffer, .size = size+k_importationStatusSize});
    delete[] buffer;
    return e;
  }
  
  }