本文整理汇总了C++中Environment::GetSignal方法的典型用法代码示例。如果您正苦于以下问题:C++ Environment::GetSignal方法的具体用法?C++ Environment::GetSignal怎么用?C++ Environment::GetSignal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::GetSignal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Prod
Value Iterator::Prod(Environment &env)
{
Signal &sig = env.GetSignal();
Value value;
if (!Next(env, value)) return Value::Nil;
if (!value.Is_number()) {
const Operator *pOperatorMul = env.GetOperator(OPTYPE_Mul);
Value valResult(value);
while (Next(env, value)) {
valResult = pOperatorMul->EvalBinary(env, valResult, value, FLAG_None);
if (sig.IsSignalled()) return Value::Nil;
}
return valResult;
}
Number result = value.GetNumber();
while (Next(env, value)) {
if (value.Is_number()) {
if (result == 0) break;
result *= value.GetNumber();
} else {
const Operator *pOperatorMul = env.GetOperator(OPTYPE_Mul);
Value valResult(result);
do {
valResult = pOperatorMul->EvalBinary(env, valResult, value, FLAG_None);
if (sig.IsSignalled()) return Value::Nil;
} while (Next(env, value));
return valResult;
}
}
return Value(result);
}
示例2: PutValue
bool Object_writer::PutValue(Environment &env, const Value &value)
{
Signal &sig = env.GetSignal();
String str;
if (value.IsInvalid()) {
return true;
} else if (value.Is_number()) {
str = Formatter::FormatValueList(sig, _format.c_str(), ValueList(value));
} else if (value.Is_complex()) {
str = Formatter::FormatValueList(sig, _format.c_str(), ValueList(value));
} else if (value.Is_string()) {
str += '"';
for (const char *p = value.GetString(); *p != '\0'; p++) {
char ch = *p;
str += ch;
if (ch == '"') str += ch;
}
str += '"';
} else {
sig.SetError(ERR_TypeError, "can't output in CSV format");
return false;
}
_pStreamDst->Print(sig, str.c_str());
return true;
}
示例3: FindMinMaxIndices
Value Iterator::FindMinMaxIndices(Environment &env, bool maxFlag)
{
Signal &sig = env.GetSignal();
if (IsInfinite()) {
SetError_InfiniteNotAllowed(sig);
return Value::Nil;
}
Value valueHit;
if (!Next(env, valueHit)) return Value::Nil;
Value result;
int idxHit = GetIndexCur();
Object_list *pObjListResult = result.InitAsList(env);
pObjListResult->Add(Value(idxHit));
Value value;
while (Next(env, value)) {
int cmp = Value::Compare(env, valueHit, value);
if (sig.IsSignalled()) return Value::Nil;
if (maxFlag) cmp = -cmp;
if (cmp > 0) {
int idxHit = GetIndexCur();
valueHit = value;
pObjListResult->Clear();
pObjListResult->Add(Value(idxHit));
} else if (cmp == 0) {
int idxHit = GetIndexCur();
pObjListResult->Add(Value(static_cast<Number>(idxHit)));
}
}
if (sig.IsSignalled()) return Value::Nil;
return result;
}
示例4: ToList
Value Iterator::ToList(Environment &env, bool alwaysListFlag, bool excludeNilFlag)
{
Signal &sig = env.GetSignal();
if (IsInfinite()) {
SetError_InfiniteNotAllowed(sig);
return Value::Nil;
}
Value result;
Object_list *pObjList = nullptr;
size_t cnt = 0;
Value value;
if (alwaysListFlag) {
pObjList = result.InitAsList(env);
}
while (Next(env, value)) {
if (pObjList == nullptr && !value.IsUndefined()) {
pObjList = result.InitAsList(env, cnt, Value::Nil);
}
if (value.IsValid()) {
if (pObjList == nullptr) {
pObjList = result.InitAsList(env, cnt, Value::Nil);
}
pObjList->Add(value);
} else if (excludeNilFlag) {
// nothing to do
} else if (pObjList != nullptr) {
pObjList->Add(value);
}
cnt++;
}
if (sig.IsSignalled()) return Value::Nil;
return result;
}
示例5: Reduce
Value Iterator::Reduce(Environment &env, Value valueAccum, const Function *pFuncBlock)
{
Signal &sig = env.GetSignal();
if (IsInfinite()) {
SetError_InfiniteNotAllowed(sig);
return Value::Nil;
}
Value value;
while (Next(env, value)) {
AutoPtr<Argument> pArgSub(new Argument(pFuncBlock));
if (!pArgSub->StoreValue(env, value, valueAccum)) return Value::Nil;
Value result = pFuncBlock->Eval(env, *pArgSub);
if (!sig.IsSignalled()) {
// nothing to do
} else if (sig.IsBreak()) {
result = sig.GetValue();
sig.ClearSignal();
if (result.IsValid()) return result;
return valueAccum;
} else if (sig.IsContinue()) {
result = sig.GetValue();
sig.ClearSignal();
if (result.IsInvalid()) continue;
} else if (sig.IsReturn()) {
return Value::Nil;
} else {
return Value::Nil;
}
valueAccum = result;
}
if (sig.IsSignalled()) return Value::Nil;
return valueAccum;
}
示例6: Count
size_t Iterator::Count(Environment &env, const Value &criteria)
{
Signal &sig = env.GetSignal();
if (IsInfinite()) {
SetError_InfiniteNotAllowed(sig);
return 0;
}
size_t cnt = 0;
if (criteria.Is_function()) {
const Function *pFunc = criteria.GetFunction();
Value value;
while (Next(env, value)) {
AutoPtr<Argument> pArg(new Argument(pFunc));
if (!pArg->StoreValue(env, value)) return 0;
Value valueFlag = pFunc->Eval(env, *pArg);
if (sig.IsSignalled()) return 0;
if (valueFlag.GetBoolean()) cnt++;
}
if (sig.IsSignalled()) return 0;
} else {
Value value;
while (Next(env, value)) {
int cmp = Value::Compare(env, value, criteria);
if (sig.IsSignalled()) return 0;
if (cmp == 0) cnt++;
}
}
return cnt;
}
示例7:
//-----------------------------------------------------------------------------
// Stream
//-----------------------------------------------------------------------------
Stream::Stream(Environment &env, ULong attr) :
_cntRef(1), _sig(env.GetSignal()), _attr(attr), _offsetCur(0), _blockingFlag(false),
_pCodec(Codec::CreateCodecNone(true, false))
{
_peek.buff = nullptr;
_peek.bytes = 0;
_peek.offsetRead = 0;
}
示例8: PrintlnEach
void Iterator::PrintlnEach(Environment &env, Stream *pStream)
{
Signal &sig = env.GetSignal();
Value value;
while (Next(env, value)) {
pStream->Println(sig, value.ToString(false).c_str());
if (sig.IsSignalled()) break;
}
}
示例9: Consume
bool Iterator::Consume(Environment &env)
{
Signal &sig = env.GetSignal();
if (IsInfinite()) {
SetError_InfiniteNotAllowed(sig);
return false;
}
Value value;
while (Next(env, value)) ;
return !sig.IsSignalled();
}
示例10: StandardDeviation
Value Iterator::StandardDeviation(Environment &env, size_t &cnt, bool populationFlag)
{
Signal &sig = env.GetSignal();
if (IsInfinite()) {
SetError_InfiniteNotAllowed(sig);
return Value::Nil;
}
Value valueVar = Clone()->Variance(env, cnt, populationFlag);
if (!valueVar.Is_number()) return Value::Nil;
return Value(::sqrt(valueVar.GetNumber()));
}
示例11: FindTrue
size_t Iterator::FindTrue(Environment &env, Value &value)
{
Signal &sig = env.GetSignal();
if (IsInfinite()) {
SetError_InfiniteNotAllowed(sig);
return 0;
}
while (Next(env, value)) {
if (value.GetBoolean()) return GetIndexCur();
}
return InvalidSize;
}
示例12: PrintfEach
void Iterator::PrintfEach(Environment &env, Stream *pStream, const char *format)
{
Signal &sig = env.GetSignal();
Value value;
while (Next(env, value)) {
if (value.Is_list()) {
pStream->PrintFmt(sig, format, value.GetList());
} else {
pStream->PrintFmt(sig, format, ValueList(value));
}
if (sig.IsSignalled()) break;
}
}
示例13: PutLine
bool Object_writer::PutLine(Environment &env, const ValueList &valList)
{
Signal &sig = env.GetSignal();
foreach_const (ValueList, pValue, valList) {
if (pValue != valList.begin()) {
_pStreamDst->PutChar(sig, ',');
if (sig.IsSignalled()) return false;
}
if (!PutValue(env, *pValue)) return false;
}
_pStreamDst->PutChar(sig, '\n');
return !sig.IsSignalled();
}
示例14: GetLengthEx
size_t Iterator::GetLengthEx(Environment &env)
{
if (IsFinitePredictable()) return GetLength();
Signal &sig = env.GetSignal();
if (IsInfinite()) {
SetError_InfiniteNotAllowed(sig);
return 0;
}
size_t len = 0;
AutoPtr<Iterator> pIterator(Clone());
Value value;
for ( ; pIterator->Next(env, value); len++) ;
return sig.IsSignalled()? 0 : len;
}
示例15: CountTrue
size_t Iterator::CountTrue(Environment &env)
{
Signal &sig = env.GetSignal();
if (IsInfinite()) {
SetError_InfiniteNotAllowed(sig);
return 0;
}
size_t cnt = 0;
Value value;
while (Next(env, value)) {
if (value.GetBoolean()) cnt++;
}
return cnt;
}