Permalink
Browse files

Added some accessors; builds static lib as well

  • Loading branch information...
1 parent d154c89 commit 172e4df43dde4c90718e9195bf137d2b7f120260 @codehero committed Jun 15, 2010
Showing with 43 additions and 18 deletions.
  1. +2 −1 SConstruct
  2. +4 −3 benejson/SConscript
  3. +21 −13 benejson/pull.cpp
  4. +16 −1 benejson/pull.hh
View
@@ -10,7 +10,8 @@ mydir = os.getcwd()
#Set default C++ building flags for both libraries and executables
default_env = Environment(ENV = os.environ)
default_env.Append(CPPPATH = [mydir + '/include'])
-default_env.Append(CCFLAGS = ' -Wall -pedantic -std=c99')
+default_env.Append(CCFLAGS = ' -Wall -pedantic')
+default_env.Append(CFLAGS = ' -Wall -pedantic -std=c99')
#default_env.Append(CCFLAGS = ' -O2 -fomit-frame-pointer')
default_env.Append(CCFLAGS = ' -O0 -g')
View
@@ -5,6 +5,7 @@ Import('*')
lib_env = lib_env.Clone()
-lt = lib_env.SharedLibrary('benejson', Split('benejson.c pull.cpp'))
-li = lib_env.Install(bin_env.LibDest, lt)
-lh = lib_env.Install(lib_env.IncDest + "/benejson", Split('benejson.h pull.hh'))
+lstatic = lib_env.StaticLibrary('benejson', Split('benejson.c pull.cpp memreader.cpp'))
+lt = lib_env.SharedLibrary('benejson', Split('benejson.c pull.cpp memreader.cpp'))
+lib_env.Install(bin_env.LibDest, [lt, lstatic])
+lib_env.Install(lib_env.IncDest + "/benejson", Split('benejson.h pull.hh memreader.hh'))
View
@@ -99,22 +99,30 @@ BNJ::PullParser::input_error::input_error(const char* blurb,
BNJ::PullParser::invalid_value::invalid_value(const char* blurb,
const PullParser& p)
{
- const bnj_val& val = p.GetValue();
+ if(p.ValidValue()){
+ const bnj_val& val = p.GetValue();
- /* Reserve 1 char in buff for '\0', and 1 for ' ' */
- char* x = s_compose_9(_msg, p.FileOffset(val));
+ /* Reserve 1 char in buff for '\0', and 1 for ' ' */
+ char* x = s_compose_9(_msg, p.FileOffset(val));
- /* Copy key value if necessary. */
- if(val.key_length){
- x = stpcpy(x, "Key: ");
- x = bnj_stpnkeycpy(x, 254 - (x - _msg), &val, p.Buff());
- *x = ' ';
- ++x;
- }
+ /* Copy key value if necessary. */
+ if(val.key_length){
+ x = stpcpy(x, "Key: ");
+ x = bnj_stpnkeycpy(x, 254 - (x - _msg), &val, p.Buff());
+ *x = ' ';
+ ++x;
+ }
- /* Copy as many bytes of blurb as possible. */
- x = stpncpy(x, blurb, 254 - (x - _msg));
- *x = '\0';
+ /* Copy as many bytes of blurb as possible. */
+ x = stpncpy(x, blurb, 254 - (x - _msg));
+ *x = '\0';
+ }
+ else {
+ /* FIXME taking a guess here as to the offset. */
+ char* x = s_compose_9(_msg, p.TotalParsed());
+ x = stpncpy(x, blurb, 254 - (x - _msg));
+ *x = '\0';
+ }
}
/* Only initialize the read state here to NULL values. */
View
@@ -156,6 +156,10 @@ namespace BNJ {
* @throw When parser state is not ST_DATUM */
const bnj_val& GetValue(void) const;
+ /** @brief Whether there is a value available to GetValue()
+ * (descending states do not have valid values available) */
+ bool ValidValue(void) const;
+
/** @brief Retrieve current parser state.
* @return After Begin() and before first Pull() call, returns ST_BEGIN.
* Otherwise, identical to return value from Pull() */
@@ -189,6 +193,9 @@ namespace BNJ {
/** @brief Indicate at what file offset value begins. */
unsigned FileOffset(const bnj_val& v) const throw();
+ /** @brief Total bytes parsed. */
+ unsigned TotalParsed() const;
+
private:
/** @brief Private default ctor to prevent inheritance. */
@@ -302,11 +309,15 @@ inline const char* BNJ::PullParser::invalid_value::what(void) const throw(){
}
inline const bnj_val& BNJ::PullParser::GetValue(void) const{
- if(_val_idx >= _val_len)
+ if(!ValidValue())
throw input_error("No valid parser value!", _total_pulled);
return _valbuff[_val_idx];
}
+inline bool BNJ::PullParser::ValidValue(void) const{
+ return _val_idx < _val_len;
+}
+
inline BNJ::PullParser::State BNJ::PullParser::GetState(void) const{
return _parser_state;
}
@@ -335,4 +346,8 @@ inline unsigned BNJ::PullParser::BuffLen(void) const{
return _len;
}
+inline unsigned BNJ::PullParser::TotalParsed() const{
+ return _total_parsed;
+}
+
#endif

0 comments on commit 172e4df

Please sign in to comment.