コード例 #1
0
MSBuiltinVector<Type>::MSBuiltinVector (unsigned int length_, const Type & filler_)
    : MSBaseVector<Type,MSAllocator<Type> > ((MSVectorImpl *)0)
{
    this->_pImpl = new MSBuiltinVectorImpl(&ops(),&ops(),length_,(void *)&filler_);
}
コード例 #2
0
void
nsCSSValue::AppendToString(nsCSSProperty aProperty, nsAString& aResult) const
{
  // eCSSProperty_UNKNOWN gets used for some recursive calls below.
  NS_ABORT_IF_FALSE((0 <= aProperty &&
                     aProperty <= eCSSProperty_COUNT_no_shorthands) ||
                    aProperty == eCSSProperty_UNKNOWN,
                    "property ID out of range");

  nsCSSUnit unit = GetUnit();
  if (unit == eCSSUnit_Null) {
    return;
  }

  if (eCSSUnit_String <= unit && unit <= eCSSUnit_Attr) {
    if (unit == eCSSUnit_Attr) {
      aResult.AppendLiteral("attr(");
    }
    nsAutoString  buffer;
    GetStringValue(buffer);
    if (unit == eCSSUnit_String) {
      nsStyleUtil::AppendEscapedCSSString(buffer, aResult);
    } else if (unit == eCSSUnit_Families) {
      // XXX We really need to do *some* escaping.
      aResult.Append(buffer);
    } else {
      nsStyleUtil::AppendEscapedCSSIdent(buffer, aResult);
    }
  }
  else if (eCSSUnit_Array <= unit && unit <= eCSSUnit_Steps) {
    switch (unit) {
      case eCSSUnit_Counter:  aResult.AppendLiteral("counter(");  break;
      case eCSSUnit_Counters: aResult.AppendLiteral("counters("); break;
      case eCSSUnit_Cubic_Bezier: aResult.AppendLiteral("cubic-bezier("); break;
      case eCSSUnit_Steps: aResult.AppendLiteral("steps("); break;
      default: break;
    }

    nsCSSValue::Array *array = GetArrayValue();
    bool mark = false;
    for (size_t i = 0, i_end = array->Count(); i < i_end; ++i) {
      if (mark && array->Item(i).GetUnit() != eCSSUnit_Null) {
        if (unit == eCSSUnit_Array &&
            eCSSProperty_transition_timing_function != aProperty)
          aResult.AppendLiteral(" ");
        else
          aResult.AppendLiteral(", ");
      }
      if (unit == eCSSUnit_Steps && i == 1) {
        NS_ABORT_IF_FALSE(array->Item(i).GetUnit() == eCSSUnit_Enumerated &&
                          (array->Item(i).GetIntValue() ==
                            NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_START ||
                           array->Item(i).GetIntValue() ==
                            NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_END),
                          "unexpected value");
        if (array->Item(i).GetIntValue() ==
              NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_START) {
          aResult.AppendLiteral("start");
        } else {
          aResult.AppendLiteral("end");
        }
        continue;
      }
      nsCSSProperty prop =
        ((eCSSUnit_Counter <= unit && unit <= eCSSUnit_Counters) &&
         i == array->Count() - 1)
        ? eCSSProperty_list_style_type : aProperty;
      if (array->Item(i).GetUnit() != eCSSUnit_Null) {
        array->Item(i).AppendToString(prop, aResult);
        mark = true;
      }
    }
    if (eCSSUnit_Array == unit &&
        aProperty == eCSSProperty_transition_timing_function) {
      aResult.AppendLiteral(")");
    }
  }
  /* Although Function is backed by an Array, we'll handle it separately
   * because it's a bit quirky.
   */
  else if (eCSSUnit_Function == unit) {
    const nsCSSValue::Array* array = GetArrayValue();
    NS_ABORT_IF_FALSE(array->Count() >= 1,
                      "Functions must have at least one element for the name.");

    /* Append the function name. */
    const nsCSSValue& functionName = array->Item(0);
    if (functionName.GetUnit() == eCSSUnit_Enumerated) {
      // We assume that the first argument is always of nsCSSKeyword type.
      const nsCSSKeyword functionId =
        static_cast<nsCSSKeyword>(functionName.GetIntValue());
      nsStyleUtil::AppendEscapedCSSIdent(
        NS_ConvertASCIItoUTF16(nsCSSKeywords::GetStringValue(functionId)),
        aResult);
    } else {
      functionName.AppendToString(aProperty, aResult);
    }
    aResult.AppendLiteral("(");

    /* Now, step through the function contents, writing each of them as we go. */
    for (size_t index = 1; index < array->Count(); ++index) {
      array->Item(index).AppendToString(aProperty, aResult);

      /* If we're not at the final element, append a comma. */
      if (index + 1 != array->Count())
        aResult.AppendLiteral(", ");
    }

    /* Finally, append the closing parenthesis. */
    aResult.AppendLiteral(")");
  }
  else if (IsCalcUnit()) {
    NS_ABORT_IF_FALSE(GetUnit() == eCSSUnit_Calc, "unexpected unit");
    CSSValueSerializeCalcOps ops(aProperty, aResult);
    css::SerializeCalc(*this, ops);
  }
  else if (eCSSUnit_Integer == unit) {
    aResult.AppendInt(GetIntValue(), 10);
  }
  else if (eCSSUnit_Enumerated == unit) {
    if (eCSSProperty_text_decoration_line == aProperty) {
      PRInt32 intValue = GetIntValue();
      if (NS_STYLE_TEXT_DECORATION_LINE_NONE == intValue) {
        AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue),
                           aResult);
      } else {
        // Ignore the "override all" internal value.
        // (It doesn't have a string representation.)
        intValue &= ~NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL;
        nsStyleUtil::AppendBitmaskCSSValue(
          aProperty, intValue,
          NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE,
          NS_STYLE_TEXT_DECORATION_LINE_PREF_ANCHORS,
          aResult);
      }
    }
    else if (eCSSProperty_marks == aProperty) {
      PRInt32 intValue = GetIntValue();
      if (intValue == NS_STYLE_PAGE_MARKS_NONE) {
        AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue),
                           aResult);
      } else {
        nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue,
                                           NS_STYLE_PAGE_MARKS_CROP,
                                           NS_STYLE_PAGE_MARKS_REGISTER,
                                           aResult);
      }
    }
    else if (eCSSProperty_unicode_bidi == aProperty) {
      PR_STATIC_ASSERT(NS_STYLE_UNICODE_BIDI_NORMAL == 0);
      PRInt32 intValue = GetIntValue();
      if (NS_STYLE_UNICODE_BIDI_NORMAL == intValue) {
        AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue),
                           aResult);
      } else {
        nsStyleUtil::AppendBitmaskCSSValue(
          aProperty, intValue,
          NS_STYLE_UNICODE_BIDI_EMBED,
          NS_STYLE_UNICODE_BIDI_PLAINTEXT,
          aResult);
      }
    }
    else {
      const nsAFlatCString& name = nsCSSProps::LookupPropertyValue(aProperty, GetIntValue());
      AppendASCIItoUTF16(name, aResult);
    }
  }
  else if (eCSSUnit_EnumColor == unit) {
    // we can lookup the property in the ColorTable and then
    // get a string mapping the name
    nsCAutoString str;
    if (nsCSSProps::GetColorName(GetIntValue(), str)){
      AppendASCIItoUTF16(str, aResult);
    } else {
      NS_ABORT_IF_FALSE(false, "bad color value");
    }
  }
  else if (eCSSUnit_Color == unit) {
    nscolor color = GetColorValue();
    if (color == NS_RGBA(0, 0, 0, 0)) {
      // Use the strictest match for 'transparent' so we do correct
      // round-tripping of all other rgba() values.
      aResult.AppendLiteral("transparent");
    } else {
      PRUint8 a = NS_GET_A(color);
      if (a < 255) {
        aResult.AppendLiteral("rgba(");
      } else {
        aResult.AppendLiteral("rgb(");
      }

      NS_NAMED_LITERAL_STRING(comma, ", ");

      aResult.AppendInt(NS_GET_R(color), 10);
      aResult.Append(comma);
      aResult.AppendInt(NS_GET_G(color), 10);
      aResult.Append(comma);
      aResult.AppendInt(NS_GET_B(color), 10);
      if (a < 255) {
        aResult.Append(comma);
        aResult.AppendFloat(nsStyleUtil::ColorComponentToFloat(a));
      }
      aResult.Append(PRUnichar(')'));
    }
  }
  else if (eCSSUnit_URL == unit || eCSSUnit_Image == unit) {
    aResult.Append(NS_LITERAL_STRING("url("));
    nsStyleUtil::AppendEscapedCSSString(
      nsDependentString(GetOriginalURLValue()), aResult);
    aResult.Append(NS_LITERAL_STRING(")"));
  }
  else if (eCSSUnit_Element == unit) {
    aResult.Append(NS_LITERAL_STRING("-moz-element(#"));
    nsAutoString tmpStr;
    GetStringValue(tmpStr);
    nsStyleUtil::AppendEscapedCSSIdent(tmpStr, aResult);
    aResult.Append(NS_LITERAL_STRING(")"));
  }
  else if (eCSSUnit_Percent == unit) {
    aResult.AppendFloat(GetPercentValue() * 100.0f);
  }
  else if (eCSSUnit_Percent < unit) {  // length unit
    aResult.AppendFloat(GetFloatValue());
  }
  else if (eCSSUnit_Gradient == unit) {
    nsCSSValueGradient* gradient = GetGradientValue();

    if (gradient->mIsRepeating) {
      if (gradient->mIsRadial)
        aResult.AppendLiteral("-moz-repeating-radial-gradient(");
      else
        aResult.AppendLiteral("-moz-repeating-linear-gradient(");
    } else {
      if (gradient->mIsRadial)
        aResult.AppendLiteral("-moz-radial-gradient(");
      else
        aResult.AppendLiteral("-moz-linear-gradient(");
    }

    if (gradient->mIsToCorner) {
      aResult.AppendLiteral("to");
      NS_ABORT_IF_FALSE(gradient->mBgPos.mXValue.GetUnit() == eCSSUnit_Enumerated &&
                        gradient->mBgPos.mYValue.GetUnit() == eCSSUnit_Enumerated,
                        "unexpected unit");
      if (!(gradient->mBgPos.mXValue.GetIntValue() & NS_STYLE_BG_POSITION_CENTER)) {
        aResult.AppendLiteral(" ");
        gradient->mBgPos.mXValue.AppendToString(eCSSProperty_background_position,
                                                aResult);
      }
      if (!(gradient->mBgPos.mYValue.GetIntValue() & NS_STYLE_BG_POSITION_CENTER)) {
        aResult.AppendLiteral(" ");
        gradient->mBgPos.mYValue.AppendToString(eCSSProperty_background_position,
                                                aResult);
      }
      aResult.AppendLiteral(", ");
    } else if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None ||
        gradient->mBgPos.mYValue.GetUnit() != eCSSUnit_None ||
        gradient->mAngle.GetUnit() != eCSSUnit_None) {
      if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None) {
        gradient->mBgPos.mXValue.AppendToString(eCSSProperty_background_position,
                                                aResult);
        aResult.AppendLiteral(" ");
      }
      if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None) {
        gradient->mBgPos.mYValue.AppendToString(eCSSProperty_background_position,
                                                aResult);
        aResult.AppendLiteral(" ");
      }
      if (gradient->mAngle.GetUnit() != eCSSUnit_None) {
        gradient->mAngle.AppendToString(aProperty, aResult);
      }
      aResult.AppendLiteral(", ");
    }

    if (gradient->mIsRadial &&
        (gradient->mRadialShape.GetUnit() != eCSSUnit_None ||
         gradient->mRadialSize.GetUnit() != eCSSUnit_None)) {
      if (gradient->mRadialShape.GetUnit() != eCSSUnit_None) {
        NS_ABORT_IF_FALSE(gradient->mRadialShape.GetUnit() ==
                          eCSSUnit_Enumerated,
                          "bad unit for radial gradient shape");
        PRInt32 intValue = gradient->mRadialShape.GetIntValue();
        NS_ABORT_IF_FALSE(intValue != NS_STYLE_GRADIENT_SHAPE_LINEAR,
                          "radial gradient with linear shape?!");
        AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(intValue,
                               nsCSSProps::kRadialGradientShapeKTable),
                           aResult);
        aResult.AppendLiteral(" ");
      }

      if (gradient->mRadialSize.GetUnit() != eCSSUnit_None) {
        NS_ABORT_IF_FALSE(gradient->mRadialSize.GetUnit() ==
                          eCSSUnit_Enumerated,
                          "bad unit for radial gradient size");
        PRInt32 intValue = gradient->mRadialSize.GetIntValue();
        AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(intValue,
                               nsCSSProps::kRadialGradientSizeKTable),
                           aResult);
      }
      aResult.AppendLiteral(", ");
    }

    for (PRUint32 i = 0 ;;) {
      gradient->mStops[i].mColor.AppendToString(aProperty, aResult);
      if (gradient->mStops[i].mLocation.GetUnit() != eCSSUnit_None) {
        aResult.AppendLiteral(" ");
        gradient->mStops[i].mLocation.AppendToString(aProperty, aResult);
      }
      if (++i == gradient->mStops.Length()) {
        break;
      }
      aResult.AppendLiteral(", ");
    }

    aResult.AppendLiteral(")");
  } else if (eCSSUnit_Pair == unit) {
    GetPairValue().AppendToString(aProperty, aResult);
  } else if (eCSSUnit_Triplet == unit) {
    GetTripletValue().AppendToString(aProperty, aResult);
  } else if (eCSSUnit_Rect == unit) {
    GetRectValue().AppendToString(aProperty, aResult);
  } else if (eCSSUnit_List == unit || eCSSUnit_ListDep == unit) {
    GetListValue()->AppendToString(aProperty, aResult);
  } else if (eCSSUnit_PairList == unit || eCSSUnit_PairListDep == unit) {
    GetPairListValue()->AppendToString(aProperty, aResult);
  }

  switch (unit) {
    case eCSSUnit_Null:         break;
    case eCSSUnit_Auto:         aResult.AppendLiteral("auto");     break;
    case eCSSUnit_Inherit:      aResult.AppendLiteral("inherit");  break;
    case eCSSUnit_Initial:      aResult.AppendLiteral("-moz-initial"); break;
    case eCSSUnit_None:         aResult.AppendLiteral("none");     break;
    case eCSSUnit_Normal:       aResult.AppendLiteral("normal");   break;
    case eCSSUnit_System_Font:  aResult.AppendLiteral("-moz-use-system-font"); break;
    case eCSSUnit_All:          aResult.AppendLiteral("all"); break;
    case eCSSUnit_Dummy:
    case eCSSUnit_DummyInherit:
      NS_ABORT_IF_FALSE(false, "should never serialize");
      break;

    case eCSSUnit_String:       break;
    case eCSSUnit_Ident:        break;
    case eCSSUnit_Families:     break;
    case eCSSUnit_URL:          break;
    case eCSSUnit_Image:        break;
    case eCSSUnit_Element:      break;
    case eCSSUnit_Array:        break;
    case eCSSUnit_Attr:
    case eCSSUnit_Cubic_Bezier:
    case eCSSUnit_Steps:
    case eCSSUnit_Counter:
    case eCSSUnit_Counters:     aResult.Append(PRUnichar(')'));    break;
    case eCSSUnit_Local_Font:   break;
    case eCSSUnit_Font_Format:  break;
    case eCSSUnit_Function:     break;
    case eCSSUnit_Calc:         break;
    case eCSSUnit_Calc_Plus:    break;
    case eCSSUnit_Calc_Minus:   break;
    case eCSSUnit_Calc_Times_L: break;
    case eCSSUnit_Calc_Times_R: break;
    case eCSSUnit_Calc_Divided: break;
    case eCSSUnit_Integer:      break;
    case eCSSUnit_Enumerated:   break;
    case eCSSUnit_EnumColor:    break;
    case eCSSUnit_Color:        break;
    case eCSSUnit_Percent:      aResult.Append(PRUnichar('%'));    break;
    case eCSSUnit_Number:       break;
    case eCSSUnit_Gradient:     break;
    case eCSSUnit_Pair:         break;
    case eCSSUnit_Triplet:      break;
    case eCSSUnit_Rect:         break;
    case eCSSUnit_List:         break;
    case eCSSUnit_ListDep:      break;
    case eCSSUnit_PairList:     break;
    case eCSSUnit_PairListDep:  break;

    case eCSSUnit_Inch:         aResult.AppendLiteral("in");   break;
    case eCSSUnit_Millimeter:   aResult.AppendLiteral("mm");   break;
    case eCSSUnit_PhysicalMillimeter: aResult.AppendLiteral("mozmm");   break;
    case eCSSUnit_Centimeter:   aResult.AppendLiteral("cm");   break;
    case eCSSUnit_Point:        aResult.AppendLiteral("pt");   break;
    case eCSSUnit_Pica:         aResult.AppendLiteral("pc");   break;

    case eCSSUnit_EM:           aResult.AppendLiteral("em");   break;
    case eCSSUnit_XHeight:      aResult.AppendLiteral("ex");   break;
    case eCSSUnit_Char:         aResult.AppendLiteral("ch");   break;
    case eCSSUnit_RootEM:       aResult.AppendLiteral("rem");  break;

    case eCSSUnit_Pixel:        aResult.AppendLiteral("px");   break;

    case eCSSUnit_Degree:       aResult.AppendLiteral("deg");  break;
    case eCSSUnit_Grad:         aResult.AppendLiteral("grad"); break;
    case eCSSUnit_Radian:       aResult.AppendLiteral("rad");  break;

    case eCSSUnit_Hertz:        aResult.AppendLiteral("Hz");   break;
    case eCSSUnit_Kilohertz:    aResult.AppendLiteral("kHz");  break;

    case eCSSUnit_Seconds:      aResult.Append(PRUnichar('s'));    break;
    case eCSSUnit_Milliseconds: aResult.AppendLiteral("ms");   break;
  }
}
コード例 #3
0
ファイル: wts_ops.c プロジェクト: qixin/wiredtiger
/*
 * wts_ops --
 *	Perform a number of operations in a set of threads.
 */
void
wts_ops(void)
{
	TINFO *tinfo, total;
	WT_CONNECTION *conn;
	WT_SESSION *session;
	time_t now;
	int ret, running;
	uint32_t i;

	conn = g.wts_conn;

	/* Open a session. */
	session = NULL;
	if (g.logging == LOG_OPS) {
		if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
			die(ret, "connection.open_session");

		(void)time(&now);
		(void)session->msg_printf(session,
		    "===============\nthread ops start: %s===============",
		    ctime(&now));
	}

	if (SINGLETHREADED) {
		memset(&total, 0, sizeof(total));
		total.id = 1;
		(void)ops(&total);
	} else {
		/* Create thread structure. */
		if ((tinfo =
		    calloc((size_t)g.c_threads, sizeof(*tinfo))) == NULL)
			die(errno, "calloc");
		for (i = 0; i < g.c_threads; ++i) {
			tinfo[i].id = (int)i + 1;
			tinfo[i].state = TINFO_RUNNING;
			if ((ret = pthread_create(
			    &tinfo[i].tid, NULL, ops, &tinfo[i])) != 0)
				die(ret, "pthread_create");
		}

		/* Wait for the threads. */
		for (;;) {
			total.search =
			    total.insert = total.remove = total.update = 0;
			for (i = running = 0; i < g.c_threads; ++i) {
				total.search += tinfo[i].search;
				total.insert += tinfo[i].insert;
				total.remove += tinfo[i].remove;
				total.update += tinfo[i].update;
				switch (tinfo[i].state) {
				case TINFO_RUNNING:
					running = 1;
					break;
				case TINFO_COMPLETE:
					tinfo[i].state = TINFO_JOINED;
					(void)pthread_join(tinfo[i].tid, NULL);
					break;
				case TINFO_JOINED:
					break;
				}
			}
			track("read/write ops", 0ULL, &total);
			if (!running)
				break;
			(void)usleep(100000);		/* 1/10th of a second */
		}
		free(tinfo);
	}

	if (session != NULL) {
		(void)time(&now);
		(void)session->msg_printf(session,
		    "===============\nthread ops stop: %s===============",
		    ctime(&now));

		if ((ret = session->close(session, NULL)) != 0)
			die(ret, "session.close");
	}
}
コード例 #4
0
 OpenGlVec<T,N> 
 operator-(const T& val) const { return ops(minus, val); }
コード例 #5
0
 OpenGlVec<T,N>
 operator/(const T& val) const { return ops(div, val); }
コード例 #6
0
 OpenGlVec<T,N> 
 operator*(const T& scal) const { return ops(times, scal); }
コード例 #7
0
 OpenGlVec<T,N> 
 operator+(const T& val) const { return ops(add, val); }
コード例 #8
0
ファイル: MSIndexVector.C プロジェクト: PlanetAPL/a-plus
MSIndexVector::MSIndexVector() : MSVector()
{
  _pImpl = new MSBuiltinVectorImpl(&ops(),&ops());
}
コード例 #9
0
ファイル: MSIndexVector.C プロジェクト: PlanetAPL/a-plus
MSIndexVector::MSIndexVector (unsigned int length_) : MSVector()
{
  _pImpl = new MSBuiltinVectorImpl(&ops(),&ops(),length_);
}
コード例 #10
0
ファイル: ops.c プロジェクト: RolfAndreassen/wiredtiger
/*
 * wts_ops --
 *	Perform a number of operations in a set of threads.
 */
void
wts_ops(void)
{
	TINFO *tinfo, total;
	WT_CONNECTION *conn;
	WT_SESSION *session;
	pthread_t backup_tid, compact_tid;
	int ret, running;
	uint32_t i;

	conn = g.wts_conn;

	/*
	 * We support replay of threaded runs, but don't log random numbers
	 * after threaded operations start, there's no point.
	 */
	if (!SINGLETHREADED)
		g.rand_log_stop = 1;

	/* Initialize the table extension code. */
	table_append_init();

	/* Open a session. */
	if (g.logging != 0) {
		if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
			die(ret, "connection.open_session");
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "=============== thread ops start ===============");
	}

	if (SINGLETHREADED) {
		memset(&total, 0, sizeof(total));
		total.id = 1;
		(void)ops(&total);
	} else {
		g.threads_finished = 0;

		/*
		 * Create thread structure; start worker, backup, compaction
		 * threads.
		 */
		if ((tinfo =
		    calloc((size_t)g.c_threads, sizeof(*tinfo))) == NULL)
			die(errno, "calloc");
		for (i = 0; i < g.c_threads; ++i) {
			tinfo[i].id = (int)i + 1;
			tinfo[i].state = TINFO_RUNNING;
			if ((ret = pthread_create(
			    &tinfo[i].tid, NULL, ops, &tinfo[i])) != 0)
				die(ret, "pthread_create");
		}
		if ((ret =
		    pthread_create(&backup_tid, NULL, hot_backup, NULL)) != 0)
			die(ret, "pthread_create");
		if (g.c_compact && (ret =
		    pthread_create(&compact_tid, NULL, compact, NULL)) != 0)
			die(ret, "pthread_create");

		/* Wait for the threads. */
		for (;;) {
			total.commit = total.deadlock = total.insert =
			    total.remove = total.rollback = total.search =
			    total.update = 0;
			for (i = 0, running = 0; i < g.c_threads; ++i) {
				total.commit += tinfo[i].commit;
				total.deadlock += tinfo[i].deadlock;
				total.insert += tinfo[i].insert;
				total.remove += tinfo[i].remove;
				total.rollback += tinfo[i].rollback;
				total.search += tinfo[i].search;
				total.update += tinfo[i].update;
				switch (tinfo[i].state) {
				case TINFO_RUNNING:
					running = 1;
					break;
				case TINFO_COMPLETE:
					tinfo[i].state = TINFO_JOINED;
					(void)pthread_join(tinfo[i].tid, NULL);
					break;
				case TINFO_JOINED:
					break;
				}
			}
			track("ops", 0ULL, &total);
			if (!running)
				break;
			(void)usleep(100000);		/* 1/10th of a second */
		}
		free(tinfo);

		/* Wait for the backup, compaction thread. */
		g.threads_finished = 1;
		(void)pthread_join(backup_tid, NULL);
		if (g.c_compact)
			(void)pthread_join(compact_tid, NULL);
	}

	if (g.logging != 0) {
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "=============== thread ops stop ===============");
		if ((ret = session->close(session, NULL)) != 0)
			die(ret, "session.close");
	}
}
コード例 #11
0
void
Restore::execREAD_CONFIG_REQ(Signal* signal)
{
  jamEntry();
  const ReadConfigReq * req = (ReadConfigReq*)signal->getDataPtr();
  Uint32 ref = req->senderRef;
  Uint32 senderData = req->senderData;
  ndbrequire(req->noOfParameters == 0);

  const ndb_mgm_configuration_iterator * p = 
    m_ctx.m_config.getOwnConfigIterator();
  ndbrequire(p != 0);

#if 0
  Uint32 noBackups = 0, noTables = 0, noAttribs = 0;
  ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DB_DISCLESS, &m_diskless));
  ndb_mgm_get_int_parameter(p, CFG_DB_PARALLEL_BACKUPS, &noBackups);
  //  ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DB_NO_TABLES, &noTables));
  ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DICT_TABLE, &noTables));
  ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DB_NO_ATTRIBUTES, &noAttribs));

  noAttribs++; //RT 527 bug fix

  c_backupPool.setSize(noBackups);
  c_backupFilePool.setSize(3 * noBackups);
  c_tablePool.setSize(noBackups * noTables);
  c_attributePool.setSize(noBackups * noAttribs);
  c_triggerPool.setSize(noBackups * 3 * noTables);

  // 2 = no of replicas
  c_fragmentPool.setSize(noBackups * NO_OF_FRAG_PER_NODE * noTables);
  
  Uint32 szMem = 0;
  ndb_mgm_get_int_parameter(p, CFG_DB_BACKUP_MEM, &szMem);
  Uint32 noPages = (szMem + sizeof(Page32) - 1) / sizeof(Page32);
  // We need to allocate an additional of 2 pages. 1 page because of a bug in
  // ArrayPool and another one for DICTTAINFO.
  c_pagePool.setSize(noPages + NO_OF_PAGES_META_FILE + 2); 

  Uint32 szDataBuf = (2 * 1024 * 1024);
  Uint32 szLogBuf = (2 * 1024 * 1024);
  Uint32 szWrite = 32768;
  ndb_mgm_get_int_parameter(p, CFG_DB_BACKUP_DATA_BUFFER_MEM, &szDataBuf);
  ndb_mgm_get_int_parameter(p, CFG_DB_BACKUP_LOG_BUFFER_MEM, &szLogBuf);
  ndb_mgm_get_int_parameter(p, CFG_DB_BACKUP_WRITE_SIZE, &szWrite);
  
  c_defaults.m_logBufferSize = szLogBuf;
  c_defaults.m_dataBufferSize = szDataBuf;
  c_defaults.m_minWriteSize = szWrite;
  c_defaults.m_maxWriteSize = szWrite;
  
  { // Init all tables
    ArrayList<Table> tables(c_tablePool);
    TablePtr ptr;
    while(tables.seize(ptr)){
      new (ptr.p) Table(c_attributePool, c_fragmentPool);
    }
    tables.release();
  }

  {
    ArrayList<BackupFile> ops(c_backupFilePool);
    BackupFilePtr ptr;
    while(ops.seize(ptr)){
      new (ptr.p) BackupFile(* this, c_pagePool);
    }
    ops.release();
  }
  
  {
    ArrayList<BackupRecord> recs(c_backupPool);
    BackupRecordPtr ptr;
    while(recs.seize(ptr)){
      new (ptr.p) BackupRecord(* this, c_pagePool, c_tablePool, 
			       c_backupFilePool, c_triggerPool);
    }
    recs.release();
  }

  // Initialize BAT for interface to file system
  {
    Page32Ptr p;
    ndbrequire(c_pagePool.seizeId(p, 0));
    c_startOfPages = (Uint32 *)p.p;
    c_pagePool.release(p);
    
    NewVARIABLE* bat = allocateBat(1);
    bat[0].WA = c_startOfPages;
    bat[0].nrr = c_pagePool.getSize()*sizeof(Page32)/sizeof(Uint32);
  }
#endif
  m_file_pool.setSize(1);
  Uint32 cnt = 2*MAX_ATTRIBUTES_IN_TABLE;
  cnt += PAGES;
  cnt += List::getSegmentSize()-1;
  cnt /= List::getSegmentSize();
  cnt += 2;
  m_databuffer_pool.setSize(cnt);
  
  ReadConfigConf * conf = (ReadConfigConf*)signal->getDataPtrSend();
  conf->senderRef = reference();
  conf->senderData = senderData;
  sendSignal(ref, GSN_READ_CONFIG_CONF, signal, 
	     ReadConfigConf::SignalLength, JBB);
}
コード例 #12
0
ファイル: dialogs.c プロジェクト: Efreak/elinks
	get_cache_entry_root,    \
	matchfn,                 \
	can_delete_cache_entry,  \
	delete_cache_entry_item, \
	NULL,                    \
	&cache_messages,

/* Each hierbox window is represented by an instance of struct hierbox,
 * which has a corresponding instance of struct listbox_data.  That
 * instance of struct listbox_data will point one of the following two
 * struct listbox_ops instances depending on which type of search the
 * user is performing in that hierbox.  The two struct listbox_ops
 * instances differ only in the match callback. */

const static struct listbox_ops cache_entry_listbox_ops_match_contents = {
	ops(match_cache_entry_contents)
};

const static struct listbox_ops cache_entry_listbox_ops = {
	ops(match_cache_entry)
};

#undef ops

static widget_handler_status_T
push_cache_hierbox_search_button(struct dialog_data *dlg_data, struct widget_data *button)
{
	struct listbox_data *box = get_dlg_listbox_data(dlg_data);

	box->ops = &cache_entry_listbox_ops;
コード例 #13
0
MSBuiltinVector<Type>::MSBuiltinVector (MSTypeData<Type,MSAllocator<Type> > *pData_, unsigned int len_)
    : MSBaseVector<Type,MSAllocator<Type> > ((MSVectorImpl *)0)
{
    this->_pImpl = new MSBuiltinVectorImpl(&ops(),&ops(),pData_,len_);
}
コード例 #14
0
MSBuiltinVector<Type>::MSBuiltinVector (const char * pString_) : MSBaseVector<Type,MSAllocator<Type> > ((MSVectorImpl *)0)
{
    this->_pImpl = new MSBuiltinVectorImpl(&ops(),&ops());
    this->_pImpl->setFromString (pString_);
}
コード例 #15
0
ファイル: parameter_validation.cpp プロジェクト: Aand1/ROSCH
TEST(ParameterValidation, advertiseStarDataType)
{
  ros::NodeHandle nh;
  ros::AdvertiseOptions ops("blah", 0, "blah", "*", "blah");
  ASSERT_THROWS(nh.advertise(ops));
}
コード例 #16
0
ファイル: MSIndexVector.C プロジェクト: PlanetAPL/a-plus
MSIndexVector::MSIndexVector (unsigned int length_, const unsigned int filler_) : MSVector()
{
  _pImpl = new MSBuiltinVectorImpl(&ops(), &ops(), length_, (void *)&filler_);
}
コード例 #17
0
void
Backup::execREAD_CONFIG_REQ(Signal* signal)
{
  const ReadConfigReq * req = (ReadConfigReq*)signal->getDataPtr();
  Uint32 ref = req->senderRef;
  Uint32 senderData = req->senderData;
  ndbrequire(req->noOfParameters == 0);

  const ndb_mgm_configuration_iterator * p = 
    m_ctx.m_config.getOwnConfigIterator();
  ndbrequire(p != 0);

  c_defaults.m_disk_write_speed = 10 * (1024 * 1024);
  c_defaults.m_disk_write_speed_sr = 100 * (1024 * 1024);
  c_defaults.m_disk_synch_size = 4 * (1024 * 1024);
  c_defaults.m_o_direct = true;

  Uint32 noBackups = 0, noTables = 0, noAttribs = 0, noFrags = 0;
  ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DB_DISCLESS, 
					&c_defaults.m_diskless));
  ndb_mgm_get_int_parameter(p, CFG_DB_O_DIRECT,
                            &c_defaults.m_o_direct);
  ndb_mgm_get_int_parameter(p, CFG_DB_CHECKPOINT_SPEED_SR,
			    &c_defaults.m_disk_write_speed_sr);
  ndb_mgm_get_int_parameter(p, CFG_DB_CHECKPOINT_SPEED,
			    &c_defaults.m_disk_write_speed);
  ndb_mgm_get_int_parameter(p, CFG_DB_DISK_SYNCH_SIZE,
			    &c_defaults.m_disk_synch_size);
  ndb_mgm_get_int_parameter(p, CFG_DB_COMPRESSED_BACKUP,
			    &c_defaults.m_compressed_backup);
  ndb_mgm_get_int_parameter(p, CFG_DB_COMPRESSED_LCP,
			    &c_defaults.m_compressed_lcp);

  m_backup_report_frequency = 0;
  ndb_mgm_get_int_parameter(p, CFG_DB_BACKUP_REPORT_FREQUENCY, 
			    &m_backup_report_frequency);
  /*
    We adjust the disk speed parameters from bytes per second to rather be
    words per 100 milliseconds. We convert disk synch size from bytes per
    second to words per second.
  */
  c_defaults.m_disk_write_speed /= (4 * 10);
  c_defaults.m_disk_write_speed_sr /= (4 * 10);

  ndb_mgm_get_int_parameter(p, CFG_DB_PARALLEL_BACKUPS, &noBackups);
  //  ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DB_NO_TABLES, &noTables));
  ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DICT_TABLE, &noTables));
  ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DB_NO_ATTRIBUTES, &noAttribs));
  ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DIH_FRAG_CONNECT, &noFrags));

  noAttribs++; //RT 527 bug fix

  c_nodePool.setSize(MAX_NDB_NODES);
  c_backupPool.setSize(noBackups + 1);
  c_backupFilePool.setSize(3 * noBackups + 1);
  c_tablePool.setSize(noBackups * noTables + 1);
  c_triggerPool.setSize(noBackups * 3 * noTables);
  c_fragmentPool.setSize(noBackups * noFrags + 1);
  
  Uint32 szDataBuf = (2 * 1024 * 1024);
  Uint32 szLogBuf = (2 * 1024 * 1024);
  Uint32 szWrite = 32768, maxWriteSize = (256 * 1024);
  ndb_mgm_get_int_parameter(p, CFG_DB_BACKUP_DATA_BUFFER_MEM, &szDataBuf);
  ndb_mgm_get_int_parameter(p, CFG_DB_BACKUP_LOG_BUFFER_MEM, &szLogBuf);
  ndb_mgm_get_int_parameter(p, CFG_DB_BACKUP_WRITE_SIZE, &szWrite);
  ndb_mgm_get_int_parameter(p, CFG_DB_BACKUP_MAX_WRITE_SIZE, &maxWriteSize);

  if (maxWriteSize < szWrite)
  {
    /**
     * max can't be lower than min
     */
    maxWriteSize = szWrite;
  }
  if ((maxWriteSize % szWrite) != 0)
  {
    /**
     * max needs to be a multiple of min
     */
    maxWriteSize = (maxWriteSize + szWrite - 1) / szWrite;
    maxWriteSize *= szWrite;
  }

  /**
   * add min writesize to buffer size...and the alignment added here and there
   */
  Uint32 extra = szWrite + 4 * (/* align * 512b */ 128);

  szDataBuf += extra;
  szLogBuf += extra;

  c_defaults.m_logBufferSize = szLogBuf;
  c_defaults.m_dataBufferSize = szDataBuf;
  c_defaults.m_minWriteSize = szWrite;
  c_defaults.m_maxWriteSize = maxWriteSize;
  c_defaults.m_lcp_buffer_size = szDataBuf;

  Uint32 szMem = 0;
  ndb_mgm_get_int_parameter(p, CFG_DB_BACKUP_MEM, &szMem);

  szMem += 3 * extra; // (data+log+lcp);
  Uint32 noPages =
    (szMem + sizeof(Page32) - 1) / sizeof(Page32) +
    (c_defaults.m_lcp_buffer_size + sizeof(Page32) - 1) / sizeof(Page32);

  // We need to allocate an additional of 2 pages. 1 page because of a bug in
  // ArrayPool and another one for DICTTAINFO.
  c_pagePool.setSize(noPages + NO_OF_PAGES_META_FILE + 2, true); 
  
  { // Init all tables
    SLList<Table> tables(c_tablePool);
    TablePtr ptr;
    while (tables.seizeFirst(ptr)){
      new (ptr.p) Table(c_fragmentPool);
    }
    while (tables.releaseFirst());
  }

  {
    SLList<BackupFile> ops(c_backupFilePool);
    BackupFilePtr ptr;
    while (ops.seizeFirst(ptr)){
      new (ptr.p) BackupFile(* this, c_pagePool);
    }
    while (ops.releaseFirst());
  }
  
  {
    SLList<BackupRecord> recs(c_backupPool);
    BackupRecordPtr ptr;
    while (recs.seizeFirst(ptr)){
      new (ptr.p) BackupRecord(* this, c_tablePool, 
			       c_backupFilePool, c_triggerPool);
    }
    while (recs.releaseFirst());
  }

  // Initialize BAT for interface to file system
  {
    Page32Ptr p;
    ndbrequire(c_pagePool.seizeId(p, 0));
    c_startOfPages = (Uint32 *)p.p;
    c_pagePool.release(p);
    
    NewVARIABLE* bat = allocateBat(1);
    bat[0].WA = c_startOfPages;
    bat[0].nrr = c_pagePool.getSize()*sizeof(Page32)/sizeof(Uint32);
  }

  ReadConfigConf * conf = (ReadConfigConf*)signal->getDataPtrSend();
  conf->senderRef = reference();
  conf->senderData = senderData;
  sendSignal(ref, GSN_READ_CONFIG_CONF, signal, 
	     ReadConfigConf::SignalLength, JBB);
}
コード例 #18
0
ファイル: MSIndexVector.C プロジェクト: PlanetAPL/a-plus
MSIndexVector::MSIndexVector (const char *pString_) : MSVector()
{
  _pImpl = new MSBuiltinVectorImpl(&ops(),&ops());
  _pImpl->setFromString (pString_);
}
コード例 #19
0
 OpenGlVec<T,N>
 operator*(const OpenGlVec<T,N>& vec) const { return ops(times, vec); }
コード例 #20
0
ファイル: MSIndexVector.C プロジェクト: PlanetAPL/a-plus
MSIndexVector::MSIndexVector (MSIndexVector::Data *pData_, unsigned int len_) : MSVector()
{
  _pImpl = new MSBuiltinVectorImpl(&ops(), &ops(), (void *)pData_, len_);
}
コード例 #21
0
 OpenGlVec<T,N>
 operator+(const OpenGlVec<T,N>& vec) const { return ops(add, vec); }
コード例 #22
0
ファイル: ICamera.cpp プロジェクト: AWhetter/alembic
//-*****************************************************************************
void ICameraSchema::init( const Abc::Argument &iArg0,
                          const Abc::Argument &iArg1 )
{
    ALEMBIC_ABC_SAFE_CALL_BEGIN( "ICameraSchema::init()" );

    AbcA::CompoundPropertyReaderPtr _this = this->getPtr();

    Abc::Arguments args;
    iArg0.setInto( args );
    iArg1.setInto( args );


    m_coreProperties = Abc::IScalarProperty( _this, ".core",
        args.getErrorHandlerPolicy() );

    // none of the things below here are guaranteed to exist

    if ( this->getPropertyHeader( ".childBnds" ) != NULL )
    {
        m_childBoundsProperty = Abc::IBox3dProperty( _this, ".childBnds",
            iArg0, iArg1 );
    }

    if ( this->getPropertyHeader( ".arbGeomParams" ) != NULL )
    {
        m_arbGeomParams = Abc::ICompoundProperty( _this, ".arbGeomParams",
            args.getErrorHandlerPolicy() );
    }

    if ( this->getPropertyHeader( ".userProperties" ) != NULL )
    {
        m_userProperties = Abc::ICompoundProperty( _this, ".userProperties",
            args.getErrorHandlerPolicy() );
    }

    // read the film back operations
    const AbcA::PropertyHeader * header =
        this->getPropertyHeader(".filmBackOps");

    // read it from the scalar property
    if ( header != NULL && header->isScalar() )
    {
        Abc::IScalarProperty opsProp( _this, ".filmBackOps",
            args.getErrorHandlerPolicy() );

        size_t numOps = opsProp.getDataType().getExtent();

        std::vector < std::string > ops( numOps );
        opsProp.get( &ops.front() );
        m_ops.resize( ops.size() );


        for ( size_t i = 0; i < numOps; ++i )
        {
            m_ops[i] = FilmBackXformOp( ops[i] );
        }

    }
    // read it from the array property
    else if ( header != NULL && header->isArray() )
    {
        Abc::IStringArrayProperty opsProp( _this, ".filmBackOps",
            iArg0, iArg1 );

        Abc::StringArraySamplePtr ops;
        opsProp.get( ops );
        size_t numOps = ops->size();
        m_ops.resize( numOps );


        for ( size_t i = 0; i < numOps; ++i )
        {
            m_ops[i] = FilmBackXformOp( (*ops)[i] );
        }
    }

    header = this->getPropertyHeader( ".filmBackChannels" );

    if ( header != NULL && header->isScalar() )
    {
        m_smallFilmBackChannels = Abc::IScalarProperty( _this,
            ".filmBackChannels", args.getErrorHandlerPolicy() );
    }
    else if ( header != NULL && header->isArray() )
    {
        m_largeFilmBackChannels = Abc::IDoubleArrayProperty( _this,
            ".filmBackChannels", iArg0, iArg1 );
    }

    ALEMBIC_ABC_SAFE_CALL_END_RESET();
}
コード例 #23
0
 OpenGlVec<T,N>
 operator-(const OpenGlVec<T,N>& vec) const { return ops(minus, vec); }
コード例 #24
0
ファイル: jswriter.cpp プロジェクト: serghei/kde-kdesdk
void JSWriter::writeClass(UMLClassifier *c)
{
    if(!c)
    {
        kDebug()<<"Cannot write class of NULL concept!" << endl;
        return;
    }

    QString classname = cleanName(c->getName());
    QString fileName = c->getName().lower();

    //find an appropriate name for our file
    fileName = findFileName(c,".js");
    if (fileName.isEmpty())
    {
        emit codeGenerated(c, false);
        return;
    }

    QFile filejs;
    if(!openFile(filejs, fileName))
    {
        emit codeGenerated(c, false);
        return;
    }
    QTextStream js(&filejs);

    //////////////////////////////
    //Start generating the code!!
    /////////////////////////////


    //try to find a heading file (license, coments, etc)
    QString str;
    str = getHeadingFile(".js");
    if(!str.isEmpty())
    {
        str.replace(QRegExp("%filename%"),fileName);
        str.replace(QRegExp("%filepath%"),filejs.name());
        js << str << m_endl;
    }


    //write includes
    UMLPackageList includes;
    findObjectsRelated(c,includes);
    for (UMLPackage *conc = includes.first(); conc; conc = includes.next())
    {
        QString headerName = findFileName(conc, ".js");
        if ( !headerName.isEmpty() )
        {
            js << "#include \"" << headerName << "\"" << m_endl;
        }
    }
    js << m_endl;

    //Write class Documentation if there is somthing or if force option
    if(forceDoc() || !c->getDoc().isEmpty())
    {
        js << m_endl << "/**" << m_endl;
        js << "  * class " << classname << m_endl;
        js << formatDoc(c->getDoc(),"  * ");
        js << "  */" << m_endl << m_endl;
    }


    //check if class is abstract and / or has abstract methods
    if(c->getAbstract() && !hasAbstractOps(c))
        js << "/******************************* Abstract Class ****************************" << m_endl << "  "
        << classname << " does not have any pure virtual methods, but its author" << m_endl
        << "  defined it as an abstract class, so you should not use it directly." << m_endl
        << "  Inherit from it instead and create only objects from the derived classes" << m_endl
        << "*****************************************************************************/" << m_endl << m_endl;

    js << classname << " = function ()" << m_endl;
    js << "{" << m_endl;
    js << m_indentation << "this._init ();" << m_endl;
    js << "}" << m_endl;
    js << m_endl;

    UMLClassifierList superclasses = c->getSuperClasses();
    for (UMLClassifier *obj = superclasses.first();
            obj; obj = superclasses.next()) {
        js << classname << ".prototype = new " << cleanName(obj->getName()) << " ();" << m_endl;
    }

    js << m_endl;

    if (! c->isInterface()) {
        UMLAttributeList atl = c->getAttributeList();

        js << "/**" << m_endl;
        QString temp = "_init sets all " + classname + " attributes to their default value."
                       " Make sure to call this method within your class constructor";
        js << formatDoc(temp, " * ");
        js << " */" << m_endl;
        js << classname << ".prototype._init = function ()" << m_endl;
        js << "{" << m_endl;
        for(UMLAttribute *at = atl.first(); at ; at = atl.next())
        {
            if (forceDoc() || !at->getDoc().isEmpty())
            {
                js << m_indentation << "/**" << m_endl
                << formatDoc(at->getDoc(), m_indentation + " * ")
                << m_indentation << " */" << m_endl;
            }
            if(!at->getInitialValue().isEmpty())
            {
                js << m_indentation << "this.m_" << cleanName(at->getName()) << " = " << at->getInitialValue() << ";" << m_endl;
            }
            else
            {
                js << m_indentation << "this.m_" << cleanName(at->getName()) << " = \"\";" << m_endl;
            }
        }
    }

    //associations
    UMLAssociationList aggregations = c->getAggregations();
    if (forceSections() || !aggregations.isEmpty ())
    {
        js << m_endl << m_indentation << "/**Aggregations: */" << m_endl;
        writeAssociation(classname, aggregations , js );

    }
    UMLAssociationList compositions = c->getCompositions();
    if( forceSections() || !compositions.isEmpty())
    {
        js << m_endl << m_indentation << "/**Compositions: */" << m_endl;
        writeAssociation(classname, compositions , js );

    }
    js << m_endl;
    js << "}" << m_endl;
    js << m_endl;

    //operations
    UMLOperationList ops(c->getOpList());
    writeOperations(classname, &ops, js);

    js << m_endl;

    //finish file

    //close files and notfiy we are done
    filejs.close();
    emit codeGenerated(c, true);
}
コード例 #25
0
ファイル: profile.hpp プロジェクト: bambang/vsipl
 float  mops() const { return (count() * ops()) / (1e6 * total());}
コード例 #26
0
ファイル: parameter_validation.cpp プロジェクト: Aand1/ROSCH
TEST(ParameterValidation, subscribeNoCallback)
{
  ros::NodeHandle nh;
  ros::SubscribeOptions ops("blah", 0, "blah", "blah");
  ASSERT_THROWS(nh.subscribe(ops));
}
コード例 #27
0
//=============================================================================
// METHOD    : SPELLwsWarmStartImpl::restoreState()
//=============================================================================
PyFrameObject* SPELLwsWarmStartImpl::restoreState()
{
	DEBUG("[WS] Restoring state ========================================");

	// We need a separate scope so that we can invoke saveState at the end without deadlock
	{
		std::cerr << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
		std::cerr << "RESTORE STATE START" << std::endl;
		std::cerr << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;

		// Synchronize so that nothing can be done while saving
		SPELLmonitor m(m_lock);

		SPELLsafePythonOperations ops("SPELLwsWarmStartImpl::restoreState()");

		// Create a fresh thread state
		PyThreadState* tstate = PyThreadState_Get();

		DEBUG("[WS] Restoring interpreter parameters");

		tstate->recursion_depth = m_storage->loadLong();
		DEBUG("    - Recursion depth : " + ISTR(tstate->recursion_depth));
		tstate->tick_counter = m_storage->loadLong();
		DEBUG("    - Tcik counter    : " + ISTR(tstate->tick_counter));
		tstate->gilstate_counter = m_storage->loadLong();
		DEBUG("    - GIL counter     : " + ISTR(tstate->gilstate_counter));
		int numFrames = m_storage->loadLong();
		DEBUG("    - Number of frames: " + ISTR(numFrames));

		if (numFrames < 0)
		{
			THROW_EXCEPTION("Unable to restore state", "Failed to restore interpreter parameters", SPELL_ERROR_WSTART);
		}

		DEBUG("[WS] Restoring frames");
		m_frames.clear();
		m_recursionDepth = 0;

		// Restore the frames now. Consider that the top frame is already there

		// Use the originally created frame to copy globals
		PyFrameObject* prevFrame = NULL;

		for( int count = 0; count < numFrames; count++ )
		{
			// In recursion depth zero, use the original frame
			// to copy the globals from
			std::string frameId = PYSSTR(m_storage->loadObject());
			m_topFrame = new SPELLwsFrame( frameId, m_startup, m_frames.size(), prevFrame );
			m_frames.push_back(m_topFrame);
			// For the head frame, store its address in the interpreter thread state
			if (m_recursionDepth == 0)
			{
				if (tstate->frame) delete tstate->frame;
				tstate->frame = m_topFrame->getFrameObject();
			}
			m_recursionDepth++;
			prevFrame = m_topFrame->getFrameObject();
		}
		// Update the recursion depth
		tstate->recursion_depth = m_recursionDepth;

		DEBUG("[WS] Checking errors");
		SPELLpythonHelper::instance().checkError();

		DEBUG("[WS] Switching to save state mode");
		// Reset the storage now, to mode write
		delete m_storage;
		m_storage = new SPELLwsStorage( m_persistentFile, SPELLwsStorage::MODE_WRITE );

		std::cerr << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
		std::cerr << "RESTORE STATE END" << std::endl;
		std::cerr << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;

	}

	// Re-save the current state, so that the new persistent files are ok
	saveState();

	DEBUG("[WS] Checking errors");
	SPELLpythonHelper::instance().checkError();

	// Reset values
	m_startup.recoveryFile = "";
	m_startup.performRecovery = false;

	DEBUG("[WS] State recovered ===========================================");

	return m_topFrame->getFrameObject();
}
コード例 #28
0
ファイル: parameter_validation.cpp プロジェクト: Aand1/ROSCH
TEST(ParameterValidation, advertiseEmptyMD5Sum)
{
  ros::NodeHandle nh;
  ros::AdvertiseOptions ops("blah", 0, "", "blah", "blah");
  ASSERT_THROWS(nh.advertise(ops));
}
コード例 #29
0
ファイル: builtin_power.cpp プロジェクト: r0mai/r0math
expression_tree Power(const expression_tree::operands_t& ops_to_copy, enviroment& env) {

    expression_tree::operands_t ops(ops_to_copy);

    if ( ops.size() == 0 ) {
        return expression_tree::make_exact_number( mpq_class(1) );   
    }

    if ( ops.size() == 1 ) {
        return expression_tree( ops[0] );   
    }
    
    assert( ops.size() == 2 );

    assert( ops[0].get_type() != expression_tree::APPROXIMATE_NUMBER );
    assert( ops[1].get_type() != expression_tree::APPROXIMATE_NUMBER );


    //if exponent is an integer, then there are possible simplifications
    if ( ops[1].is_integer() ) {

        //(a^b)^c == a^(bc) if c is an integer
        if ( ops[0].is_operator("Power") ) {

            const expression_tree::operands_t& power_ops = ops[0].get_operands();

            assert( power_ops.size() == 2 );

            ops[1] = expression_tree::make_operator("Times", power_ops[1], ops[1]).evaluate(env);
            ops[0] = power_ops[0];

        }

    }

    //x^0 == 0
    //x^1 == x
    //But 0^0 is Indeterminate, TODO!!?? DEBUG : Expand[Det[{{n,n,n},{n+1,n+1,n+2},{n+3,n+2,n+1}}]]
    if ( ops[1].get_type() == expression_tree::EXACT_NUMBER ) {
        if ( ops[1].get_exact_number() == 0 ) {
            if ( ops[0].get_type() == expression_tree::EXACT_NUMBER ) {
                env.raise_error( "Power", "Indeterminate expression 0^0 encountered." );
                return expression_tree::make_symbol( "Indeterminate" );
            } else {
                return expression_tree::make_exact_number( 1 );
            }
        } else if ( ops[1].get_exact_number() == 1 ) {
            return ops[0];
        }        
    }

    if ( ops[0].get_type() != expression_tree::EXACT_NUMBER || ops[1].get_type() != expression_tree::EXACT_NUMBER ) {
        return expression_tree::make_operator( "Power", ops ); //nonnumber nonpowering
    }

    
    //TODO check if fits
    //If the don't fit into these, then why bother calculating?

    long exponent = 0;
    unsigned long inverse_exponent = 0;

    bool exponent_conversion_success = mpz_get_si_checked(exponent, ops[1].get_exact_number().get_num());
    bool inverse_exponent_conversion_success = mpz_get_ui_checked(inverse_exponent, ops[1].get_exact_number().get_den());

    if ( !exponent_conversion_success || !inverse_exponent_conversion_success ) {
        env.raise_error( "Power", "exponent overflow" );
        return expression_tree::make_operator( "Power", ops );
    }

    if ( ops[0].get_exact_number() < 0 ) {
        if ( inverse_exponent != 1 ) {
            env.raise_error( "Power", "can't raise a negative base to a rational exponent" );
            return expression_tree::make_symbol( "Indeterminate" );
        }
    } else if ( ops[0].get_exact_number() == 0 ) {
        if ( exponent > 0 ) {
            return expression_tree( ops[0] ); // mpq_class(0) why reconstruct?
        } else if ( exponent == 0 ) {
            env.raise_error( "Power", "Indeterminate 0^0" );
            return expression_tree::make_symbol( "Indeterminate" );
        } else { //exponent < 0
            env.raise_error( "Power", "Infinite expression 0^-exp" );
            return expression_tree::make_symbol( "Infinity" );
        }
    } else { //ops[0].get_exact_number() > 0
        //everything is mathOK here
    }
    //shortcut for Power[a, -1]
    if ( exponent == -1 && inverse_exponent == 1 ) {
        mpq_class result = mpq_class(1) / ops[0].get_exact_number();
        return expression_tree::make_exact_number( result );
    }

    bool negative_exponent = false;
    if ( exponent < 0 ) {
        negative_exponent = true;
        exponent = -exponent;
    }        

    mpq_class resultq = mpq_pow_ui_class( ops[0].get_exact_number(), exponent );

    if (negative_exponent) {
        resultq = mpq_class(1) / resultq;
    }
    if ( inverse_exponent == 1 ) {
        return expression_tree::make_exact_number( resultq );
    } else {
        //ops[1] is now equals 1/d. We did the numerator's job above.
        //ops[1] = mpq_class( mpz_class(1), ops[1].get_exact_number().get_den() ); //implicit constructor

        //TODO check if fits
        //unsigned long inverse_exponent = ops[1].get_exact_number().get_den().get_ui();

        mpz_class numerator_result;
        mpz_class denominator_result;

        bool numerator_success = mpz_root_class( numerator_result, resultq.get_num(), inverse_exponent);
        bool denominator_success = mpz_root_class( denominator_result, resultq.get_den(), inverse_exponent);

        if ( numerator_success && denominator_success ) {
            mpq_class result( numerator_result, denominator_result );
            return expression_tree::make_exact_number( result );
        } else if ( numerator_success ) { //&& !denominator_success
            /*
                Creating :
                Times[numerator_result, Power[resultq.get_den(), -1/inverse_exponent]]
            */                
            expression_tree::operands_t ops_power;
            expression_tree::operands_t ops_times;

            mpq_class negated_exponent( mpq_class(-1)*mpq_class(1, inverse_exponent) );

            ops_power.push_back( expression_tree::make_exact_number( mpq_class(resultq.get_den()) ) );
            ops_power.push_back( expression_tree::make_exact_number( negated_exponent ) ); //could use 1/inverse_exponent also
            expression_tree power_expr = expression_tree::make_operator( "Power", ops_power ); //don't have to evaulate, can't do anything anyway

            if ( numerator_result == 1 ) {
                return power_expr;
            } else {
                ops_times.push_back( expression_tree::make_exact_number( mpq_class(numerator_result) ) );
                ops_times.push_back( power_expr );
                return expression_tree::make_operator("Times", ops_times)/*.evaluate()*/;
            }
        } else if ( denominator_success ) { //&& !numerator_success
            /*
                Creating :
                Times[Power[resultq.get_num(), 1/inverse_exponent], 1/denominator_result]
            */
            expression_tree::operands_t ops_powerlhs;
            expression_tree::operands_t ops_times;

            ops_powerlhs.push_back( expression_tree::make_exact_number( mpq_class(resultq.get_num()) ) );
            ops_powerlhs.push_back( expression_tree::make_exact_number( mpq_class(1, inverse_exponent) ) );
            expression_tree powerlhs_tree = expression_tree::make_operator("Power", ops_powerlhs);

            if ( denominator_result == 1 ) {
                return powerlhs_tree;
            } else {
                ops_times.push_back( powerlhs_tree );
                ops_times.push_back( expression_tree::make_exact_number(mpq_class( mpz_class(1), denominator_result )) );
                return expression_tree::make_operator("Times", ops_times)/*.evaluate()*/; //FIXME might evaulate this? no...
            }

        } else { //!denominator_success && !numerator_success
            /*
                Creating :
                Power[resultq, exponent/inverse_exponent]
            */
            expression_tree::operands_t ops_power;
            ops_power.push_back( expression_tree::make_exact_number( resultq ) );
            ops_power.push_back( expression_tree::make_exact_number( mpq_class(1, inverse_exponent) ) );
            return expression_tree::make_operator("Power", ops_power);
        }

    }
    
}
コード例 #30
0
MSBuiltinVector<Type>::MSBuiltinVector (unsigned int length_) : MSBaseVector<Type,MSAllocator<Type> > ((MSVectorImpl *)0)
{
    this->_pImpl = new MSBuiltinVectorImpl(&ops(),&ops(),length_);
}