Beispiel #1
0
/**
 * @brief Return the n-th element from a composite value
 *
 * To the user, AnyType is a fully recursive type: Each AnyType object can be a
 * composite object and be composed of a number of other AnyType objects.
 * On top of the C++ abstraction layer, function have a single-top level
 * AnyType object as parameter.
 */
inline
AbstractionLayer::AnyType
AbstractionLayer::AnyType::operator[](uint16_t inID) const {
    consistencyCheck();

    if (isNull())
        throw std::invalid_argument("Unexpected Null value in function "
            "argument.");
    if (!isComposite())
        throw std::invalid_argument("Invalid type conversion requested. "
            "Expected composite type but got simple type.");
    
    if (mContent == ReturnComposite)
        return mChildren[inID];

    Oid typeID = 0;
    bool isMutable = false;
    Datum datum = 0;
    bool isTuple = false;
    HeapTupleHeader pgTuple = NULL;

    try {
        if (mContent == FunctionComposite) {
            if (inID >= size_t(PG_NARGS()))
                throw std::out_of_range("Access behind end of argument list");
            
            if (PG_ARGISNULL(inID))
                return AnyType();
                    
            backendGetTypeIDForFunctionArg(inID, typeID, isMutable);
            datum = PG_GETARG_DATUM(inID);
        } else if (mContent == NativeComposite)
            backendGetTypeIDAndDatumForTupleElement(inID, typeID, datum);
        
        if (typeID == InvalidOid)
            throw std::invalid_argument("Backend returned invalid type ID.");
        
        backendGetIsCompositeTypeAndHeapTupleHeader(typeID, datum, isTuple,
            pgTuple);
    } catch (PGException &e) {
        throw std::invalid_argument("An exception occurred while "
            "gathering information about PostgreSQL function arguments.");
    }

    return isTuple ?
        AnyType(pgTuple, datum, typeID) :
        AnyType(datum, typeID, isMutable);
}
AnyType TPTScriptInterface::eval(std::deque<std::string> * words)
{
	if(words->size() < 1)
		return AnyType(TypeNull, NULL);
	std::string word = words->front(); words->pop_front();
	char * rawWord = (char *)word.c_str();
	ValueType wordType = testType(word);
	switch(wordType)
	{
	case TypeFunction:
		if(word == "set")
			return tptS_set(words);
		else if(word == "create")
			return tptS_create(words);
		else if(word == "delete" || word == "kill")
			return tptS_delete(words);
		else if(word == "load")
			return tptS_load(words);
		else if(word == "reset")
			return tptS_reset(words);
		else if(word == "bubble")
			return tptS_bubble(words);
		break;
	case TypeNumber:
		return NumberType(atoi(rawWord));
	case TypePoint:
	{
		int pointX, pointY;
		sscanf(rawWord, "%d,%d", &pointX, &pointY);
		return PointType(pointX, pointY);
	}
	case TypeString:
		return StringType(word);
	}
}
Beispiel #3
0
  AnyType RendererSystemComponent::Observe(const ISubject* subject, const System::MessageType& message, AnyType::AnyTypeMap parameters)
  {
    if (message == System::Messages::SetPosition)
    {
      MathVector3 position = parameters[ System::Attributes::Position ].As<MathVector3>();
      m_sceneNode->setPosition(MathTools::AsOgreVector3(position));
    }

    if (message == System::Messages::SetOrientation)
    {
      MathQuaternion orientation = parameters[ System::Attributes::Orientation ].As<MathQuaternion>();
      m_sceneNode->setOrientation(MathTools::AsOgreQuaternion(orientation));
    }

    if (message == System::Messages::GetAnimationState)
    {
      SkeletonList skeletons;

      this->LinkSkeletons(m_sceneNode, &skeletons);
      
      return skeletons;
    }

    return AnyType();
  }
AnyType TPTScriptInterface::eval(std::deque<String> * words)
{
	if(words->size() < 1)
		return AnyType(TypeNull, ValueValue());
	String word = words->front(); words->pop_front();
	ValueType wordType = testType(word);
	switch(wordType)
	{
	case TypeFunction:
		if(word == "set")
			return tptS_set(words);
		else if(word == "create")
			return tptS_create(words);
		else if(word == "delete" || word == "kill")
			return tptS_delete(words);
		else if(word == "load")
			return tptS_load(words);
		else if(word == "reset")
			return tptS_reset(words);
		else if(word == "bubble")
			return tptS_bubble(words);
		else if(word == "quit")
			return tptS_quit(words);
		break;
	case TypeNumber:
		return NumberType(parseNumber(word));
	case TypeFloat:
		return FloatType(atof(word.ToUtf8().c_str()));
	case TypePoint:
	{
		int x, y;
		if(String::Split comma = word.SplitNumber(x))
			if(comma.After().BeginsWith(","))
				if(comma.After().Substr(1).SplitNumber(y))
					return PointType(x, y);
		return PointType(0, 0);
	}
	case TypeString:
		return StringType(word);
	default:
		break;
	}
	return StringType(word);
}
Beispiel #5
0
        return anyUnicodeStringToSystemString(boost::any_cast<AnyUnicodeString>(source));
    else if (source.type() == typeid(AnyByteArray))
        return anyByteArrayToByteArray(boost::any_cast<AnyByteArray>(source));
	else if (source.type() == typeid(AnyAsciiStringArray))
		return anyAsciiStringArrayToStringArray(boost::any_cast<AnyAsciiStringArray>(source));
	else if (source.type() == typeid(AnyUnicodeStringArray))
		return anyUnicodeStringArrayToStringArray(boost::any_cast<AnyUnicodeStringArray>(source));

	return nullptr;
}

void toAny(System::Object ^source, AnyType &destination)
{    
	if (source == nullptr)
	{
		destination = AnyType();
		return;
	}

    System::Type^ type = source->GetType();

    if (type == System::Boolean::typeid)
    {
        AnyBoolean value = safe_cast<System::Boolean>(source);
        destination = value;
    }
    else if (type == System::SByte::typeid)
    {
        AnyInt8 value = safe_cast<System::SByte>(source);
        destination = value;
    }
Beispiel #6
0
/**
 * @brief Return an AnyType object representing Null.
 *
 * @internal
 *     An object representing Null is not guaranteed to be unique. In fact, here
 *     we simply return an AnyType object initialized by the default
 *     constructor.
 *
 * @see AbstractionLayer::AnyType::AnyType()
 */
inline
AnyType
Null() {
    return AnyType();
}
Beispiel #7
0
/**
 * @brief Return the n-th element from a composite value
 *
 * To the user, AnyType is a fully recursive type: Each AnyType object can be a
 * composite object and be composed of a number of other AnyType objects.
 * Function written using the C++ abstraction layer have a single logical
 * argument of type AnyType.
 */
inline
AnyType
AnyType::operator[](uint16_t inID) const {
    consistencyCheck();

    if (isNull()) {
        // Handle case mContent == NULL
        throw std::invalid_argument("Invalid type conversion. "
                                    "Null where not expected.");
    }
    if (!isComposite()) {
        // Handle case mContent == Scalar
        throw std::invalid_argument("Invalid type conversion. "
                                    "Composite type where not expected.");
    }

    if (mContent == ReturnComposite)
        return mChildren[inID];

    // It holds now that mContent is either FunctionComposite or NativeComposite
    // In this case, it is guaranteed that fcinfo != NULL
    Oid typeID = 0;
    bool isMutable = false;
    Datum datum = 0;

    if (mContent == FunctionComposite) {
        // This AnyType object represents to composite value consisting of all
        // function arguments

        if (inID >= size_t(PG_NARGS()))
            throw std::out_of_range("Invalid type conversion. Access behind "
                                    "end of argument list.");

        if (PG_ARGISNULL(inID))
            return AnyType();

        typeID = mSysInfo->functionInformation(fcinfo->flinfo->fn_oid)
                 ->getArgumentType(inID, fcinfo->flinfo);
        if (inID == 0) {
            // If we are called as an aggregate function, the first argument is
            // the transition state. In that case, we are free to modify the
            // data. In fact, for performance reasons, we *should* even do all
            // modifications in-place. In all other cases, directly modifying
            // memory is dangerous.
            // See warning at:
            // http://www.postgresql.org/docs/current/static/xfunc-c.html#XFUNC-C-BASETYPE

            // BACKEND: AggCheckCallContext currently will never raise an
            // exception
            isMutable = AggCheckCallContext(fcinfo, NULL);
        }
        datum = PG_GETARG_DATUM(inID);
    } else { /* if (mContent == NativeComposite) */
        // This AnyType objects represents a tuple that was passed from the
        // backend

        TupleDesc tupdesc = mSysInfo
                            ->typeInformation(HeapTupleHeaderGetTypeId(mTupleHeader))
                            ->getTupleDesc(HeapTupleHeaderGetTypMod(mTupleHeader));

        if (inID >= tupdesc->natts)
            throw std::out_of_range("Invalid type conversion. Access behind "
                                    "end of composite object.");

        typeID = tupdesc->attrs[inID]->atttypid;
        bool isNull = false;
        datum = madlib_GetAttributeByNum(mTupleHeader, inID, &isNull);
        if (isNull)
            return AnyType();
    }

    if (typeID == InvalidOid)
        throw std::invalid_argument("Backend returned invalid type ID.");

    return mSysInfo->typeInformation(typeID)->isCompositeType()
           ? AnyType(mSysInfo, madlib_DatumGetHeapTupleHeader(datum), datum,
                     typeID)
           : AnyType(mSysInfo, datum, typeID, isMutable);
}
Beispiel #8
0
 /**
  * @brief Get the element at the given position (0-based).
  *
  * This function is a convenience wrapper around getValueByID(uint16_t).
  */
 AnyType operator[](uint16_t inID) const {
     return AnyType(getValueByID(inID));
 }
Beispiel #9
0
 /**
  * @brief Clone this instance if it is not mutable, otherwise return this
  */
 AnyType cloneIfImmutable() const {
     if (isMutable() || !mDelegate)
         return *this;
     
     return AnyType(mDelegate->clone());
 }
Beispiel #10
0
void CGroup::HandlerMailOpt(CRole *pCRole, WorldPacket &pkg)
{
	uint64 group_id;
	uint32_t mail_id;
	uint8_t flag;
	group_id = MAKE_FIND_GROUPID(GetdwCreateId(), GetdwId()); 
	pkg >> mail_id;
	pkg >> flag;
	IME_LOG("group_id %llu, mail_id %u", group_id, mail_id);
	
	CDBCtrl::SGroupMail tempMailDetail;
	if (!CDBCtrl::GetGroupMailInfoSingle(group_id, mail_id, tempMailDetail))
	{
		IME_ERROR("get mail data fail");
		pCRole->SendErrorMsg(ERRNO_MSG_DB_NO_DATA_OR_ERROR, CMD_SC_GROUP_MAIL_OPT_RESULT);
		return;
	}
	if (flag == 0)
	{
		IME_ERROR("nothing to do email groupid %llu, mail_id %u, opt %u", group_id, mail_id, flag);
		pCRole->SendErrorMsg(ERRNO_MSG_DATA_ILLEGAL, CMD_SC_GROUP_MAIL_OPT_RESULT);
		return;
	}

	ByteBuffer blob;
	blob.append(tempMailDetail.blob.data(), tempMailDetail.blob.size());
	uint32_t userid;
	uint32_t index;
	std::string username;
	if (tempMailDetail.byDetailType == E_GDT_MAIL_REQUEST_ENTER)
	{	
		if (tempMailDetail.byDoflag != 0)
		{
			IME_ERROR("the mail have been handled groupid %u mailid %u", group_id, mail_id);
			pCRole->SendErrorMsg(ERRNO_MSG_MAIL_ALREADY_HANDLE, CMD_SC_GROUP_MAIL_OPT_RESULT);
			return;
		}

		SGroupMember *pSGroupMember = GetGroupMember(pCRole->GetdwAccountId());
		if (!CConfGroupAdmin::GetVal(pSGroupMember->byPosion, E_GA_MEMBER_IO))
		{
			pCRole->SendErrorMsg(ERRNO_MSG_GROUP_NOT_AUTH, CMD_SC_GROUP_MAIL_OPT_RESULT);
			return;
		}

		if (GetwPersionNumber() >= GetwPersionLimit())
		{
			IME_ERROR("overload persion limit now %u limit %u", GetwPersionNumber(), GetwPersionLimit());
			pCRole->SendErrorMsg(ERRNO_MSG_GROUP_PERSION_OVERLOAD, CMD_SC_GROUP_MAIL_OPT_RESULT);
			return;
		}
		blob >> userid >> index >> username;
		if (sWorld->GetCGroupByUserId(userid) != NULL)
		{
			IME_ERROR("this user %u have joined group", userid);
			pCRole->SendErrorMsg(ERRNO_MSG_ALREADY_IN_GROUP, CMD_SC_GROUP_MAIL_OPT_RESULT);
			return;
		}
		

		if (!CDBCtrl::UpdateGroupMail(group_id, mail_id, flag))
		{
			IME_ERROR("update mail fail from not do to do groupid %u,mail %u", group_id, mail_id);
			pCRole->SendErrorMsg(ERRNO_MSG_DB_NO_DATA_OR_ERROR, CMD_SC_GROUP_MAIL_OPT_RESULT);
			return;
		}

		if (flag == 1)
		{
			IME_LOG("userid %u want to join group %llu", userid, group_id);
			SetwPersionNumber(m_wPersionNumber + 1);
			m_vecPosion5Persion.push_back(AnyType(userid));
			SetvecPosion5Persion(m_vecPosion5Persion);
			SGroupMember SGMtmp;
			CreateSGroupMemberNormal(SGMtmp, userid);
			m_mapUserGroup[userid] = SGMtmp;	

			SendMailAgreeEnter(pCRole, username);

			WorldPacket updatepkg;
			PackProUpdate(updatepkg);
			SendDataToAllMember(&updatepkg);
		}	
		else
		{
		}
	}
	else
	{