Loading...
Searching...
No Matches
lintree.h
Go to the documentation of this file.
#ifndef _singthread_lintree_h
#define _singthread_lintree_h
#include <string>
#include <vector>
#include <cstring>
#include <Singular/ipid.h>
namespace LinTree {
class LinTree;
typedef void (*LinTreeEncodeFunc)(LinTree &lintree, leftv val);
typedef leftv (*LinTreeDecodeFunc)(LinTree &lintree);
typedef void (*LinTreeRefFunc)(LinTree &lintree, int by);
extern std::vector<LinTreeEncodeFunc> encoders;
extern std::vector<LinTreeDecodeFunc> decoders;
extern std::vector<LinTreeRefFunc> refupdaters;
void install(int typ, LinTreeEncodeFunc enc, LinTreeDecodeFunc dec,
LinTreeRefFunc ref);
class LinTree {
private:
std::string &memory;
size_t cursor;
const char * error;
void *last_ring;
public:
LinTree();
LinTree(const LinTree &other);
~LinTree();
LinTree(std::string &source);
LinTree& operator=(const LinTree &other);
void rewind() { cursor = 0; }
void clear() { memory.clear(); cursor = 0; error = NULL; last_ring = NULL; }
void mark_error(const char *s) {
error = s;
}
int has_error() {
return error != NULL;
}
const char *error_msg() {
return error;
}
template<typename T>
T get() {
T result;
memcpy(&result, memory.c_str() + cursor, sizeof(T));
cursor += sizeof(T);
return result;
}
template<typename T>
T get_prev() {
T result;
memcpy(&result, memory.c_str() + cursor - sizeof(T), sizeof(T));
return result;
}
template<typename T>
void put(T data) {
memory.append((const char *) &data, sizeof(T));
}
template<typename T>
void skip() {
cursor += sizeof(T);
}
int get_int() {
return get<int>();
}
size_t get_size() {
return get<size_t>();
}
void put_int(int code) {
put(code);
}
void skip_int() {
skip<int>();
}
const char *get_bytes(size_t n) {
const char *result = memory.c_str() + cursor;
cursor += n;
return result;
}
const char *get_addr() {
return memory.c_str() + cursor;
}
void put_bytes(char *p, size_t n) {
memory.append(p, n);
}
char *reserve_bytes(size_t n) {
size_t pos = memory.size();
memory.reserve(n);
for (size_t i = 0; i < n; i++) {
memory += '\0';
}
return (char *)(memory.c_str() + pos);
}
void put_cstring(char *p) {
size_t n = strlen(p);
put(n);
put_bytes(p, n+1);
}
const char *get_cstring() {
size_t n = get_size();
const char *result = memory.c_str() + cursor;
cursor += n + 1;
return result;
}
void skip_cstring() {
size_t n = get_size();
cursor += n + 1;
}
void skip_bytes(size_t n) {
cursor += n;
}
std::string &to_string() {
return memory;
}
void set_last_ring(void *r);
int has_last_ring() {
return last_ring != NULL;
}
void *get_last_ring() {
return last_ring;
}
};
std::string to_string(leftv val);
leftv from_string(std::string &str);
void init();
};
#endif
i
int i
Definition cfEzgcd.cc:132
p
int p
Definition cfModGcd.cc:4086
LinTree::LinTree
Definition lintree.h:24
LinTree::LinTree::last_ring
void * last_ring
Definition lintree.h:29
LinTree::LinTree::error
const char * error
Definition lintree.h:28
LinTree::LinTree::get
T get()
Definition lintree.h:48
LinTree::LinTree::put_bytes
void put_bytes(char *p, size_t n)
Definition lintree.h:88
LinTree::LinTree::get_int
int get_int()
Definition lintree.h:68
LinTree::LinTree::to_string
std::string & to_string()
Definition lintree.h:117
LinTree::LinTree::skip_int
void skip_int()
Definition lintree.h:77
LinTree::LinTree::skip_bytes
void skip_bytes(size_t n)
Definition lintree.h:114
LinTree::LinTree::skip
void skip()
Definition lintree.h:65
LinTree::LinTree::rewind
void rewind()
Definition lintree.h:36
LinTree::LinTree::put_cstring
void put_cstring(char *p)
Definition lintree.h:99
LinTree::LinTree::get_last_ring
void * get_last_ring()
Definition lintree.h:124
LinTree::LinTree::clear
void clear()
Definition lintree.h:37
LinTree::LinTree::get_size
size_t get_size()
Definition lintree.h:71
LinTree::LinTree::reserve_bytes
char * reserve_bytes(size_t n)
Definition lintree.h:91
LinTree::LinTree::put
void put(T data)
Definition lintree.h:61
LinTree::LinTree::get_prev
T get_prev()
Definition lintree.h:55
LinTree::LinTree::operator=
LinTree & operator=(const LinTree &other)
Definition lintree.cc:888
LinTree::LinTree::get_bytes
const char * get_bytes(size_t n)
Definition lintree.h:80
LinTree::LinTree::put_int
void put_int(int code)
Definition lintree.h:74
LinTree::LinTree::has_last_ring
int has_last_ring()
Definition lintree.h:121
LinTree::LinTree::memory
std::string & memory
Definition lintree.h:26
LinTree::LinTree::mark_error
void mark_error(const char *s)
Definition lintree.h:38
LinTree::LinTree::get_cstring
const char * get_cstring()
Definition lintree.h:104
LinTree::LinTree::has_error
int has_error()
Definition lintree.h:41
LinTree::LinTree::cursor
size_t cursor
Definition lintree.h:27
LinTree::LinTree::get_addr
const char * get_addr()
Definition lintree.h:85
LinTree::LinTree::error_msg
const char * error_msg()
Definition lintree.h:44
LinTree::LinTree::skip_cstring
void skip_cstring()
Definition lintree.h:110
result
return result
Definition facAbsBiFact.cc:76
s
const CanonicalForm int s
Definition facAbsFact.cc:51
ipid.h
T
STATIC_VAR jList * T
Definition janet.cc:30
LinTree
Definition lintree.cc:42
LinTree::init
void init()
Definition lintree.cc:864
LinTree::decoders
vector< LinTreeDecodeFunc > decoders
Definition lintree.cc:47
LinTree::LinTreeRefFunc
void(* LinTreeRefFunc)(LinTree &lintree, int by)
Definition lintree.h:15
LinTree::to_string
std::string to_string(leftv val)
Definition lintree.cc:843
LinTree::LinTreeDecodeFunc
leftv(* LinTreeDecodeFunc)(LinTree &lintree)
Definition lintree.h:14
LinTree::refupdaters
vector< LinTreeRefFunc > refupdaters
Definition lintree.cc:48
LinTree::encoders
vector< LinTreeEncodeFunc > encoders
Definition lintree.cc:46
LinTree::install
void install(int typ, LinTreeEncodeFunc enc, LinTreeDecodeFunc dec, LinTreeRefFunc ref)
Definition lintree.cc:51
LinTree::from_string
leftv from_string(std::string &str)
Definition lintree.cc:854
LinTree::LinTreeEncodeFunc
void(* LinTreeEncodeFunc)(LinTree &lintree, leftv val)
Definition lintree.h:13
NULL
#define NULL
Definition omList.c:12
leftv
sleftv * leftv
Definition structs.h:53