当前位置: 首页>>代码示例>>C++>>正文


C++ Datum函数代码示例

本文整理汇总了C++中Datum函数的典型用法代码示例。如果您正苦于以下问题:C++ Datum函数的具体用法?C++ Datum怎么用?C++ Datum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Datum函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pack

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() );
    }
}
开发者ID:mworks,项目名称:mworks,代码行数:35,代码来源:MessagePackAdaptorTests.cpp

示例2: switch

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;			
	}
}
开发者ID:wangjing0,项目名称:mworks,代码行数:31,代码来源:ComponentRegistry.cpp

示例3: cacheKey

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));
}
开发者ID:wangjing0,项目名称:mworks,代码行数:58,代码来源:ComponentRegistry.cpp

示例4: Datum

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;
}
开发者ID:BramVerhoef,项目名称:mworks,代码行数:15,代码来源:StimulusDisplay.cpp

示例5: name

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);
}
开发者ID:AReim1982,项目名称:scummvm,代码行数:35,代码来源:lingo-code.cpp

示例6: Import

		/** 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;
		}
开发者ID:NikosPapakonstantinou,项目名称:inspircd,代码行数:8,代码来源:m_ssl_gnutls.cpp

示例7: Datum

// ScopedVariable delegate methods
Datum ScopedVariableEnvironment::getValue(int index){
	if(current_context != NULL){
		return current_context->get(index);
	}
	
	// TODO: warn
	return Datum();
}
开发者ID:mworks,项目名称:mworks,代码行数:9,代码来源:ScopedVariableEnvironment.cpp

示例8: announceData

// 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);
}
开发者ID:coxlab,项目名称:coxlab_mwcore_plugins,代码行数:10,代码来源:DisplayBitCodeStimulus.cpp

示例9: warning

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)));
}
开发者ID:AReim1982,项目名称:scummvm,代码行数:9,代码来源:lingo-code.cpp

示例10: BOOST_STATIC_ASSERT

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 );
    }
}
开发者ID:mworks,项目名称:mworks,代码行数:44,代码来源:MessagePackAdaptorTests.cpp

示例11: shared_data

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) );
	
}
开发者ID:mworks,项目名称:mworks,代码行数:10,代码来源:ExpandableListTest.cpp

示例12: _makeString

	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);
        }
	}
开发者ID:davidcox,项目名称:mworks,代码行数:43,代码来源:Utilities.cpp

示例13: Datum

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;
}
开发者ID:mworks,项目名称:mworks,代码行数:21,代码来源:BaseFrameListStimulus.cpp

示例14: main

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);

}
开发者ID:ushakov,项目名称:mapsoft,代码行数:21,代码来源:t3a.cpp

示例15: while

// 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;
}
开发者ID:mingliangfu,项目名称:IMLP,代码行数:27,代码来源:cisstCovTreeNode.cpp


注:本文中的Datum函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。