FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const {
  if (this == pOther)
    return TRUE;
  if (!pOther)
    return FALSE;
  if (pOther->m_Type != m_Type) {
    if (IsReference() && GetDirect())
      return GetDirect()->IsIdentical(pOther);
    if (pOther->IsReference())
      return IsIdentical(pOther->GetDirect());
    return FALSE;
  }
  switch (m_Type) {
    case PDFOBJ_BOOLEAN:
      return AsBoolean()->Identical(pOther->AsBoolean());
    case PDFOBJ_NUMBER:
      return AsNumber()->Identical(pOther->AsNumber());
    case PDFOBJ_STRING:
      return AsString()->Identical(pOther->AsString());
    case PDFOBJ_NAME:
      return AsName()->Identical(pOther->AsName());
    case PDFOBJ_ARRAY:
      return AsArray()->Identical(pOther->AsArray());
    case PDFOBJ_DICTIONARY:
      return AsDictionary()->Identical(pOther->AsDictionary());
    case PDFOBJ_NULL:
      return TRUE;
    case PDFOBJ_STREAM:
      return AsStream()->Identical(pOther->AsStream());
    case PDFOBJ_REFERENCE:
      return AsReference()->Identical(pOther->AsReference());
  }
  return FALSE;
}
示例#2
0
inline uint64_t Object::Get<uint64_t>(const std::string &key) const
{
	auto value = Find(key);
	if(!value->IsNumber() && !value->IsString())
		throw std::logic_error(std::string("Field was not of type json=type Number of String ") + key);

	return value->IsNumber() ? static_cast<uint64_t>(value->AsNumber())
		: std::stoll(value->AsString());
}
示例#3
0
double
XPath_Value::AsNumberL ()
{
  switch (type)
    {
    case XP_VALUE_BOOLEAN:
      return data.boolean ? 1. : 0.;

    case XP_VALUE_NUMBER:
      return data.number;

    case XP_VALUE_STRING:
      return AsNumber (data.string);
    }

  TempBuffer buffer; ANCHOR (TempBuffer, buffer);
  return AsNumber (AsStringL (buffer));
}
示例#4
0
inline bool Object::Get<bool>(const std::string &key) const
{
	auto value = Find(key);

	if(value->IsBool())
		return value->AsBool();
	else if(value->IsNumber())
		return value->AsNumber();
	else
		return std::stod(value->AsString());
}
FX_FLOAT CPDF_Object::GetNumber() const {
  switch (m_Type) {
    case PDFOBJ_NUMBER:
      return AsNumber()->GetNumber();
    case PDFOBJ_REFERENCE: {
      const CPDF_Reference* pRef = AsReference();
      if (!pRef->m_pObjList)
        break;

      CPDF_Object* pObj =
          pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum(), nullptr);
      return pObj ? pObj->GetNumber() : 0;
    }
  }
  return 0;
}
void CPDF_Object::SetString(const CFX_ByteString& str) {
  switch (m_Type) {
    case PDFOBJ_BOOLEAN:
      AsBoolean()->m_bValue = (str == "true");
      return;
    case PDFOBJ_NUMBER:
      AsNumber()->SetString(str);
      return;
    case PDFOBJ_STRING:
      AsString()->m_String = str;
      return;
    case PDFOBJ_NAME:
      AsName()->m_Name = str;
      return;
  }
  ASSERT(FALSE);
}
示例#7
0
inline uint64_t Object::GetOpt<uint64_t>(const std::string &key, const uint64_t &defaultValue) const
{
	auto value = FindOpt(key);
	if(!value || (!value->IsNumber() && !value->IsString()))
		return defaultValue;

	if(value->IsString() && value->AsString().empty())
		return defaultValue;

	try
	{
		return value->IsNumber() ? static_cast<uint32_t>(value->AsNumber()) 
			: std::stoll(value->AsString());
	}
	catch(std::exception &)
	{
		return defaultValue;
	}
}
CFX_ByteString CPDF_Object::GetString() const {
  switch (m_Type) {
    case PDFOBJ_BOOLEAN:
      return AsBoolean()->m_bValue ? "true" : "false";
    case PDFOBJ_NUMBER:
      return AsNumber()->GetString();
    case PDFOBJ_STRING:
      return AsString()->m_String;
    case PDFOBJ_NAME:
      return AsName()->m_Name;
    case PDFOBJ_REFERENCE: {
      const CPDF_Reference* pRef = AsReference();
      if (!pRef->m_pObjList)
        break;

      CPDF_Object* pObj =
          pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum(), nullptr);
      return pObj ? pObj->GetString() : CFX_ByteString();
    }
  }
  return CFX_ByteString();
}
int CPDF_Object::GetInteger() const {
  CFX_AutoRestorer<int> restorer(&s_nCurRefDepth);
  if (++s_nCurRefDepth > kObjectRefMaxDepth)
    return 0;

  switch (m_Type) {
    case PDFOBJ_BOOLEAN:
      return AsBoolean()->m_bValue;
    case PDFOBJ_NUMBER:
      return AsNumber()->GetInteger();
    case PDFOBJ_REFERENCE: {
      const CPDF_Reference* pRef = AsReference();
      PARSE_CONTEXT context;
      FXSYS_memset(&context, 0, sizeof(PARSE_CONTEXT));
      if (!pRef->m_pObjList)
        return 0;

      CPDF_Object* pObj =
          pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum(), &context);
      return pObj ? pObj->GetInteger() : 0;
    }
  }
  return 0;
}
CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
                                        std::set<FX_DWORD>* visited) const {
  switch (m_Type) {
    case PDFOBJ_BOOLEAN:
      return new CPDF_Boolean(AsBoolean()->m_bValue);
    case PDFOBJ_NUMBER: {
      const CPDF_Number* pThis = AsNumber();
      return new CPDF_Number(pThis->m_bInteger ? pThis->m_Integer
                                               : pThis->m_Float);
    }
    case PDFOBJ_STRING: {
      const CPDF_String* pString = AsString();
      return new CPDF_String(pString->m_String, pString->IsHex());
    }
    case PDFOBJ_NAME:
      return new CPDF_Name(AsName()->m_Name);
    case PDFOBJ_ARRAY: {
      CPDF_Array* pCopy = new CPDF_Array();
      const CPDF_Array* pThis = AsArray();
      int n = pThis->GetCount();
      for (int i = 0; i < n; i++) {
        CPDF_Object* value = pThis->m_Objects.GetAt(i);
        pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited));
      }
      return pCopy;
    }
    case PDFOBJ_DICTIONARY: {
      CPDF_Dictionary* pCopy = new CPDF_Dictionary();
      const CPDF_Dictionary* pThis = AsDictionary();
      for (const auto& it : *pThis) {
        pCopy->m_Map.insert(std::make_pair(
            it.first, it.second->CloneInternal(bDirect, visited)));
      }
      return pCopy;
    }
    case PDFOBJ_NULL: {
      return new CPDF_Null;
    }
    case PDFOBJ_STREAM: {
      const CPDF_Stream* pThis = AsStream();
      CPDF_StreamAcc acc;
      acc.LoadAllData(pThis, TRUE);
      FX_DWORD streamSize = acc.GetSize();
      CPDF_Dictionary* pDict = pThis->GetDict();
      if (pDict) {
        pDict = ToDictionary(pDict->CloneInternal(bDirect, visited));
      }
      return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
    }
    case PDFOBJ_REFERENCE: {
      const CPDF_Reference* pRef = AsReference();
      FX_DWORD obj_num = pRef->GetRefObjNum();
      if (bDirect && !pdfium::ContainsKey(*visited, obj_num)) {
        visited->insert(obj_num);
        auto* pDirect = pRef->GetDirect();
        return pDirect ? pDirect->CloneInternal(TRUE, visited) : nullptr;
      }
      return new CPDF_Reference(pRef->m_pObjList, obj_num);
    }
  }
  return NULL;
}
bool USocketIOClientComponent::CallBPFunctionWithResponse(UObject* Target, const FString& FunctionName, TArray<TSharedPtr<FJsonValue>> Response)
{
	if (!Target->IsValidLowLevel())
	{
		UE_LOG(SocketIOLog, Warning, TEXT("CallFunctionByNameWithArguments: Target not found for '%s'"), *FunctionName);
		return false;
	}

	UFunction* Function = Target->FindFunction(FName(*FunctionName));
	if (nullptr == Function)
	{
		UE_LOG(SocketIOLog, Warning, TEXT("CallFunctionByNameWithArguments: Function not found '%s'"), *FunctionName);
		return false;
	}

	//Check function signature
	TFieldIterator<UProperty> Iterator(Function);

	TArray<UProperty*> Properties;
	while (Iterator && (Iterator->PropertyFlags & CPF_Parm))
	{
		UProperty* Prop = *Iterator;
		Properties.Add(Prop);
		++Iterator;
	}

	auto ResponseJsonValue = USIOJConvert::ToSIOJsonValue(Response);

	bool bResponseNumNotZero = Response.Num() > 0;
	bool bNoFunctionParams = Properties.Num() == 0;
	bool bNullResponse = ResponseJsonValue->IsNull();

	if (bNullResponse && bNoFunctionParams)
	{
		Target->ProcessEvent(Function, nullptr);
		return true;
	}
	else if (bResponseNumNotZero)
	{
		//function has too few params
		if (bNoFunctionParams)
		{
			UE_LOG(SocketIOLog, Warning, TEXT("CallFunctionByNameWithArguments: Function '%s' has too few parameters, callback parameters ignored : <%s>"), *FunctionName, *ResponseJsonValue->EncodeJson());
			Target->ProcessEvent(Function, nullptr);
			return true;
		}
		struct FDynamicArgs
		{
			void* Arg01 = nullptr;
			USIOJsonValue* Arg02 = nullptr;
		};
		//create the container
		FDynamicArgs Args = FDynamicArgs();

		//add the full response array as second param
		Args.Arg02 = ResponseJsonValue;
		const FString& FirstParam = Properties[0]->GetCPPType();
		auto FirstFJsonValue = Response[0];

		//Is first param...
		//SIOJsonValue?
		if (FirstParam.Equals("USIOJsonValue*"))
		{
			//convenience wrapper, response is a single object
			USIOJsonValue* Value = NewObject<USIOJsonValue>();
			Value->SetRootValue(FirstFJsonValue);
			Args.Arg01 = Value;
			Target->ProcessEvent(Function, &Args);
			return true;
		}
		//SIOJsonObject?
		else if (FirstParam.Equals("USIOJsonObject*"))
		{
			//convenience wrapper, response is a single object
			USIOJsonObject* ObjectValue = NewObject<USIOJsonObject>();
			ObjectValue->SetRootObject(FirstFJsonValue->AsObject());
			Args.Arg01 = ObjectValue;
			Target->ProcessEvent(Function, &Args);
			return true;
		}
		//String?
		else if (FirstParam.Equals("FString"))
		{
			FString	StringValue = USIOJConvert::ToJsonString(FirstFJsonValue);
			
			Target->ProcessEvent(Function, &StringValue);
			return true;
		}
		//Float?
		else if (FirstParam.Equals("float"))
		{
			float NumberValue = (float)FirstFJsonValue->AsNumber();
			Target->ProcessEvent(Function, &NumberValue);
			return true;
		}
		//Int?
		else if (FirstParam.Equals("int32"))
		{
			int NumberValue = (int)FirstFJsonValue->AsNumber();
			Target->ProcessEvent(Function, &NumberValue);
			return true;
		}
		//bool?
		else if (FirstParam.Equals("bool"))
		{
			bool BoolValue = FirstFJsonValue->AsBool();
			Target->ProcessEvent(Function, &BoolValue);
			return true;
		}
		//array?
		else if (FirstParam.Equals("TArray"))
		{
			UArrayProperty* ArrayProp = Cast<UArrayProperty>(Properties[0]);

			FString Inner;
			ArrayProp->GetCPPMacroType(Inner);

			//byte array is the only supported version
			if (Inner.Equals("uint8"))
			{
				TArray<uint8> Bytes = ResponseJsonValue->AsArray()[0]->AsBinary();
				Target->ProcessEvent(Function, &Bytes);
				return true;
			}
		}
	}

	UE_LOG(SocketIOLog, Warning, TEXT("CallFunctionByNameWithArguments: Function '%s' signature not supported expected <%s>"), *FunctionName, *ResponseJsonValue->EncodeJson());
	return false;
}
示例#12
0
文件: debug.cpp 项目: ufasoft/lisp
void CLispEng::Print(ostream& os, CP form) {
	form &= ~FLAG_Mark;
	//!!!	os << "<" << (void*)form << ">";
	
	os << String(' ', m_printIndent*2);

	switch (Type(form)) {
		/*!!!  case TS_NIL:
		os << "NIL";
		break;*/
	case TS_CHARACTER:
		{
			os << "#\\";
			wchar_t ch = AsChar(form);
			switch (ch) {
			case '\0': os << "NULL"; break;
			case '\a': os << "BELL"; break;
			case '\b': os << "BS"; break;
			case '\t': os << "TAB"; break;
			case '\n': os << "NL"; break;
			case '\r': os << "CR"; break;
			case '\f': os << "FF"; break;
			case '\x1B': os << "ESC"; break;
			case '\x7F': os << "RUBOUT"; break;
			default: os << (char)ch; break; //!!!
			}
		}
		break;
	case TS_FIXNUM:
		os << AsNumber(form);
		break;
	case TS_FRAME_PTR:
		os << "#<FRAME " << (DWORD)AsIndex(form) << ">";
		break;
	case TS_FRAMEINFO:
		os << "#<FRAMEINFO>";
		break;
	case TS_BIGNUM:
		os << ToBigInteger(form);
		break;
	case TS_FLONUM:
		os << AsFloatVal(form);
		break;
	case TS_SYMBOL:
		{
			//!!!			Print(get_Special(L_S_PACKAGE));//!!!D
			CSymbolValue *sv = ToSymbol(form);
			if (sv->HomePackage == m_packKeyword)
				os << ':';
			else if (!sv->HomePackage)
				os << "#:";
			/*!!!      else if (!ToPackage(get_Special(L_S_PACKAGE))->IsPresent(form))
			{
			CPackage *pack = ToPackage(sv->HomePackage);
			os << pack->m_name << ':';
			if (pack->m_mapExternalSym.find(sv) == pack->m_mapExternalSym.end())
			os << ':';
			}*/
#if UCFG_LISP_SPLIT_SYM
			os << SymNameByIdx(AsIndex(form));
#else
			os << sv->m_s;
#endif
		}
		break;
	case TS_PATHNAME:
		os << "#P\"" << AsPathname(form)->ToString() << "\"";
		break;
	case TS_RATIO:
		Print(os, AsRatio(form)->m_numerator);
		os << "/";
		Print(os, AsRatio(form)->m_denominator);
		break;//!!!
	case TS_MACRO:
		os << "#<MACRO>";
		break;
	case TS_COMPLEX:
		os << "#C()"; //!!!
		break;
	case TS_CONS:
		switch (form) {
		case 0:
			os << "NIL";
			break;
		case V_U:
			os << "#<UNBOUND>";
			break;
		default:
			CSPtr car = Car(form),
				cdr = Cdr(form);
			if (car == S(L_QUOTE)) {
				if (ConsP(cdr)) {
					os << "\'";
					Print(os, Car(cdr));
					break;
				}
			}
			if (car == S(L_BACKQUOTE)) {
				os << "`";
				Print(os, Car(cdr));
			} else if (car == S(L_UNQUOTE)) {
				os << ",";
				Print(os, Car(cdr));
			} else if (car == S(L_SPLICE)) {
				os << ",@";
				Print(os, Car(cdr));
			} else {
				os << "(";
				PrintList(os, form);
				os << ")";
			}
		}
		break;
	case TS_STRUCT:
		os << "#<STRUCT " << (DWORD)AsIndex(form) << ">";
		break;
	case TS_STREAM:
		os << "#<STREAM " << (DWORD)AsIndex(form) << ">";
		break;
	case TS_WEAKPOINTER:
		os << "<#WEAKPOINTER ";
		Print(os, ToWeakPointer(form)->m_p);
		os << ">";
		break;
	case TS_SUBR:
	case TS_INTFUNC:
	case TS_CCLOSURE:
		{
			os << "#\'";
			Push(m_r);
			pair<CP, CP> pp = GetFunctionName(form);
			Print(os, pp.second);
			m_r = Pop();
		}
		break;
	case TS_PACKAGE:
		os << "#<PACKAGE " << ToPackage(form)->m_name << ">";
		break;
	case TS_READTABLE:
		os << "#<READTABLE>";
		break;
	case TS_HASHTABLE:
		{
			os << "#S(HASH-TABLE  <fun>";
			CHashMap& m = *Lisp().ToHashTable(form)->m_pMap;
			for (CHashMap::iterator i=m.begin(); i!=m.end(); ++i) {
				os << "(";
				Print(os, i->first);
				os << " . ";
				Print(os, i->second);
				os << ")";
			}
			os << ">";
		}
		break;
	case TS_ARRAY:
		if (StringP(form))
			os << "\"" << AsString(form) << "\"";
		else if (VectorP(form)) {
			os << "#(";
			CArrayValue *av = ToArray(form);
			for (size_t i=0; i<av->GetVectorLength(); i++) {
				if (i)
					os << " ";
				Print(os, av->GetElement(i));
			}
			os << ")";
		} else {
			CArrayValue *av = ToArray(form);
			os << "<ARRAY " << (DWORD)av->TotalSize() << ">";

			//!!!
			/*!!!        os << "#(";
			for (int i=0; i<vv->m_count-1; i++)
			{
			Print(vv->m_pData[i]);
			os << " ";
			}
			os << ")";*/
		}
		break;
	case TS_OBJECT:
		{
			os << "#<OBJECT ";
			//!!!      Print(ToObject(form)->m_class);
			os << " ";
			//!!!      Print(ToObject(form)->m_slots);
			os << ">";
		}
		break;
	case TS_SYMBOLMACRO:
		{
			os << "#<SYMBOL-MACRO ";
			CSymbolMacro *sm = ToSymbolMacro(form);
			Print(os, sm->m_macro);
			os << ">";
		}
		break;
#if UCFG_LISP_FFI
	case TS_FF_PTR:
		os << "#<POINTER " << ToPointer(form) << ">";
		break;
#endif

	default:
		os << "#<Bad Form>";
		//!!!    Ext::Throw(E_FAIL);
	}
}
示例#13
0
文件: debug.cpp 项目: ufasoft/lisp
void CVerifier::Verify(CP p) {
	CTypeSpec ts = Type(p);
	if (ts < TS_SYMBOL && (ts!=TS_CONS || p))
		return;
	CObMap::CVal& val = m_obMap.m_arP[g_arTS[ts]][AsIndex(p)];
	if (val.Flag)
		return;
	val.Flag = true;
	switch (ts) {
	case TS_FRAME_PTR:
		Throw(E_FAIL);
	case TS_CONS:
	case TS_RATIO:
	case TS_COMPLEX:
#if UCFG_LISP_BUILTIN_RANDOM_STATE
	case TS_RANDOMSTATE:
#endif
		{
			CConsValue *cons = Lisp().AsCons(p);
			Verify(cons->m_car);
			Verify(cons->m_cdr);
		}
		break;
	case TS_SYMBOL:
		{
			CSymbolValue *sv = ToSymbol(p);
			Verify(sv->GetFun());
			Verify(sv->GetPropList());
			Verify(sv->m_dynValue);
		}
		break;
	case TS_INTFUNC:
		{
			CIntFuncValue *ifv = Lisp().ToIntFunc(p);
			Verify(ifv->m_name);
			Verify(ifv->m_docstring);
			Verify(ifv->m_body);
			Verify(ifv->m_vars);
			Verify(ifv->m_optInits);
			Verify(ifv->m_keywords);
			Verify(ifv->m_keyInits);
			Verify(ifv->m_auxInits);
			Verify(ifv->m_env.m_varEnv);
			Verify(ifv->m_env.m_funEnv);
			Verify(ifv->m_env.m_blockEnv);
			Verify(ifv->m_env.m_goEnv);
			Verify(ifv->m_env.m_declEnv);
		}
		break;
	case TS_HASHTABLE:
		{
			CHashMap& m = *Lisp().ToHashTable(p)->m_pMap;
			Verify(m.m_func);
			for (CHashMap::iterator i=m.begin(); i!=m.end(); ++i) {
				Verify(i->first);
				Verify(i->second);
			}
		}
		break;
	case TS_STRUCT:
	case TS_OBJECT:
	case TS_ARRAY:
	case TS_CCLOSURE:
		{
			CArrayValue *av = Lisp().ToArray(p);
			Verify(av->m_displace);
			Verify(av->m_fillPointer);
			Verify(av->m_dims);
			if (!av->m_displace && av->m_elType == ELTYPE_T) {
				uintptr_t size = 1;
				for (CP p1=av->m_dims; p1;) {
					CConsValue *cons = Lisp().AsCons(p1);
					size *= AsNumber(cons->m_car);
					p1 = cons->m_cdr;
				}
				for (size_t i=0; i<size; ++i)
					Verify(av->m_pData[i]); 
			}
		}
		break;  
	case TS_PACKAGE:
		{
			CPackage *pack = ToPackage(p);
			Verify(pack->m_useList);  //!!!
			Verify(pack->m_docString);
		}
		break;
	}
}