示例#1
0
void MessagePackAdaptorTests::testString() {
    // Empty
    {
        pack(Datum(""));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::STR, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isString() );
        CPPUNIT_ASSERT( d.stringIsCString() );
        CPPUNIT_ASSERT_EQUAL( std::string(), d.getString() );
    }

    // Text
    {
        pack(Datum("abc 123"));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::STR, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isString() );
        CPPUNIT_ASSERT( d.stringIsCString() );
        CPPUNIT_ASSERT_EQUAL( std::string("abc 123"), d.getString() );
    }

    // Data
    {
        const std::string value("\1\0\2\0\3\0", 6);
        pack(Datum(value));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::BIN, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isString() );
        CPPUNIT_ASSERT( !d.stringIsCString() );
        CPPUNIT_ASSERT_EQUAL( value, d.getString() );
    }
}
示例#2
0
void MessagePackAdaptorTests::testFloat() {
    // Negative
    {
        pack(Datum(-1.5));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::FLOAT, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isFloat() );
        CPPUNIT_ASSERT_EQUAL( -1.5, d.getFloat() );
    }

    // Zero
    {
        pack(Datum(0.0));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::FLOAT, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isFloat() );
        CPPUNIT_ASSERT_EQUAL( 0.0, d.getFloat() );
    }

    // Positive
    {
        pack(Datum(2.5));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::FLOAT, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isFloat() );
        CPPUNIT_ASSERT_EQUAL( 2.5, d.getFloat() );
    }
}
示例#3
0
Datum ComponentRegistry::getNumber(std::string expression, GenericDataType type){

  Datum value;
    switch(type){
      case M_FLOAT:
      case M_INTEGER:
      case M_BOOLEAN:
      case M_STRING:
          value = getValue(expression, type);
          if (value.getDataType() == type) {
              return value;
          }
          break;
      default:
          throw FatalParserException("Attempt to cast a number of invalid type");
    }
	
	switch (type){
	
		case M_FLOAT:
			return Datum(value.getFloat());
		case M_INTEGER:
			return Datum(value.getInteger());
		case M_STRING:
			return Datum(value.getString());
		case M_BOOLEAN:
			return Datum(value.getBool());
		default:
			return value;			
	}
}
示例#4
0
Datum ComponentRegistry::getValue(std::string expression, GenericDataType type) {

  std::pair<std::string, GenericDataType> cacheKey(expression, type);
  shared_ptr<Datum> test = data_cache[cacheKey];
  if(test != NULL){
    return *test;
  }
  
  double doubleValue;
  long longValue;
  bool boolValue;
  Datum value;
  try {
    switch(type){
      case M_FLOAT:
      case M_INTEGER:
      case M_BOOLEAN:
            doubleValue = boost::lexical_cast<double>(expression);
            if (M_FLOAT == type) {
                value = Datum(doubleValue);
            } else if (M_INTEGER == type) {
                longValue = (long)doubleValue;
                if ((double)longValue != doubleValue) {
                    
                    throw NonFatalParserException("invalid integer literal", expression.c_str());
                }
                value = Datum(longValue);
            } else {
                boolValue = (bool)doubleValue;
                if ((double)boolValue != doubleValue) {
                    
                    throw NonFatalParserException("invalid boolean literal", expression.c_str());
                }
                value = Datum(boolValue);
            }
            break;
      case M_STRING:
          value = Datum(string(expression));
          break;
      default:
          // No lexical_cast for other types
          break;
    }
    
    if (!value.isUndefined()) {
        data_cache[cacheKey] = shared_ptr<Datum>(new Datum(value));
        return value;
    }
  } catch (NonFatalParserException& e){
      // Until we work out how to effectively flag these issues, treat them as fatal errors
      throw FatalParserException(e.what());
  } catch (boost::bad_lexical_cast& e){
    // no biggie, we can do this the hard(er) way
  }
  
  
	return Datum(ParsedExpressionVariable::evaluateExpression(expression));
}
示例#5
0
Datum StimulusDisplay::getAnnounceData(bool updateIsExplicit) {
    Datum stimAnnounce;
    
    if (!shouldAnnounceStimuli(updateIsExplicit)) {
        // No stim announcements, so just report the number of stimuli drawn
        stimAnnounce = Datum(long(stimAnnouncements.size()));
    } else {
        stimAnnounce = Datum(M_LIST, int(stimAnnouncements.size()));
        for (size_t i = 0; i < stimAnnouncements.size(); i++) {
            stimAnnounce.addElement(stimAnnouncements[i]);
        }
    }
    
	return stimAnnounce;
}
示例#6
0
void Lingo::b_framesToHMS(int nargs) {
	g_lingo->printStubWithArglist("b_framesToHMS", nargs);

	g_lingo->dropStack(nargs);

	g_lingo->push(Datum(0));
}
示例#7
0
void Lingo::b_numToChar(int nargs) {
	Datum d = g_lingo->pop();

	d.toInt();

	g_lingo->push(Datum((char)d.u.i));
}
示例#8
0
void Lingo::b_HMStoFrames(int nargs) {
	g_lingo->printStubWithArglist("b_HMStoFrames", nargs);

	g_lingo->dropStack(nargs);

	g_lingo->push(Datum(0));
}
示例#9
0
void Lingo::c_varpush() {
	Common::String name((char *)&(*g_lingo->_currentScript)[g_lingo->_pc]);
	Datum d;

	g_lingo->_pc += g_lingo->calcStringAlignment(name.c_str());

	// In immediate mode we will push variables as strings
	// This is used for playAccel
	if (g_lingo->_immediateMode) {
		g_lingo->push(Datum(new Common::String(name)));

		return;
	}

	if (g_lingo->getHandler(name) != NULL) {
		d.type = HANDLER;
		d.u.s = new Common::String(name);
		g_lingo->push(d);
		return;
	}

	d.u.sym = g_lingo->lookupVar(name.c_str());
	if (d.u.sym->type == CASTREF) {
		d.type = INT;
		int val = d.u.sym->u.i;

		delete d.u.sym;

		d.u.i = val;
	} else {
		d.type = VAR;
	}

	g_lingo->push(d);
}
		/** Import */
		static std::auto_ptr<DHParams> Import(const std::string& dhstr)
		{
			std::auto_ptr<DHParams> dh(new DHParams);
			int ret = gnutls_dh_params_import_pkcs3(dh->dh_params, Datum(dhstr).get(), GNUTLS_X509_FMT_PEM);
			ThrowOnError(ret, "Unable to import DH params");
			return dh;
		}
示例#11
0
void MessagePackAdaptorTests::testUndefined() {
    pack(Datum());
    auto o = unpack();
    CPPUNIT_ASSERT_EQUAL( msgpack::type::NIL, o.type );
    Datum d = o.as<Datum>();
    CPPUNIT_ASSERT( d.isUndefined() );
}
示例#12
0
void Lingo::b_label(int nargs) {
	Datum d = g_lingo->pop();
	d.toInt();
	warning("STUB: b_label(%d)", d.u.i);

	g_lingo->push(Datum(0));
}
示例#13
0
// ScopedVariable delegate methods
Datum ScopedVariableEnvironment::getValue(int index){
	if(current_context != NULL){
		return current_context->get(index);
	}
	
	// TODO: warn
	return Datum();
}
// override of base class to provide more info
Datum DisplayBitCodeStimulus::getCurrentAnnounceDrawData() {
    
    
    Datum announceData(M_DICTIONARY, 2);
    announceData.addElement(STIM_NAME, getTag());        // char
    announceData.addElement("bit_code",Datum((long)(*code_variable))); 

    return (announceData);
}
示例#15
0
void Lingo::c_symbolpush() {
	char *s = (char *)&(*g_lingo->_currentScript)[g_lingo->_pc];
	g_lingo->_pc += g_lingo->calcStringAlignment(s);

	warning("STUB: c_symbolpush()");

	// TODO: FIXME: Must push symbol instead of string
	g_lingo->push(Datum(new Common::String(s)));
}
示例#16
0
void Lingo::b_hilite(int nargs) {
	Datum d = g_lingo->pop();

	d.toInt();

	warning("STUB: b_hilite");

	g_lingo->push(Datum((char)d.u.i));
}
示例#17
0
void MessagePackAdaptorTests::testInteger() {
    constexpr auto llmin = std::numeric_limits<long long>::min();
    BOOST_STATIC_ASSERT(llmin < 0);  // Sanity check
    constexpr auto llmax = std::numeric_limits<long long>::max();
    BOOST_STATIC_ASSERT(llmax > 0);  // Sanity check

    // Negative
    {
        pack(Datum(llmin));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::NEGATIVE_INTEGER, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isInteger() );
        CPPUNIT_ASSERT_EQUAL( llmin, d.getInteger() );
    }

    // Zero
    {
        pack(Datum(0));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::POSITIVE_INTEGER, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isInteger() );
        CPPUNIT_ASSERT_EQUAL( 0LL, d.getInteger() );
    }

    // Positive
    {
        pack(Datum(llmax));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::POSITIVE_INTEGER, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isInteger() );
        CPPUNIT_ASSERT_EQUAL( llmax, d.getInteger() );
    }

    // Out of bounds
    {
        pack(static_cast<unsigned long long>(llmax) + 1ULL);
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::POSITIVE_INTEGER, o.type );
        CPPUNIT_ASSERT_THROW( o.as<Datum>(), msgpack::type_error );
    }
}
示例#18
0
void ExpandableListTestFixture::testAddSharedPtr(){
	ExpandableList<Datum> list;
	
	shared_ptr<Datum> shared_data(new Datum(10L));
	list.addElement(shared_data);
	
	CPPUNIT_ASSERT( list.getNElements() == 1 );
	CPPUNIT_ASSERT( *(list[0]) == Datum(10L) );
	
}
示例#19
0
	void _makeString(const std::string &format, va_list ap, 
					 MessageType type, 
					 MessageDomain domain = M_GENERIC_MESSAGE_DOMAIN) {
		char buffer[MSG_BUFFER_SIZE];// = { '\0' };
		int length = vsnprintf(buffer, MSG_BUFFER_SIZE, format.c_str(), ap);
        
        // If the message is a warning or an error, append line number information (if available)
        if (type >= M_WARNING_MESSAGE &&
            length < MSG_BUFFER_SIZE - 1)
        {
            boost::shared_ptr<StateSystem> stateSystem = StateSystem::instance(false);
            boost::shared_ptr<State> currentState;
            if (stateSystem && (currentState = stateSystem->getCurrentState().lock())) {
                int currentLineNumber = currentState->getLineNumber();
                if (currentLineNumber > 0) {
                    snprintf(buffer + length, MSG_BUFFER_SIZE - length, " [at line %d]", currentLineNumber);
                }
            }
        }
		
		if (GlobalMessageVariable) {
            Datum messageDatum(M_DICTIONARY, 4);
            messageDatum.addElement(M_MESSAGE_DOMAIN, Datum(M_INTEGER, domain));
            messageDatum.addElement(M_MESSAGE, Datum(buffer));
            messageDatum.addElement(M_MESSAGE_TYPE, Datum(M_INTEGER, type));
            messageDatum.addElement(M_MESSAGE_ORIGIN, Datum(M_INTEGER, GlobalMessageOrigin));
            
            // Use a mutex to ensure that the set and reset happen atomically
            boost::lock_guard<boost::mutex> lock(globalMessageVariableMutex);
            GlobalMessageVariable->setValue(messageDatum);
            GlobalMessageVariable->setSilentValue(0L);
		}
        
        // For debugging:  If the environment variable MWORKS_WRITE_MESSAGES_TO_STDERR is set,
        // write the message to standard error
        static int echo_to_stderr = -1;
        if (echo_to_stderr < 0) {
            echo_to_stderr = (NULL != getenv("MWORKS_WRITE_MESSAGES_TO_STDERR"));
        }
        if (echo_to_stderr) {
            fprintf(stderr, "%s\n", buffer);
        }
	}
示例#20
0
void Lingo::b_constrainV(int nargs) {
	Datum num = g_lingo->pop();
	Datum sprite = g_lingo->pop();

	num.toInt();
	sprite.toInt();

	warning("STUB: b_constrainV(%d, %d)", sprite.u.i, num.u.i);

	g_lingo->push(Datum(0));
}
示例#21
0
void Lingo::b_offset(int nargs) {
	Datum target = g_lingo->pop();
	Datum source = g_lingo->pop();

	target.toString();
	source.toString();

	warning("STUB: b_offset()");

	g_lingo->push(Datum(0));
}
示例#22
0
Datum BaseFrameListStimulus::getCurrentAnnounceDrawData() {
    Datum announceData = StandardDynamicStimulus::getCurrentAnnounceDrawData();
    
    if (stimulusGroup) {
        announceData.addElement(STIMULUS_GROUP, stimulusGroup->getTag());
    }
    
    announceData.addElement(LOOP, loop->getValue());
    announceData.addElement("playing", Datum(isPlaying()));
    
    int frameNumber = getFrameNumber();
    announceData.addElement("current_frame", Datum((long)frameNumber));
    
    Datum currentStimulusAnnounceData(0L);
    if ((frameNumber >= 0) && (frameNumber < getNumFrames())) {
        currentStimulusAnnounceData = getStimulusForFrame(frameNumber)->getCurrentAnnounceDrawData();
    }
    announceData.addElement("current_stimulus", currentStimulusAnnounceData);
    
    return announceData;
}
示例#23
0
文件: t3a.cpp 项目: ushakov/mapsoft
int main(){

  Options o;
  o.put("lon0",39.0);
  o.put("E0",500000.0);
  convs::pt2pt cnv(Datum("wgs84"), Proj("lonlat"), Options(),
                  Datum("pulkovo"), Proj("tmerc"), o);


  dPoint p( 39 + ((double)rand()/RAND_MAX - 0.5) * 6,    // 36..42
                 ((double)rand()/RAND_MAX - 0.5) * 180); // -90..+90
  printf("%.12f %.12f\n",p.x,p.y);

  int i;
  for (i=0; i<1000000; i++){
    cnv.frw(p);
    cnv.bck(p);
  }
  printf("%.12f %.12f\n",p.x,p.y);

}
示例#24
0
void MessagePackAdaptorTests::testBoolean() {
    // True
    {
        pack(Datum(true));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::BOOLEAN, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isBool() );
        CPPUNIT_ASSERT_EQUAL( true, d.getBool() );
    }

    // False
    {
        pack(Datum(false));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::BOOLEAN, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isBool() );
        CPPUNIT_ASSERT_EQUAL( false, d.getBool() );
    }
}
示例#25
0
// returns a value "top", for which datums should be on the More side if t>=top
int cisstCovTreeNode::SortNodeForSplit()
{
  int top = NData;
  static int callNumber = 0;
  callNumber++;
  vct3 Ck; vct3 Ct;
  vct3 r = F.Rotation().Row(0);
  double px = F.Translation()[0];
  for (int k = 0; k < top; k++) {
    Ck = pMyTree->DatumSortPoint(Datum(k)); // 3D coordinate of datum in global coord system
    double kx = r*Ck + px;  // compute the x coordinate in local coord system
    if (kx > 0) { // this one needs to go to the end of the line
      while ((--top) > k) {
        Ct = pMyTree->DatumSortPoint(Datum(top));
        double tx = r*Ct + px;
        if (tx <= 0) {
          int Temp = Datum(k);
          Datum(k) = Datum(top);
          Datum(top) = Temp;
          break; // from the "top" loop
        };
      };	// end of the "t" loop
    };	// end of the kx>0 case; at this point F*datum.x-coord <= 0 for i=0,...,k
  };	// end of k loop
  return top;
}
示例#26
0
void MessagePackAdaptorTests::testDictionary() {
    // Empty
    {
        pack(Datum(Datum::dict_value_type()));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::MAP, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isDictionary() );
        CPPUNIT_ASSERT( d.getDict().empty() );
    }

    // Non-empty
    {
        const Datum::dict_value_type value = { { Datum("foo"), Datum(1.5) }, { Datum(2), Datum(false) } };
        pack(Datum(value));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::MAP, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isDictionary() );
        CPPUNIT_ASSERT( value == d.getDict() );
    }
}
示例#27
0
void MessagePackAdaptorTests::testList() {
    // Empty
    {
        pack(Datum(Datum::list_value_type()));
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::ARRAY, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isList() );
        CPPUNIT_ASSERT( d.getList().empty() );
    }

    // Non-empty
    {
        const Datum::list_value_type value = { Datum(true), Datum(1.5), Datum("foo") };
        pack(value);
        auto o = unpack();
        CPPUNIT_ASSERT_EQUAL( msgpack::type::ARRAY, o.type );
        auto d = o.as<Datum>();
        CPPUNIT_ASSERT( d.isList() );
        CPPUNIT_ASSERT( value == d.getList() );
    }
}
示例#28
0
void VariableTestFixture::testSimpleGlobal() {
	shared_ptr<GlobalVariable>v =  global_variable_registry->createGlobalVariable( new VariableProperties(
																										   new Datum(42L), "test1",
																										   "Test",
																										   "Test",
																										   M_NEVER, M_WHEN_CHANGED,
																										   true, false,
																										   M_CONTINUOUS_INFINITE,""));	
	CPPUNIT_ASSERT((long)*v == 42);
	CPPUNIT_ASSERT(v->getValue() == Datum(M_INTEGER, 42));
	CPPUNIT_ASSERT(v->getVariableName() == "test1");
	CPPUNIT_ASSERT(v->getLogging() == M_WHEN_CHANGED);
	
	v->setLogging(M_NEVER);
	CPPUNIT_ASSERT(v->getLogging() == M_NEVER);
	
	v->setValue(Datum(M_INTEGER, 666));
	CPPUNIT_ASSERT((long)*v == 666);
	
	v->setValue(2112L);
	CPPUNIT_ASSERT((long)*v == 2112);
	
}
示例#29
0
int insertInto(vector<string> operations){

	string tableName = operations[2];
	vector<Datum> data;

	for(int i = 5; i < operations.size(); i++){

		if( isInteger(operations[i]) == true ){

			int number = atoi(operations[i].c_str());
			data.push_back(Datum(number));
		}

		else{

			data.push_back(Datum(operations[i]));
		}
	}

	engine.insertInto(tableName,data);

	return 0;
}
示例#30
0
// compute the function value(s) with the current parameters
//bool LinearFitableFunction::applyTheFunction(Datum *pInputData, Datum *outputData){ // DDC fix
bool LinearFitableFunction::applyTheFunction(const Datum& pInputData, Datum *outputData){ 

    lock();
    
    if (Parameters == NULL) {
        mwarning(M_SYSTEM_MESSAGE_DOMAIN,
			"WARNING: Prompted for calibrated value but parameters not yet set.");
        unlock(); return false;
    }
    
    //if (pInputData->getNElements() != numInputs) { // DDC fix
	if (pInputData.getNElements() != numInputs) {
    
//        //int xxx0 = pInputData->getNElements(); // DDC fix
//		int xxx0 = pInputData.getNElements();
//        //double xxx1 = (double)(pInputData->getElement(0)); // DDC fix
//        //double xxx2 = (double)(pInputData->getElement(1));
//        double xxx1 = (double)(pInputData.getElement(0)); // DDC fix
//        double xxx2 = (double)(pInputData.getElement(1));

    
        mwarning(M_SYSTEM_MESSAGE_DOMAIN,
			"WARNING: Prompted for calibrated value but not all input data exists.");
        unlock(); return false;
    }
    
    
    double *inputDataDouble = new double [numInputs];
    for (int i=0;i<numInputs;i++) {
        
		//inputDataDouble[i] = (double)(pInputData->getElement(i));  // copy data here // DDC fix
        inputDataDouble[i] = (double)(pInputData.getElement(i));  // copy data here // DDC fix
		
		//xxx = inputDataDouble[i];   //TODO -- remove
    }
    
    double temp = 0;
    for (int p=0; p< (basisSet->getNElements()); p++) {
        temp = temp + ((Parameters[p])*((basisSet->getElement(p))->applyBasis(inputDataDouble)));
        //ppp = Parameters[p];    //TODO -- remove
    }
    *outputData = Datum(temp);//DDC edit
	//*outputData = (Datum)temp;
    
	delete [] inputDataDouble; // DDC added
	
    unlock(); 
    return true;
    
}