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();
}
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());
}
Exemple #3
0
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;
}
Exemple #4
0
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());
}
Exemple #5
0
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;
}
Exemple #6
0
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;
}
TEST_F(TypeParserTests, TestCharUTF32BETypeParsing) {
    this->setInput("Char:utf32be a");

    DataType type = this->typeParser()->parseType();
    ASSERT_EQ(DataType::Character, type.kind());
    ASSERT_EQ(DataType::CharacterEncoding::UTF32BE, type.characterEncoding());
}
Exemple #8
0
    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;
    }
Exemple #9
0
    DataType TypeParser::parseArrayType(bool genericParam) {
        assert(_helper->next().type() == Token::Type::PunctuationOpenBracket);

        DataType type = DataType(genericParam ? DataType::Kind::GenericArray : DataType::Kind::Array);

        if (_helper->peek().type() != Token::Type::PunctuationCloseBracket) {
            uint32_t value = 0;

            if (!this->parseIntegerSpecifierValue(&value)) {
                assert(0 && "Message: unable to parse array size");
                return DataType();
            }

            type.setArrayCount(value);
        }

        if (!_helper->nextIf(Token::Type::PunctuationCloseBracket)) {
            assert(0 && "Message: array type element count should be followed by a close bracket");
            return DataType();
        }

        type.addSubtype(this->parseType(genericParam));

        return this->applyTypePostfixes(type, genericParam);
    }
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;
}
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() );
    }
}
Exemple #12
0
    bool TypeParser::parseTypeList(Token::Type closingToken, bool allowIdentifiers, std::function<void (const DataType& type)> func) {
        // the type list could be empty
        if (_helper->peek().type() == closingToken) {
            return true;
        }

        for (int i = 0;; ++i) {
            assert(i < 100 && "Trapped potential infinite loop parsing list of types");

            if (!this->isAtType()) {
                break;
            }

            DataType type = this->parseType();

            if (allowIdentifiers && _helper->peek().type() == Token::Type::Identifier) {
                type.setLabel(_helper->nextStr());
            }

            func(type);

            if (_helper->nextIf(Token::Type::PunctuationComma)) {
                continue;
            }

            if (_helper->peek().type() == closingToken) {
                return true;
            }
        }

        // failed to parse the list as this point

        return false;
    }
Exemple #13
0
    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 ();
    }
Exemple #14
0
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;
}
Exemple #15
0
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;
       }
   }
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;
}
Exemple #17
0
//--------------------------------------------------------------------------
// 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);
    }
}
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;
}
int BattleroomListCtrl::CompareSide(const DataType user1, const DataType user2)
{
	if ( !user1 && !user2 ) return 0;
	else if ( !user1 ) return 1;
	else if ( !user2 ) return -1;

  int side1;
  if ( user1->BattleStatus().spectator )
    side1 = 1000;
  else
    side1 = user1->BattleStatus().side;

  int side2;
  if ( user2->BattleStatus().spectator )
    side2 = 1000;
  else
    side2 = user2->BattleStatus().side;

  if ( side1 < side2 )
      return -1;
  if ( side1 > side2 )
      return 1;

  return 0;
}
int BattleroomListCtrl::CompareRank(const DataType user1, const DataType user2)
{
	if ( !user1 && !user2 ) return 0;
	else if ( !user1 ) return 1;
	else if ( !user2 ) return -1;

  int rank1;
  if ( user1->BattleStatus().IsBot() )
    rank1 = 1000;
  else
    rank1 = user1->GetStatus().rank;

  int rank2;
  if ( user2->BattleStatus().IsBot() )
    rank2 = 1000;
  else
    rank2 = user2->GetStatus().rank;

  if ( rank1 < rank2 )
      return -1;
  if ( rank1 > rank2 )
      return 1;

  return 0;
}
Exemple #21
0
bool BSTClass<DataType>::findItemHelper(BSTNode <DataType> *temp, DataType &value ) const
    {
        char *nameData = new char[MAX_STR_LEN];   // created to obtain the information aside from the name
        int acctNum;   
        char *acctType = new char[MAX_STR_LEN];
             
             if ( temp == NULL ) 
             {  
                return false;
             }
             else if ( value.compareTo(temp->dataItem) == 0) // within this statement, we use set and get to obtain the required info
             {
                
                temp->dataItem.getAccount(nameData, acctNum, acctType);
                value.setAccount(nameData, acctNum, acctType);
                return true;
             }
             
             if ( value.compareTo(temp->dataItem) < 0)     
                    {
                        return findItemHelper( temp->left, value );
                    }
             else if( value.compareTo(temp->dataItem) > 0)
                    {
                        return findItemHelper( temp->right, value );
                    }
                    
                    
                    delete nameData;
                    delete acctType;
                    nameData = acctType = NULL;  
                   
         return true;      
    }
Exemple #22
0
void BSTClass<DataType>::insertNodeHelper(BSTNode<DataType> *temp, const DataType &value)
{
    if(value.compareTo(temp->dataItem) < 0)
    {
        if ( temp->left == NULL)
        {
            temp->left = new BSTNode<DataType> (value, NULL, NULL);
        }
        else
        {
            insertNodeHelper((temp->left), value);
        }
    }

    else if(value.compareTo(temp->dataItem) > 0)
    {
        if( temp->right == NULL)
        {
            temp->right = new BSTNode<DataType> (value, NULL, NULL);
        }
        else
        {
            insertNodeHelper((temp->right), value);
        }
    }

}
Exemple #23
0
//--------------------------------------------------------------------------
// Function:	Attribute::write
///\brief	This is an overloaded member function, provided for convenience.
///		It writes a \a H5std_string to this attribute.
///\param	mem_type  - IN: Attribute datatype (in memory)
///\param	strg      - IN: Data to be written
///\exception	H5::AttributeIException
// Programmer	Binh-Minh Ribler - Apr, 2003
//--------------------------------------------------------------------------
void Attribute::write(const DataType& mem_type, const H5std_string& strg) const
{
    // Check if this attribute 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 AttributeIException("Attribute::write", "H5Tis_variable_str failed");
    }
    // Convert string to C-string
    const char* strg_C;
    strg_C = strg.c_str();  // strg_C refers to the contents of strg as a C-str
    herr_t ret_value = 0;

    // Pass string in differently depends on variable or fixed length
    if (!is_variable_len)
    {
	ret_value = H5Awrite(id, mem_type.getId(), strg_C);
    }
    else
    {
	// passing third argument by address
	ret_value = H5Awrite(id, mem_type.getId(), &strg_C);
    }
    if (ret_value < 0)
    {
	throw AttributeIException("Attribute::write", "H5Awrite failed");
    }
}
Exemple #24
0
//-------------------------------------------------------------------------------------
bool FixedDict::checkDataChanged(const char* keyName, PyObject* value, bool isDelete)
{
	FixedDictType::FIXEDDICT_KEYTYPE_MAP& keyTypes = _dataType->getKeyTypes();
	FixedDictType::FIXEDDICT_KEYTYPE_MAP::const_iterator iter = keyTypes.begin();
	
	for(; iter != keyTypes.end(); ++iter)
	{
		if((*iter).first == keyName)
		{
			if(isDelete)
			{
				char err[255];
				kbe_snprintf(err, 255, "can't delete from FIXED_DICT key[%s].\n", keyName);
				PyErr_SetString(PyExc_TypeError, err);
				PyErr_PrintEx(0);
				return false;
			}
			else
			{
				DataType* dataType = (*iter).second->dataType;
				if(!dataType->isSameType(value)){
					return false;
				}
			}

			return true;
		}
	}

	char err[255];
	kbe_snprintf(err, 255, "set FIXED_DICT to a unknown key[%s].\n", keyName);
	PyErr_SetString(PyExc_TypeError, err);
	PyErr_PrintEx(0);
	return false;
}
Exemple #25
0
bool Feather::isInteger(Type* type)
{
    if ( !type || type->typeId() != Type::typeData )
        return false;
    DataType* dataType = static_cast<DataType*>(type);
    const string* nativeName = dataType->nativeName();
    return nativeName && (*nativeName == "i32" || *nativeName == "u32");
}
TEST_F(TypeParserTests, TestIntDataTypeParsing) {
    this->setInput("Int a");

    DataType type = this->typeParser()->parseType();

    ASSERT_EQ(DataType::Integer, type.kind());
    ASSERT_EQ("a", this->peek().str());
}
Exemple #27
0
const WCHAR* Object::GetString() 
{ 
    DataType* pPT = Get();
    if( NULL == pPT )
        return NULL;
    
    return pPT->GetString(); 
}
Exemple #28
0
IncorrectTypeError::IncorrectTypeError(
    const DataType& expected_type,
    const DataType& actual_type,
    const location& loc) : FrontEndError(loc) {
  message_ = boost::str(
      boost::format("Incorrect type '%1%', '%2%' required.")
      % actual_type.getName() % expected_type.getName());
}
Exemple #29
0
bool Scalar::GetBool()
{
    DataType* pPT = Get();
    if( NULL == pPT )
        return false;

    return pPT->GetBool();
}
Exemple #30
0
/**
 * Construct the name of the associative array from the name of
 * the key and value types.
 */
static RefPtr<SharedString>
make_name(TypeSystem& typeSys, DataType& keyType, DataType& elemType)
{
    ostringstream buf;

    buf << elemType.name()->c_str() << '[' << keyType.name()->c_str() << ']';
    return typeSys.get_string(buf.str().c_str(), buf.str().length());
}