Exemple #1
0
void VirtualValue::setTo(const Variant& value, StringCache& stringcache)
{
   if ( value.isInt() )
   {
      setNumber(value.asInt());
   }
   else if ( value.isReal() )
   {
      setReal(value.asReal());
   }
   else if ( value.isBool() )
   {
      setBoolean(value.asBool());
   }
   else if ( value.isChar() )
   {
      setChar(value.asChar());
   }
   else if ( value.isString() )
   {
      setString(stringcache.lookup(value.asString()));
   }
   else
   {
      mKind = eEmpty;
   }
}
Exemple #2
0
	void Object::setNativeType(DataType type)
	{
		switch (type)
		{
		default:
			throw ObjectConversionException(FORMAT("Unknown DataType %u", this->getNativeType()));

		case NIL:
			setNil();
			break;

		case BOOLEAN:
			setBoolean(getBoolean());
			break;

		case NUMBER:
			setNumber(getNumber());
			break;

		case ADDRESS:
			setAddress(getAddress());
			break;

		case STRING:
			setString(getString());
			break;

		case USERDATA:
			throw ObjectTypeException("Cannot set native type to USERDATA");
		}
	}
Exemple #3
0
bool Settings::boolean(QString key, bool default_value)
{
  bool value = valueWithFallback(key, default_value).toBool();
  if (value==default_value)
  {
    setBoolean(key, default_value);
  }
  return value;
}
fmiStatus fmiSetBoolean(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiBoolean value[])
{
  unsigned int i=0;
  ModelInstance* comp = (ModelInstance *)c;
  if (invalidState(comp, "fmiSetBoolean", modelInstantiated|modelInitialized))
    return fmiError;
  if (nvr>0 && nullPointer(comp, "fmiSetBoolean", "vr[]", vr))
    return fmiError;
  if (nvr>0 && nullPointer(comp, "fmiSetBoolean", "value[]", value))
    return fmiError;
  if (comp->loggingOn)
    comp->functions.logger(c, comp->instanceName, fmiOK, "log", "fmiSetBoolean: nvr = %d",  nvr);
  for (i=0; i<nvr; i++) {
    if (vrOutOfRange(comp, "fmiSetBoolean", vr[i], NUMBER_OF_BOOLEANS))
      return fmiError;
    if (comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log",
        "fmiSetBoolean: #b%d# = %s", vr[i], value[i] ? "true" : "false");
    if (setBoolean(comp, vr[i],value[i]) != fmiOK) // to be implemented by the includer of this file
      return fmiError;
  }

  return fmiOK;
}
/**
 * \brief Setter function for booleans.
 *
 * Used by OMSIC or OMSICpp library.
 *
 * \param [in,out]  omsu    Central data structure containing all informations.
 * \param [in]      vr      Array of value references for boolean variables to set.
 * \param [in]      nvr     Length of array `vr`.
 * \param [in]      value   Contains booleans to be set.
 * \return                  `omsi_status omsi_ok` if successful <br>
 *                          `omsi_status omsi_error` if something went wrong.
 */
omsi_status omsi_set_boolean(omsi_t*                    omsu,
                             const omsi_unsigned_int*   vr,
                             omsi_unsigned_int          nvr,
                             const omsi_bool*           value) {

    /* Variables */
    omsi_unsigned_int i;

    if (!model_variables_allocated(omsu, "fmi2SetBoolean"))
        return omsi_error;

    if (nvr>0 && vr==NULL) {
        filtered_base_logger(global_logCategories, log_statuserror, omsi_error,
                "fmi2SetBoolean: Invalid argument vr[] = NULL.");
        return omsi_error;
    }
    if (nvr>0 && value==NULL) {
        filtered_base_logger(global_logCategories, log_statuserror, omsi_error,
                "fmi2SetBoolean: Invalid argument value[] = NULL.");
        return omsi_error;
    }

    filtered_base_logger(global_logCategories, log_all, omsi_ok,
        "fmi2SetBoolean: nvr = %d", nvr);

    for (i = 0; i < nvr; i++) {
        if (omsi_vr_out_of_range(omsu, "fmi2SetBoolean", vr[i], omsu->sim_data->model_vars_and_params->n_bools))
            return omsi_error;
        filtered_base_logger(global_logCategories, log_all, omsi_ok,
            "fmi2SetBoolean: #b%d# = %s", vr[i], value[i] ? "true" : "false");

        setBoolean(omsu, vr[i], value[i]);
    }

    return omsi_ok;
}
void CC3GLSLUniform::setBoolean( bool value )
{ 
	setBoolean( value, 0 ); 
}
Exemple #7
0
void PvObject::setBoolean(bool value)
{
    std::string key = PyPvDataUtility::getValueOrSingleFieldName(pvStructurePtr);
    setBoolean(key, value);
}
Exemple #8
0
Variant::Variant(bool boolean)
{
	setBoolean( boolean );
}
Item::e_sercode Item::deserialize( Stream *file, VMachine *vm )
{
   byte type = FLC_ITEM_NIL;
   if ( file->read((byte *) &type, 1 ) == 0 )
      return sc_eof;

   if( ! file->good() )
      return sc_ferror;

   switch( type )
   {
      case FLC_ITEM_NIL:
         setNil();
      return sc_ok;

      case FLC_ITEM_UNB:
         setUnbound();
         return sc_ok;

      case FLC_ITEM_BOOL:
      {
         byte bval;
         file->read( (byte *) &bval, sizeof( bval ) );
         if ( file->good() ) {
            setBoolean( bval != 0 );
            return sc_ok;
         }
         return sc_ferror;
      }
      return sc_ok;

      case FLC_ITEM_INT:
      {
         int64 val;
         file->read( (byte *) &val, sizeof( val ) );
         if ( file->good() ) {
            setInteger(endianInt64(val) );
            return sc_ok;
         }
         return sc_ferror;
      }
      break;

      case FLC_ITEM_RANGE:
      {
         int64 val1;
         int64 val2;
         int64 val3;
         //byte isOpen;

         file->read( (byte *) &val1, sizeof( val1 ) );
         file->read( (byte *) &val2, sizeof( val2 ) );
         file->read( (byte *) &val3, sizeof( val3 ) );
         //file->read( (byte *) &isOpen, sizeof( isOpen ) );

         val1 = endianInt64( val1 );
         val2 = endianInt64( val2 );
         val3 = endianInt64( val3 );

         if ( file->good() ) {
            setRange( new CoreRange( val1, val2, val3 ) );
            return sc_ok;
         }
         return sc_ferror;
      }
      break;

      case FLC_ITEM_NUM:
      {
         numeric val;
         file->read( (byte *) &val, sizeof( val ) );
         if ( file->good() ) {
            setNumeric( endianNum( val ) );
            return sc_ok;
         }
         return sc_ferror;
      }
      break;

      case FLC_ITEM_LBIND:
      {
         int32 id;
         file->read( (byte*) &id, sizeof(id) );
         String name;
         if ( ! name.deserialize( file ) )
            return file->bad() ? sc_ferror : sc_invformat;

         setLBind( new CoreString( name ) );
      }
      break;

      case FLC_ITEM_STRING:
      {
         CoreString *cs = new CoreString;
         setString( cs );

         if ( ! cs->deserialize( file ) )
         {
            return file->bad() ? sc_ferror : sc_invformat;
         }

         if ( file->good() ) {
            return sc_ok;
         }

         return sc_ferror;
      }
      break;

      case FLC_ITEM_MEMBUF |0x80:
      {
         // get the function pointer in the stream
         /*MemBuf *(*deserializer)( VMachine *, Stream * );
         file->read( &deserializer, sizeof( deserializer ) );
         if ( ! file->good() ) {
            return sc_ferror;
         }

         MemBuf *mb = deserializer( vm, file );
         if( mb == 0 )
         {
            return sc_invformat;
         }*/

         MemBuf* mb;
         if( file->read( &mb, sizeof( mb ) ) == sizeof(mb) )
         {
            setMemBuf( mb );
            return sc_ok;
         }
         return sc_eof;
      }

      case FLC_ITEM_MEMBUF:
      {
         MemBuf *mb = MemBuf::deserialize( vm, file );
         if ( file->good() && mb != 0 ) {
            setMemBuf( mb );
            return sc_ok;
         }

         return sc_ferror;
      }
      break;


      case FLC_ITEM_ARRAY:
      {
         int32 val;
         file->read( (byte *) &val, sizeof( val ) );
         e_sercode retval = sc_ok;

         if ( file->good() )
         {
            val = endianInt32(val);
            CoreArray *array = new CoreArray();
            array->resize(val);

            for( int i = 0; i < val; i ++ )
            {
               retval = array->items()[i].deserialize( file, vm );
               if( retval != sc_ok ) {
                  break;
               }

            }

            if ( retval == sc_ok ) {
               setArray( array );
               return sc_ok;
            }

            return retval;
         }
      }
      break;

      case FLC_ITEM_DICT:
      {
         byte blessed;
         file->read( &blessed, 1 );

         int32 val;
         file->read( (byte *) &val, sizeof( val ) );

         if ( file->good() )
         {
            val = endianInt32(val);
            LinearDict *dict = new LinearDict( val );
            LinearDictEntry *elems = dict->entries();
            e_sercode retval = sc_ok;
            for( int i = 0; i < val; i ++ ) {
               LinearDictEntry *entry = elems + i;
               retval = entry->key().deserialize( file, vm );
               if( retval == sc_ok )
                    retval = entry->value().deserialize( file, vm );

               if ( retval != sc_ok )
                  break;
               dict->length( i + 1 );
            }

            if( retval == sc_ok ) {
               CoreDict* cdict = new CoreDict( dict );
               cdict->bless( blessed ? true : false );
               setDict( cdict );

               return sc_ok;
            }
            else
               delete dict;

            return retval;
         }
      }
      break;

      case FLC_ITEM_FUNC | 0x80:
      case FLC_ITEM_FUNC:
      {
         if( vm == 0 )
            return sc_missvm;

         return deserialize_function( file, vm );
      }
     break;

      case FLC_ITEM_METHOD:
      {
         if( vm == 0 )
            return sc_missvm;

         Item obj;
         Item func;
         e_sercode sc;
         sc = obj.deserialize( file, vm );
         if ( sc != sc_ok )
            return sc;

         sc = func.deserialize( file, vm );
         if ( sc != sc_ok )
            return sc;
         if ( func.isFunction() )
            setMethod( obj, func.asMethodFunc() );
         else if ( func.isArray() && func.isCallable() )
         {
            setMethod( obj, func.asArray() );
         }
         else
            return sc_invformat;

         return sc_ok;
      }


      case FLC_ITEM_OBJECT | 0x80:
      case FLC_ITEM_OBJECT:
      {
         bool bLive = type != FLC_ITEM_OBJECT;

         if( vm == 0 )
            return sc_missvm;

         // read the module name
         Symbol *sym;
         LiveModule *lmod;
         e_sercode sc = deserialize_symbol( file, vm, &sym, &lmod );
         if ( sc != sc_ok  )
            return sc;

         Item *clitem = &lmod->globals()[ sym->itemId() ];

         // Create the core object, but don't fill attribs.
         CoreObject *object = clitem->dereference()->asClass()->createInstance(0, true);
         if ( ! object->deserialize( file, bLive ) )
         {
            return sc_missclass;
         }

         setObject( object );
         return file->good() ? sc_ok : sc_ferror;
      }
      break;

      case FLC_ITEM_CLASS:
         return deserialize_class( file, vm );


       case FLC_ITEM_CLSMETHOD:
       {
         e_sercode sc = deserialize_class( file, vm );
         if ( sc != sc_ok )
            return sc;
         return deserialize_function( file, vm );
      }
      break;

      default:
         return sc_invformat;
   }

   return sc_ferror;
}
Exemple #10
0
int main(int argc, const char *argv[]) {
    char from[MAX_GROUP_NAME];
    char message[MAX_MESSLEN];
    membership_info memb_info;
    int num_groups;
    char target_groups[100][MAX_GROUP_NAME];
    int16 mess_type;
    int endian_mismatch;

    int service_type;
    int loop = 1;
    int rc;
    int ret;
    int i;

    sqlite3 *mydb;
    char *dbName;
    char *zErrMsg;

    connectionStatus status = UNKNOWN;

    char buffer[MAX_GROUP_NAME];
    char sqlBuffer[1024];
    char *member;
    char *host;
    char *tok;
    char ch;
    extern char *optarg;

    char scratch[255];

    global.connected=0;
    global.Group=(char *)NULL;
    global.configFileName=(char *)NULL;
    global.locked = 0;
    global.rawClient =1;
    global.debug = 0;

#ifdef FICL
    global.appDir=(char *)NULL;
#endif

    char *group=(char *)NULL;

    setSymbol("BUILD",__DATE__,LOCK,LOCAL);
    setSymbol("CLIENT","raw",UNLOCK,GLOBAL);
    setSymbol("SPREAD_SERVER","4803",UNLOCK,GLOBAL);
    setSymbol("GROUP","global",UNLOCK,GLOBAL);
    setSymbol("USER","dbCache",LOCK,GLOBAL);
    setSymbol("DEBUG","false",UNLOCK,GLOBAL);
    setSymbol("MODE","local",UNLOCK,GLOBAL);
    setSymbol("START_FILE","./dbCache.rc",UNLOCK,GLOBAL);

    while((ch = getopt(argc, ( char **)argv,"dhc:")) != -1) {
        switch(ch) {
            case 'c':
                setSymbol("START_FILE", optarg,LOCK,GLOBAL);
                break;
            case 'd':
                global.debug=1;
                break;
            case 'h':
                usage();
                exit(0);
                break;
        }
    }

    loadFile(getSymbol("START_FILE"));

    if( global.debug ) {
        setBoolean("DEBUG",1);
    }

    global.debug = getBoolean("DEBUG");

    if(global.debug) {
        dumpGlobals();
        dumpSymbols();
    }

    dbName = getSymbol("DATABASE");

    connectToSpread();

    while(loop) {
        status = UNKNOWN;
        ret = SP_receive(global.Mbox, &service_type, from, 100,
                &num_groups, target_groups,
                &mess_type, &endian_mismatch, sizeof(message), message);

        if (Is_membership_mess (service_type)) {
            ret = SP_get_memb_info(message, service_type, &memb_info);

            if (Is_caused_join_mess(service_type)) {
                status=JOINED;
            } 
            if (Is_caused_leave_mess (service_type)) {
                status = LEFT;
            } 
            if (Is_caused_disconnect_mess (service_type)) {
                status = DISCONNECTED;
            } 
            if (Is_caused_network_mess (service_type)) {
                status = NETWORK;
            }

            rc = sqlite3_open(dbName, &mydb);
            for (i = 0; i < num_groups; i++) {

                if( global.debug) {
                    printf("\t%s\n",(char *) &target_groups[i][0]);
                }

                strcpy(buffer, &target_groups[i][1]);

                member=strtok(buffer,"#");
                host=strtok(NULL,"#");

                if( global.debug) {
                    printf("\t\tMember:%s\n", member);
                    printf("\t\tHost  :%s\n", host);
                }

                statusToText( status, scratch );

                if (JOINED == status ) {
                    sprintf( sqlBuffer,"insert or replace into status  ( member, host, grp, state ) values ( '%s','%s','%s','%s');", member, host,from,scratch);
                }
                if( global.debug) {
                    printf ("%s\n",sqlBuffer);
                }
                rc = sqlite3_exec(mydb, sqlBuffer, 0, 0, &zErrMsg);
            }
            strcpy(buffer, &memb_info.changed_member[1]);
            member=strtok(buffer,"#");
            host=strtok(NULL,"#");

            statusToText( status, scratch );
            sprintf( sqlBuffer, "update status set state='%s' where member = '%s' and host ='%s';",scratch, member,host);

            if( global.debug) {
                printf("CHANGE: %s %s\n",member,host);
                printf("CHANGE: %s\n", scratch);
                printf ("%s\n",sqlBuffer);
            }

            rc = sqlite3_exec(mydb, sqlBuffer, 0, 0, &zErrMsg);

            sqlite3_close(mydb);

        }

    }


    printf("============ After\n");
    dumpGlobals();

    printf("Sender %s\n",from);
    printf("Message >%s<\n",message);

    toSpread(from,"Message recieved\n");

    spreadJoin("TEST");

    sleep(2);

    spreadLeave("TEST");

    sleep(2);

    spreadDisconnect();
}
Exemple #11
0
void Configuration::readApplicationSettings(xml_node<> *app)
{
  xml_node<> *sess = singleChildElement(app, "session-management");

  if (sess) {
    xml_node<> *dedicated = singleChildElement(sess, "dedicated-process");
    xml_node<> *shared = singleChildElement(sess, "shared-process");
    std::string tracking = singleChildElementValue(sess, "tracking", "");

    if (dedicated && shared)
      throw WServer::Exception("<application-settings> requires either "
			       "<dedicated-process> or <shared-process>, "
			       "not both");

    if (dedicated) {
      sessionPolicy_ = DedicatedProcess;
      setInt(dedicated, "max-num-sessions", maxNumSessions_);
    }

    if (shared) {
      sessionPolicy_ = SharedProcess;

      setInt(shared, "num-processes", numProcesses_);
    }

    if (!tracking.empty()) {
      if (tracking == "Auto")
	sessionTracking_ = CookiesURL;
      else if (tracking == "URL")
	sessionTracking_ = URL;
      else
	throw WServer::Exception("<session-tracking>: expecting 'Auto' "
				 "or 'URL'");
    }

    setInt(sess, "timeout", sessionTimeout_);
    setInt(sess, "bootstrap-timeout", bootstrapTimeout_);
    setInt(sess, "server-push-timeout", serverPushTimeout_);
    setBoolean(sess, "reload-is-new-session", reloadIsNewSession_);
  }

  std::string maxRequestStr
    = singleChildElementValue(app, "max-request-size", "");
  if (!maxRequestStr.empty())
    maxRequestSize_ = boost::lexical_cast< ::int64_t >(maxRequestStr) * 1024;

  std::string debugStr = singleChildElementValue(app, "debug", "");

  if (!debugStr.empty()) {
    if (debugStr == "stack")
      errorReporting_ = ErrorMessageWithStack;
    else if (debugStr == "true")
      errorReporting_ = NoErrors;
    else if (debugStr == "false")
      errorReporting_ = ErrorMessage;
    else
      throw WServer::Exception("<debug>: expecting 'true', 'false',"
			       "or 'stack'");
  }

  setInt(app, "num-threads", numThreads_);

  xml_node<> *fcgi = singleChildElement(app, "connector-fcgi");
  if (!fcgi)
    fcgi = app; // backward compatibility

  valgrindPath_ = singleChildElementValue(fcgi, "valgrind-path",
					  valgrindPath_);
  runDirectory_ = singleChildElementValue(fcgi, "run-directory",
					  runDirectory_);

  setInt(fcgi, "num-threads", numThreads_); // backward compatibility < 3.2.0

  xml_node<> *isapi = singleChildElement(app, "connector-isapi");
  if (!isapi)
    isapi = app; // backward compatibility

  setInt(isapi, "num-threads", numThreads_); // backward compatibility < 3.2.0

  std::string maxMemoryRequestSizeStr =
    singleChildElementValue(isapi, "max-memory-request-size", "");
  if (!maxMemoryRequestSizeStr.empty()) {
    isapiMaxMemoryRequestSize_ = boost::lexical_cast< ::int64_t >
      (maxMemoryRequestSizeStr) * 1024;
  }

  setInt(app, "session-id-length", sessionIdLength_);

  /*
   * If a session-id-prefix is defined in the configuration file, then
   * we loose the prefix defined by the connector (e.g. wthttpd), but who
   * would do such a thing ? */
  connectorSessionIdPrefix_
    = singleChildElementValue(app,"session-id-prefix",
			      connectorSessionIdPrefix_);

  setBoolean(app, "send-xhtml-mime-type", xhtmlMimeType_);
  if (xhtmlMimeType_)
    LOG_WARN("ignoring send-xhtml-mime-type setting: HTML5 is now always used");
  redirectMsg_ = singleChildElementValue(app, "redirect-message", redirectMsg_);

  setBoolean(app, "behind-reverse-proxy", behindReverseProxy_);
  setBoolean(app, "strict-event-serialization", serializedEvents_);
  setBoolean(app, "web-sockets", webSockets_);

  setBoolean(app, "inline-css", inlineCss_);
  setBoolean(app, "persistent-sessions", persistentSessions_);

  uaCompatible_ = singleChildElementValue(app, "UA-Compatible", "");

  setBoolean(app, "progressive-bootstrap", progressiveBoot_);
  if (progressiveBoot_)
    setBoolean(app, "split-script", splitScript_);
  setBoolean(app, "session-id-cookie", sessionIdCookie_);
  setBoolean(app, "cookie-checks", cookieChecks_);

  std::string plainAjaxSessionsRatioLimit
    = singleChildElementValue(app, "plain-ajax-sessions-ratio-limit", "");

  if (!plainAjaxSessionsRatioLimit.empty())
    maxPlainSessionsRatio_
      = boost::lexical_cast<float>(plainAjaxSessionsRatioLimit);

  setBoolean(app, "ajax-puzzle", ajaxPuzzle_);
  setInt(app, "indicator-timeout", indicatorTimeout_);
  setInt(app, "double-click-timeout", doubleClickTimeout_);

  std::vector<xml_node<> *> userAgents = childElements(app, "user-agents");

  for (unsigned i = 0; i < userAgents.size(); ++i) {
    xml_node<> *userAgentsList = userAgents[i];

    std::string type;
    if (!attributeValue(userAgentsList, "type", type))
      throw WServer::Exception("<user-agents> requires attribute 'type'");

    std::string mode;
    attributeValue(userAgentsList, "mode", mode);
    
    AgentList *list;
    if (type == "ajax") {
      list = &ajaxAgentList_;
      if (mode == "black-list")
	ajaxAgentWhiteList_ = false;
      else if (mode == "white-list")
	ajaxAgentWhiteList_ = true;
      else
	throw WServer::Exception
	  ("<user-agents type=\"ajax\" requires attribute 'mode' with value "
	   "\"white-list\" or \"black-list\"");
    } else if (type == "bot")
      list = &botList_;
    else
      throw WServer::Exception
	("<user-agents> requires attribute 'type' with value "
	 "\"ajax\" or \"bot\"");

    std::vector<xml_node<> *> agents
      = childElements(userAgentsList, "user-agent");

    for (unsigned j = 0; j < agents.size(); ++j)
      list->push_back(elementValue(agents[j], "user-agent"));
  }

  xml_node<> *properties = singleChildElement(app, "properties");

  if (properties) {
    std::vector<xml_node<> *> nodes = childElements(properties, "property");

    for (unsigned i = 0; i < nodes.size(); ++i) {
      xml_node<> *property = nodes[i];

      std::string name;
      if (!attributeValue(property, "name", name))
	throw WServer::Exception("<property> requires attribute 'name'");

      std::string value = elementValue(property, "property");

      if (name == "approot")
	name = "appRoot";

      if (name == "appRoot" && !appRoot_.empty())
	LOG_WARN("ignoring configuration property 'appRoot' ("
		 << value
		 << ") because was already set to " << appRoot_);
      else
        properties_[name] = value;
    }
  }
}
	void Value::loadFromStream(std::istream &input) {
		char currentCharacter;

		// We check that the stream is in UTF-8.
		char encoding[2];
		input.get(encoding[0]);
		input.get(encoding[1]);

		if (encoding[0] != '\0' && encoding[1] != '\0') {
			// We put the characters back.
			input.putback(encoding[1]);
			input.putback(encoding[0]);

			// Boolean value used to stop reading characters after the value
			// is done loading.
			bool noErrors = true;

			while (noErrors && input.good()) {
				input.get(currentCharacter);

				if (input.good()) {
					if (currentCharacter == Structural::BEGIN_END_STRING) {
						// The value to be parsed is a string.
						setString("");
						readString(input, *data.stringValue);
						noErrors = false;

					} else if (currentCharacter == Structural::BEGIN_OBJECT) {
						// The value to be parsed is an object.
						setObject(Object());
						readObject(input, *data.objectValue);
						noErrors = false;

					} else if (currentCharacter == Structural::BEGIN_ARRAY) {
						// The value to be parsed is an array.
						setArray(Array());
						readArray(input, *data.arrayValue);
						noErrors = false;

					} else if (currentCharacter == Literals::NULL_STRING[0]) {
						// We try to read the literal 'null'.
						if (!input.eof()) {
							input.get(currentCharacter);

							if (currentCharacter == Literals::NULL_STRING[1]) {
								if (!input.eof()) {
									input.get(currentCharacter);

									if (currentCharacter == Literals::NULL_STRING[2]) {
										if (!input.eof()) {
											input.get(currentCharacter);

											if (currentCharacter == Literals::NULL_STRING[3]) {
												setNull();
												noErrors = false;

											} else {
												std::cout << "invalid characters found" << std::endl;
											}

										} else {
											std::cout << "json input ends incorrectly" << std::endl;
										}

									} else {
										std::cout << "invalid characters found" << std::endl;
									}

								} else {
									std::cout << "json input ends incorrectly" << std::endl;
								}

							} else {
								std::cout << "invalid characters found" << std::endl;
							}

						} else {
							std::cout << "json input ends incorrectly" << std::endl;
						}

					} else if (currentCharacter == Numbers::MINUS ||
					           (currentCharacter >= Numbers::DIGITS[0] && currentCharacter <= Numbers::DIGITS[9])) {
						// Numbers can't start with zeroes.
						input.putback(currentCharacter);
						readNumber(input, *this);
						noErrors = false;

					} else if (currentCharacter == Literals::TRUE_STRING[0]) {
						// We try to read the boolean literal 'true'.
						if (!input.eof()) {
							input.get(currentCharacter);

							if (currentCharacter == Literals::TRUE_STRING[1]) {
								if (!input.eof()) {
									input.get(currentCharacter);

									if (currentCharacter == Literals::TRUE_STRING[2]) {
										if (!input.eof()) {
											input.get(currentCharacter);

											if (currentCharacter == Literals::TRUE_STRING[3]) {
												setBoolean(true);
												noErrors = false;
											}
										}
									}
								}
							}
						}

					} else if (currentCharacter == Literals::FALSE_STRING[0]) {
						// We try to read the boolean literal 'false'.
						if (!input.eof()) {
							input.get(currentCharacter);

							if (currentCharacter == Literals::FALSE_STRING[1]) {
								if (!input.eof()) {
									input.get(currentCharacter);

									if (currentCharacter == Literals::FALSE_STRING[2]) {
										if (!input.eof()) {
											input.get(currentCharacter);

											if (currentCharacter == Literals::FALSE_STRING[3]) {
												if (!input.eof()) {
													input.get(currentCharacter);

													if (currentCharacter == Literals::FALSE_STRING[4]) {
														setBoolean(false);
														noErrors = false;
													}
												}
											}
										}
									}
								}
							}
						}

					} else if (!isWhiteSpace(currentCharacter)) {
						std::cout << "Invalid character found: '" << currentCharacter << "'" << std::endl;
					}
				}
			}

		} else {
			std::cout << "File is not in UTF-8, not parsing." << std::endl;
		}
	}
Exemple #13
0
	void Object::readBinary(std::istream& stream, bool debug)
	{
		if (debug)
		{
			WritableBool hasDebug = false;
			stream.read(reinterpret_cast<char*>(&hasDebug), sizeof(hasDebug));

			if (hasDebug)
			{
				UInt32 len;
				stream.read(reinterpret_cast<char*>(&len), sizeof(len));
				char* data = new char[len];
				stream.read(data, len);
				data[len - 1] = '\0';
				this->debug = new DebugInfo();
				this->debug->string = String(data);
				delete[] data;
			}
			else
			{
				this->debug = 0;
			}
		}

		DataType type;
		stream.read(reinterpret_cast<char*>(&type), sizeof(type));

		switch (type)
		{
		default:
			throw ObjectReadException(FORMAT("Unknown DataType %u read from stream", type));
			break;

		case NIL:
			setNil();
			break;

		case BOOLEAN:
		{
			WritableBool value = false;
			stream.read(reinterpret_cast<char*>(&value), sizeof(value));
			setBoolean(value != 0 ? 1 : 0);
			break;
		}

		case NUMBER:
		{
			Number value = 0;
			stream.read(reinterpret_cast<char*>(&value), sizeof(value));
			setNumber(value);
			break;
		}

		case ADDRESS:
		{
			UInt32 value = 0;
			stream.read(reinterpret_cast<char*>(&value), sizeof(value));
			setAddress(value);
			break;
		}

		case STRING:
		{
			UInt32 len;
			stream.read(reinterpret_cast<char*>(&len), sizeof(len));
			char* data = new char[len];
			stream.read(data, len);
			data[len - 1] = '\0';
			setString(String(data));
			delete[] data;
			break;
		}
		}
	}
Exemple #14
0
	Object::Object(Bool value)
	{
		setBoolean(value);
	}