本文整理汇总了C++中DataType类的典型用法代码示例。如果您正苦于以下问题:C++ DataType类的具体用法?C++ DataType怎么用?C++ DataType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createError
Expected<T, DatabaseError> InMemoryDatabase::getValue(const std::string& domain,
const std::string& key) {
debug_only::verifyTrue(is_open_, "database is not open");
if (!is_open_) {
return createError(DatabaseError::DbIsNotOpen, "Database is closed");
}
auto storage_iter = storage_.find(domain);
if (storage_iter == storage_.end()) {
return domainNotFoundError(domain);
}
std::lock_guard<std::mutex> lock(storage_iter->second->getMutex());
auto result = storage_iter->second->get(key);
if (result) {
DataType value = result.take();
if (value.type() == typeid(T)) {
return boost::get<T>(value);
} else {
auto error =
createError(DatabaseError::KeyNotFound, "Requested wrong type for: ")
<< domain << ":" << key << " stored type: " << value.type().name()
<< " requested type " << boost::core::demangle(typeid(T).name());
LOG(ERROR) << error.getFullMessageRecursive();
debug_only::fail(error.getFullMessageRecursive().c_str());
return std::move(error);
}
}
return result.takeError();
}
示例2: TEST_F
TEST_F(TypeParserTests, TestCharASCIITypeParsing) {
this->setInput("Char:ascii a");
DataType type = this->typeParser()->parseType();
ASSERT_EQ(DataType::Character, type.kind());
ASSERT_EQ(DataType::CharacterEncoding::ASCII, type.characterEncoding());
}
示例3: ASSERT
Type* SprFrontend::changeRefCount(Type* type, int numRef, const Location& loc)
{
ASSERT(type);
// If we have a LValue type, remove it
while ( type->typeId() == Type::typeLValue )
type = static_cast<LValueType*>(type)->baseType();
switch ( type->typeId() )
{
case Type::typeData:
{
DataType* dt = static_cast<DataType*>(type);
type = DataType::get(dt->classDecl(), numRef, dt->mode());
break;
}
case Type::typeConcept:
{
ConceptType* ct = static_cast<ConceptType*>(type);
type = ConceptType::get(ct->concept(), numRef, ct->mode());
break;
}
default:
REP_INTERNAL(loc, "Cannot change reference count for type %1%") % type;
}
return type;
}
示例4: FrontEndError
DataTypeNotEqualError::DataTypeNotEqualError(
const DataType& type1, const DataType& type2, const location& loc)
: FrontEndError(loc) {
message_ = boost::str(boost::format(
"Type '%s' is not equals to type '%s'")
% type1.getName() % type2.getName());
}
示例5: new_vars
Data Func::eval(VarTable *vars,
FuncTable *funcs,
vector<Data> &argv)
{
VarTable new_vars(vars);
m_args->apply(&new_vars, argv);
bool retstat = false;
Data ret = m_block->eval(&new_vars, funcs, &retstat);
DataType type = m_var_decl->get_type();
if (type != ret.get_type())
{
if (type.get_type() == "int")
{
printf("Error: function conversion from float to int\n");
exit(1);
}
int ival = ret.get_int();
ret.set_float((float)ival);
ret.set_type(DataType("float", 0));
}
return ret;
}
示例6: if
result_t SingleDataField::create(const string id, const unsigned char length,
const string name, const string comment, const string unit,
const PartType partType, int divisor, map<unsigned int, string> values,
const string constantValue, const bool verifyValue, SingleDataField* &returnField)
{
DataType* dataType = DataTypeList::getInstance()->get(id, length==REMAIN_LEN ? (unsigned char)0 : length);
if (!dataType) {
return RESULT_ERR_NOTFOUND;
}
unsigned char bitCount = dataType->getBitCount();
unsigned char byteCount = (unsigned char)((bitCount + 7) / 8);
if (dataType->isAdjustableLength()) {
// check length
if ((bitCount % 8) != 0) {
if (length == 0) {
bitCount = 1; // default bit count: 1 bit
} else if (length <= bitCount) {
bitCount = length;
} else {
return RESULT_ERR_OUT_OF_RANGE; // invalid length
}
byteCount = (unsigned char)((bitCount + 7) / 8);
} else if (length == 0) {
byteCount = 1; //default byte count: 1 byte
} else if (length <= byteCount || length == REMAIN_LEN) {
byteCount = length;
} else {
return RESULT_ERR_OUT_OF_RANGE; // invalid length
}
}
if (!constantValue.empty()) {
returnField = new ConstantDataField(name, comment, unit, dataType, partType, byteCount, constantValue, verifyValue);
return RESULT_OK;
}
if (dataType->isNumeric()) {
NumberDataType* numType = (NumberDataType*)dataType;
if (values.empty() && numType->hasFlag(DAY)) {
for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++)
values[numType->getMinValue() + i] = dayNames[i];
}
result_t result = numType->derive(divisor, bitCount, numType);
if (result!=RESULT_OK) {
return result;
}
if (values.empty()) {
returnField = new SingleDataField(name, comment, unit, numType, partType, byteCount);
return RESULT_OK;
}
if (values.begin()->first < numType->getMinValue() || values.rbegin()->first > numType->getMaxValue()) {
return RESULT_ERR_OUT_OF_RANGE;
}
returnField = new ValueListDataField(name, comment, unit, numType, partType, byteCount, values);
return RESULT_OK;
}
if (divisor != 0 || !values.empty()) {
return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field
}
returnField = new SingleDataField(name, comment, unit, (StringDataType*)dataType, partType, byteCount);
return RESULT_OK;
}
示例7: assert
DataType TypeParser::parseFunctionOrTupleType() {
assert(_helper->nextIf(Token::Type::PunctuationOpenParen));
DataType type;
this->parseTypeListWithLabels(Token::Type::PunctuationCloseParen, [&] (const DataType& subtype) {
type.addSubtype(subtype);
});
if (!_helper->nextIf(Token::Type::PunctuationCloseParen)) {
assert(0 && "Message: failed to parse a tuple/function type");
return DataType();
}
if (!_helper->nextIf(Token::Type::OperatorArrow)) {
type.setKind(DataType::Kind::Tuple);
return type;
}
type.setKind(DataType::Kind::Function);
// TODO: clean this up - move the subtypes to parameters
type.parameters = type.subtypes;
type.subtypes.clear();
type.setReturnType(this->parseType());
return type;
}
示例8: GetIndexFromData
int BattleListCtrl::GetIndexFromData( const DataType& data ) const
{
static long seekpos;
seekpos = LSL::Util::Clamp( seekpos, 0l , (long)m_data.size() );
int index = seekpos;
for ( DataCIter f_idx = m_data.begin() + seekpos; f_idx != m_data.end() ; ++f_idx )
{
if ( *f_idx != 0 && data->Equals( *(*f_idx) ) )
{
seekpos = index;
return seekpos;
}
index++;
}
//it's ok to init with seekpos, if it had changed this would not be reached
int r_index = seekpos - 1;
for ( DataRevCIter r_idx = m_data.rbegin() + ( m_data.size() - seekpos ); r_idx != m_data.rend() ; ++r_idx )
{
if ( *r_idx != 0 && data->Equals( *(*r_idx) ) )
{
seekpos = r_index;
return seekpos;
}
r_index--;
}
return -1;
}
示例9: OnDLMod
void BattleListCtrl::OnDLMod( wxCommandEvent& /*unused*/ )
{
if ( m_selected_index > 0 && (long)m_data.size() > m_selected_index ) {
DataType dt = m_data[m_selected_index];
ui().Download(_T("game"), dt->GetHostModName(), dt->GetHostModHash() );
}
}
示例10: Config_Error
CORBA::TypeCode_ptr
DynAlias_Handler::create_typecode (const DataType &type)
{
DANCE_TRACE("DynAlias_Handler::create_typecode");
if (!type.alias_p ())
{
DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR,
(LM_ERROR, ACE_TEXT ("ERROR: Alias type description required")));
throw Config_Error (ACE_TEXT (""),
ACE_TEXT ("Did not find expected alias type description, tk_kind"\
"may be wrong."));
}
CORBA::TypeCode_var tc =
DYNANY_HANDLER->orb ()->create_alias_tc
(ACE_TEXT_ALWAYS_CHAR (type.alias ().typeId ().c_str ()),
ACE_TEXT_ALWAYS_CHAR (type.alias ().name ().c_str ()),
DYNANY_HANDLER->create_typecode (type.alias ().elementType ()));
DYNANY_HANDLER->register_typecode (type.alias ().typeId (),
tc.in ());
return tc._retn ();
}
示例11: TestInteger
void TestInteger () {
DataType<int> intData = 123;
cout<<"MSB is : "<<int(intData.GetMSB())<<endl;
cout<<"LSB is : "<<int(intData.GetLSB())<<endl;
cout<<"Total Number of Bits those are One are : "<<intData.BitsCount(1)<<endl;
cout<<"Total Number of Bits those are Zero are : "<<intData.BitsCount(0)<<endl;
}
示例12: if
void BSTClass<DataType>::insertHelper
(
BSTNode<DataType> *&workingPtr,
const DataType &newData
)
{
if ( workingPtr == NULL )
{
workingPtr = new BSTNode<DataType>( newData, NULL, NULL );
}
else if ( newData.compareTo( workingPtr->dataItem ) < 0 )
{
insertHelper( workingPtr->left, newData );
}
else if ( newData.compareTo( workingPtr->dataItem ) > 0 )
{
insertHelper( workingPtr->right, newData);
}
else
{
workingPtr->dataItem = newData;
}
}
示例13: CompareTeam
int BattleroomListCtrl::CompareTeam(const DataType user1, const DataType user2)
{
if ( !user1 && !user2 ) return 0;
else if ( !user1 ) return 1;
else if ( !user2 ) return -1;
int team1;
if ( user1->BattleStatus().spectator )
team1 = 1000;
else
team1 = user1->BattleStatus().team;
int team2;
if ( user2->BattleStatus().spectator )
team2 = 1000;
else
team2 = user2->BattleStatus().team;
if ( team1 < team2 )
return -1;
if ( team1 > team2 )
return 1;
return 0;
}
示例14: read
//--------------------------------------------------------------------------
// Function: DataSet::read
///\brief This is an overloaded member function, provided for convenience.
/// It takes a reference to a \c H5std_string for the buffer.
///\param buf - IN: Buffer for read data
///\param mem_type - IN: Memory datatype
///\param mem_space - IN: Memory dataspace
///\param file_space - IN: Dataset's dataspace in the file
///\param xfer_plist - IN: Transfer property list for this I/O operation
///\exception H5::DataSetIException
// Programmer Binh-Minh Ribler - 2000
// Modification
// Jul 2009
// Follow the change to Attribute::read and use the following
// private functions to read datasets with fixed- and
// variable-length string:
// DataSet::p_read_fixed_len and
// DataSet::p_read_variable_len
//--------------------------------------------------------------------------
void DataSet::read(H5std_string& strg, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist) const
{
// Check if this dataset has variable-len string or fixed-len string and
// proceed appropriately.
htri_t is_variable_len = H5Tis_variable_str(mem_type.getId());
if (is_variable_len < 0)
{
throw DataSetIException("DataSet::read", "H5Tis_variable_str failed");
}
// Obtain identifiers for C API
hid_t mem_type_id = mem_type.getId();
hid_t mem_space_id = mem_space.getId();
hid_t file_space_id = file_space.getId();
hid_t xfer_plist_id = xfer_plist.getId();
if (!is_variable_len) // only allocate for fixed-len string
{
p_read_fixed_len(mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg);
}
else
{
p_read_variable_len(mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg);
}
}
示例15: CompareAlly
int BattleroomListCtrl::CompareAlly(const DataType user1, const DataType user2)
{
if ( !user1 && !user2 ) return 0;
else if ( !user1 ) return 1;
else if ( !user2 ) return -1;
int ally1;
if ( user1->BattleStatus().spectator )
ally1 = 1000;
else
ally1 = user1->BattleStatus().ally;
int ally2;
if ( user2->BattleStatus().spectator )
ally2 = 1000;
else
ally2 = user2->BattleStatus().ally;
if ( ally1 < ally2 )
return -1;
if ( ally1 > ally2 )
return 1;
return 0;
}