15 #include "../clib/logfacility.h" 16 #include "../clib/strutil.h" 50 s = (
char*)calloc( 1, (
unsigned)
allocLen );
59 throw std::runtime_error(
"allocation failure in SymbolContainer::resize(" +
67 int nstarting =
usedLen - datalen + 1;
69 for (
int i = 1; i < nstarting; i++ )
71 if ( memcmp(
s + i, data, datalen ) == 0 )
82 int nChars =
static_cast<unsigned int>( strlen(
string ) + 1 );
94 std::memcpy(
s +
usedLen, &lvalue,
sizeof(
int ) );
102 std::memcpy(
s +
usedLen, &dvalue,
sizeof(
double ) );
112 memcpy(
s +
usedLen, data, datalen );
120 throw std::runtime_error(
"SymbolContainer::write failed" );
121 if ( fwrite(
s,
usedLen, 1, fp ) != 1 )
122 throw std::runtime_error(
"SymbolContainer::write failed" );
133 FILE* fp = fopen( fname,
"wb" );
135 throw std::runtime_error( std::string(
"Unable to open " ) + fname +
" for writing." );
143 if ( fread_res != 1 )
144 throw std::runtime_error(
"failed to read in SymbolContainer::read()." );
145 char* new_s = (
char*)realloc(
s,
usedLen );
147 throw std::runtime_error(
"allocation failure in SymbolContainer::read()." );
149 fread_res = fread(
s,
usedLen, 1, fp );
150 if ( fread_res != 1 )
151 throw std::runtime_error(
"failed to read in SymbolContainer::read()." );
163 FILE* fp = fopen( fname,
"rb" );
165 throw std::runtime_error( std::string(
"Unable to open " ) + fname +
" for reading." );
175 atPut1( sToken, position );
177 *pposition = position;
182 if ( position >= count() )
183 throw std::runtime_error(
"Assigning token at invalid position " +
Clib::decint( position ) +
193 if ( position >= count() )
194 throw std::runtime_error(
"Retrieving token at invalid position " +
Clib::decint( position ) +
223 : type( static_cast<unsigned char>( aType ) ),
224 id( static_cast<unsigned char>( aID ) ),
225 offset( static_cast<unsigned short>( aOffset ) ),
231 <<
"Flog the programmer for using 2-byte offsets in datafiles.\n";
232 throw std::runtime_error(
"Data segment overflowed" );
void append_tok(const StoredToken &token, unsigned *position=NULL)
bool findexisting(const void *data, int datalen, unsigned &position)
void atGet1(unsigned position, StoredToken &token) const
std::string decint(unsigned short v)
virtual ~SymbolContainer()
virtual void pack(void) POL_OVERRIDE
virtual void read(FILE *fp) POL_OVERRIDE
virtual void write(FILE *fp)
unsigned int get_write_length() const
virtual void * detach(void)
void append(const char *string, unsigned &position)
virtual void resize(unsigned lengthToAdd) POL_OVERRIDE
std::unordered_map< u64, ScriptDiffData > data
SymbolContainer(int growBy=512)
void atPut1(const StoredToken &token, unsigned position)
virtual void read(FILE *fp)
virtual void resize(unsigned lengthToAdd)
virtual void * detach(void) POL_OVERRIDE
StoredToken(unsigned char aModule=0, int aID=CTRL_STATEMENTBEGIN, BTokenType aType=TYP_CONTROL, unsigned aOffset=0 )