void ANCFBeamBE2D::GetdPosdqT(const Vector2D& p_loc, Matrix& dpdqi)
{
	//p = S(p.x,p.y,p.z)*q; d(p)/dq
	dpdqi.SetSize(SOS(),Dim());
	dpdqi.FillWithZeros();
	//d = S + ...
	for (int i = 1; i <= NS(); i++)
	{
		double s = GetS0(p_loc.X(), i);
		dpdqi((i-1)*Dim()+1,1) = s;
		dpdqi((i-1)*Dim()+2,2) = s;
	}
	if (p_loc.Y() != 0)
	{
		double y = p_loc.Y();
		Vector2D rx = GetPosx2D(p_loc.X());
		Vector2D n(-rx.X(), rx.Y());
		n /= rx.Norm();

		for (int i = 1; i <= NS(); i++)
		{
			double sx = GetS0x(p_loc.X(), i) * 2./GetLx();
			//y/|n|*dn/dq
			dpdqi((i-1)*Dim()+1,2) +=  y*sx;
			dpdqi((i-1)*Dim()+2,1) += -y*sx;

			//y*n/|n|*(r_x1*S_x1 + r_x2*S_x2)
			dpdqi((i-1)*Dim()+1,1) +=  y*n.X()*(rx.X()*sx);
			dpdqi((i-1)*Dim()+1,2) +=  y*n.Y()*(rx.X()*sx);
			dpdqi((i-1)*Dim()+2,1) +=  y*n.X()*(rx.Y()*sx);
			dpdqi((i-1)*Dim()+2,2) +=  y*n.Y()*(rx.Y()*sx);
		}
	}
};
Beispiel #2
0
/** \brief initialize the tclmsgque package
 *
 * The tclmsgque package is created and one new command "msgque"
 * is added to the Tcl interpreter.
 * \param[in] interp the current interpreter
 * \return Tcl error-code
 */
TCLMQ_EXTERN int
Tclmsgque_Init (
  Tcl_Interp * interp
)
{
  // check for the reight tcl
  if (Tcl_InitStubs (interp, "8.5", 0) == NULL) {
    return TCL_ERROR;
  }

  // announce my package
  TclErrorCheck (Tcl_PkgProvide (interp, "TclMsgque", LIBMSGQUE_VERSION));

  // provide "msgque" as only public cammand of the package
  Tcl_CreateObjCommand (interp, "tclmsgque", NS(MsgqueCmd), (ClientData) NULL,
                        (Tcl_CmdDeleteProc *) NULL);

  // init libmsgque global data
  if (MqInitGet() == NULL && Tcl_GetNameOfExecutable() != NULL) {
    struct MqBufferLS * initB = MqInitCreate();

    if (Tcl_Eval(interp, "info script") == TCL_ERROR)
      return TCL_ERROR;

    MqBufferLAppendC(initB, Tcl_GetNameOfExecutable());
    MqBufferLAppendC(initB, Tcl_GetStringResult(interp));
  }

  // create the default-factory
  if (!strcmp(MqFactoryDefaultIdent(),"libmsgque")) {
    MqFactoryDefault("tclmsgque", NS(FactoryCreate), NULL, NULL, NS(FactoryDelete), NULL, NULL);
  }

  return TCL_OK;
}
static enum MqErrorE MQ_DECL NS(FactoryCreate) (
  struct MqS * const tmpl,
  enum MqFactoryE create,
  MQ_PTR data,
  struct MqS  ** contextP
)
{
  JNIEnv * env = NULL;

  // get env
  if (create == MQ_FACTORY_NEW_THREAD) {
    JavaVMAttachArgs args = {JNI_VERSION_1_6, "libmsgque", NULL};
    if ((*cached_jvm)->AttachCurrentThread(cached_jvm, (void**)&env, (void**)&args) != JNI_OK) {
      return MqErrorC (tmpl, __func__, -1, "unable to 'AttachCurrentThread'");
    }
  } else {
    env = ((JNIEnv*) tmpl->threadData);
  }

  // create new object
  *contextP = XCONTEXT((*env)->CallObjectMethod(env, (jobject)tmpl->self, NS(MID_IFactory_Factory)));
  if((*env)->ExceptionCheck(env) == JNI_TRUE) {
    (*env)->CallVoidMethod(env, tmpl->self, NS(MID_MqS_ErrorSet), (*env)->ExceptionOccurred(env));
    (*env)->ExceptionClear(env);
    return MqErrorStack(tmpl);
  }

  MqConfigDup (*contextP, tmpl);
  MqSetupDup (*contextP, tmpl);
  return MQ_OK;
}
Beispiel #4
0
/*! \internal
    \since 4.7

    Registers a user type for marshalling, as an alias of another type (typedef)
*/
int QMetaType::registerTypedef(const char* typeName, int aliasId)
{
    QVector<QCustomTypeInfo> *ct = customTypes();
    if (!ct || !typeName)
        return -1;

#ifdef QT_NO_QOBJECT
    NS(QByteArray) normalizedTypeName = typeName;
#else
    NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
#endif

    int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
                                  normalizedTypeName.size());

    if (idx) {
        Q_ASSERT(idx == aliasId);
        return idx;
    }

    QWriteLocker locker(customTypesLock());
    idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
                                           normalizedTypeName.size());

    if (idx)
        return idx;

    QCustomTypeInfo inf;
    inf.typeName = normalizedTypeName;
    inf.alias = aliasId;
    inf.constr = 0;
    inf.destr = 0;
    ct->append(inf);
    return aliasId;
}
Beispiel #5
0
TEST(StringTest, Case)
{
    NoString x = NS("xx");
    NoString X = NS("XX");
    EXPECT_EQ(X, x.toUpper());
    EXPECT_EQ(x, X.toLower());
}
Beispiel #6
0
static void
NS(test_main)(void *arg)
{
  routerset_t *set = routerset_new();
  smartlist_t *out = smartlist_new();
  int r;
  (void)arg;

  NS_MOCK(nodelist_get_list);

  smartlist_add(set->country_names, tor_strdup("{xx}"));
  NS(mock_smartlist) = smartlist_new();
  NS(mock_node).is_running = 0;
  smartlist_add(NS(mock_smartlist), (void *)&NS(mock_node));

  routerset_get_all_nodes(out, set, NULL, 1);
  r = smartlist_len(out);
  routerset_free(set);
  smartlist_free(out);
  smartlist_free(NS(mock_smartlist));

  tt_int_op(r, ==, 0);
  tt_int_op(CALLED(nodelist_get_list), ==, 1);

  done:
    ;
}
Beispiel #7
0
static void calc_coefficients(AVFilterContext *ctx)
{
    ColorMatrixContext *color = ctx->priv;
    double rgb_coeffd[4][3][3];
    double yuv_convertd[16][3][3];
    int v = 0;
    int i, j, k;

    for (i = 0; i < 4; i++)
        inverse3x3(rgb_coeffd[i], yuv_coeff[i]);
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 4; j++) {
            solve_coefficients(yuv_convertd[v], rgb_coeffd[i], yuv_coeff[j]);
            for (k = 0; k < 3; k++) {
                color->yuv_convert[v][k][0] = NS(yuv_convertd[v][k][0]);
                color->yuv_convert[v][k][1] = NS(yuv_convertd[v][k][1]);
                color->yuv_convert[v][k][2] = NS(yuv_convertd[v][k][2]);
            }
            if (color->yuv_convert[v][0][0] != 65536 || color->yuv_convert[v][1][0] != 0 ||
                    color->yuv_convert[v][2][0] != 0) {
                av_log(ctx, AV_LOG_ERROR, "error calculating conversion coefficients\n");
            }
            v++;
        }
    }
}
Beispiel #8
0
static void
NS(test_main)(void *arg)
{
  smartlist_t *out = smartlist_new();
  routerset_t *set = routerset_new();
  int out_len;
  (void)arg;

  NS_MOCK(node_get_by_nickname);

  NS(mock_node).is_running = 0;
  NS(mock_nickname) = "foo";
  smartlist_add(set->list, tor_strdup(NS(mock_nickname)));

  routerset_get_all_nodes(out, set, NULL, 1);
  out_len = smartlist_len(out);

  smartlist_free(out);
  routerset_free(set);

  tt_int_op(out_len, ==, 0);
  tt_int_op(CALLED(node_get_by_nickname), ==, 1);

  done:
    ;
}
Beispiel #9
0
static void
NS(test_main)(void *arg)
{
  smartlist_t *out = smartlist_new();
  routerset_t *set = routerset_new();
  int out_len;
  node_t *ent;
  (void)arg;

  NS_MOCK(node_get_by_nickname);

  NS(mock_nickname) = tor_strdup("foo");
  smartlist_add(set->list, NS(mock_nickname));

  routerset_get_all_nodes(out, set, NULL, 0);
  out_len = smartlist_len(out);
  ent = (node_t *)smartlist_get(out, 0);

  smartlist_free(out);
  routerset_free(set);

  tt_int_op(out_len, ==, 1);
  tt_ptr_op(ent, ==, &NS(mock_node));
  tt_int_op(CALLED(node_get_by_nickname), ==, 1);

  done:
    ;
}
Beispiel #10
0
/*! \internal

    Registers a user type for marshalling, with \a typeName, a \a
    destructor, and a \a constructor. Returns the type's handle,
    or -1 if the type could not be registered.
 */
int QMetaType::registerType(const char *typeName, Destructor destructor,
                            Constructor constructor)
{
    QVector<QCustomTypeInfo> *ct = customTypes();
    if (!ct || !typeName || !destructor || !constructor)
        return -1;

#ifdef QT_NO_QOBJECT
    NS(QByteArray) normalizedTypeName = typeName;
#else
    NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
#endif

    int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
                                  normalizedTypeName.size());

    if (!idx) {
        QWriteLocker locker(customTypesLock());
        idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
                                           normalizedTypeName.size());
        if (!idx) {
            QCustomTypeInfo inf;
            inf.typeName = normalizedTypeName;
            inf.constr = constructor;
            inf.destr = destructor;
            inf.alias = -1;
            idx = ct->size() + User;
            ct->append(inf);
        }
    }
    return idx;
}
RUBYMQ_EXTERN void Init_rubymsgque() {

  // Register system
#ifdef HAVE_FORK
//  MqInitSysAPI(NS(fork),NULL);
#endif

  // Initialize components
  NS(MqS_Init)();
  NS(MqSException_Init)();
  NS(MqBufferS_Init)();

  // get the script name
  VALUE a0 = rb_gv_get("$0");

  // init libmsgque global data
  if (MqInitBuf == NULL && !NIL_P(a0)) {
    struct MqBufferLS * initB = MqInitCreate();
    MqBufferLAppendC(initB, VAL2CST(rb_argv0));
    MqBufferLAppendC(initB, VAL2CST(a0));
  }

  // set global data
  id_receiver = rb_intern("receiver");
  id_clone = rb_intern("clone");
  id_unbind = rb_intern("unbind");
  id_bind = rb_intern("bind");
}
Beispiel #12
0
 //! Restore the original environment
 ~environment ()
 {
   std::for_each (vars_set_.begin (), vars_set_.end (),
                  NS(bind) (&environment::unsetenv_, this, NSPH(_1)));
   std::for_each (mod_vars_.begin (), mod_vars_.end (),
                  NS(bind) (&environment::setenv_, this, NSPH(_1)));
 }
Beispiel #13
0
TEST(StringTest, LeftRight)
{
    EXPECT_EQ("Xy", NS("Xyz").left(2));
    EXPECT_EQ("Xyz", NS("Xyz").left(20));

    EXPECT_EQ("yz", NS("Xyz").right(2));
    EXPECT_EQ("Xyz", NS("Xyz").right(20));
}
Beispiel #14
0
static or_state_t *
NS(get_or_state)(void)
{
  NS(mock_state) = tor_malloc_zero(sizeof(or_state_t));
  NS(mock_state)->AccountingBytesReadInInterval = 0;
  NS(mock_state)->AccountingBytesWrittenInInterval = 0;

  return NS(mock_state);
}
static void
MQ_DECL NS(ProcessExit) (
  int exitnum
)
{
  JNIEnv *env;
  if ((*cached_jvm)->GetEnv(cached_jvm, (void*) &env, JNI_VERSION_1_6) == JNI_OK) {
    (*env)->CallStaticVoidMethod(env, NS(Class_System), NS(MID_System_exit), (jint) exitnum);
  }
}
Beispiel #16
0
const node_t *
NS(node_get_by_nickname)(const char *nickname, int warn_if_unused)
{
  CALLED(node_get_by_nickname)++;
  tt_str_op(nickname, OP_EQ, NS(mock_nickname));
  tt_int_op(warn_if_unused, OP_EQ, 1);

  done:
    return &NS(mock_node);
}
void NS(MqBufferS_Init) (TSRMLS_D) {
    zend_class_entry me_ce;

    // create class and make depend on "Exception"
    INIT_CLASS_ENTRY(me_ce,"MqBufferS", NS(MqBufferS_functions));
    NS(MqBufferS) = zend_register_internal_class(&me_ce TSRMLS_CC);

    // define additional properties "buf" to save the "struct MqBufferS *" pointer
    zend_declare_property_null(NS(MqBufferS), ID(__buf), ZEND_ACC_PRIVATE TSRMLS_CC);
}
void NS(MqBufferS_New) (zval *return_value, MQ_BUF buf TSRMLS_DC)
{
    // convert to an object instance
    if (object_init_ex(return_value, NS(MqBufferS)) == FAILURE) {
        RaiseError("unable to create an 'MqBufferS' instance.");
        return;
    }
    // link 'buf' with the object instance
    zend_update_property_long(NS(MqBufferS), return_value, ID(__buf), (long) buf TSRMLS_CC);
    return;
}
Beispiel #19
0
int NS(SendEND_AND_CALLBACK) (NS_ARGS)
{
  SETUP_mqctx
  MQ_STR token;
  Tcl_Obj *callback;
  CHECK_C(token)
  CHECK_OBJ(callback)
  CHECK_NOARGS
  Tcl_IncrRefCount(callback);
  ErrorMqToTclWithCheck(MqSendEND_AND_CALLBACK(mqctx, token, NS(ProcCall), callback, NS(ProcFree)));
  RETURN_TCL
}
Beispiel #20
0
PyObject* NS(ReadForward) (
  PyObject*	self,
  PyObject*	args
)
{
  SETUP_context
  MqS_Obj *ctxO = NULL;
  MqDumpS_Obj *dumpO = NULL;
  PyErrorCheck (PyArg_ParseTuple(args, "O!|O!:ReadForward", &NS(MqS), &ctxO, &NS(MqDumpS), &dumpO));
  ErrorMqToPythonWithCheck(MqReadForward(context, &ctxO->context, dumpO == NULL ? NULL : dumpO->dump));
  SETUP_RETURN;
}
Beispiel #21
0
JNIEXPORT jobject JNICALL NS(ReadU) (
  JNIEnv *      env,
  jobject       self
)
{
  SETUP_context;
  MQ_BUF buffer;
  ErrorMqToJavaWithCheck(MqReadU(context, &buffer));
  return (*env)->NewObject(env, NS(Class_MqBufferS), NS(MID_MqBufferS_INIT), (jlong) buffer);
error:
  return NULL;
}
Beispiel #22
0
void NS(MqDumpS_New) (
  Tcl_Interp * interp,
  struct MqDumpS * dump
)
{
  char buffer[30];
  sprintf(buffer, "<MqDumpS-%p>", dump);
  Tcl_CreateObjCommand (interp, buffer, NS(MqDumpS_Cmd), dump, NS(MqDumpS_Free));

  Tcl_SetResult (interp, buffer, TCL_VOLATILE);
  Tcl_CreateExitHandler (NS(MqDumpS_Free), dump);
}
Beispiel #23
0
int NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, const char *name)
{
  int i = getEncodingIndex(name);
  if (i == UNKNOWN_ENC)
    return 0;
  INIT_ENC_INDEX(p) = (char)i;
  p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
  p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
  p->initEnc.updatePosition = initUpdatePosition;
  p->encPtr = encPtr;
  *encPtr = &(p->initEnc);
  return 1;
}
Beispiel #24
0
JNIEXPORT void JNICALL NS(ErrorSet) (
  JNIEnv      *env,
  jobject     self,
  jthrowable  ex
)
{
  SETUP_context;

  // is the EROOR from "java" or "javamsgque"
  if ((*env)->IsInstanceOf(env, ex, NS(Class_MqSException))) {
  
    // error is from "javamsgque"
    const char *txtC = JO2C_START(
      env, (jstring) (*env)->GetObjectField(env,ex,NS(FID_MqSException_txt))
    );
    MqErrorSet(context,
      (MQ_INT) (*env)->GetIntField(env,ex,NS(FID_MqSException_num)), 
      (enum MqErrorE) (*env)->GetIntField(env,ex,NS(FID_MqSException_code)), 
      txtC
    );
    JO2C_STOP(env, ex, txtC);

  } else {
    // error is from "java"
    jstring message = NULL;

    // 1. if no "message" is available -> get StackTrace
    // 
    // final Writer result = new StringWriter();
    // final PrintWriter printWriter = new PrintWriter(result);
    // ex.printStackTrace(printWriter);
    // result.toString();
    // 
    jobject stringWriter = (*env)->NewObject(env, NS(Class_StringWriter), NS(MID_StringWriter_INIT));
    jobject printWriter = (*env)->NewObject(env, NS(Class_PrintWriter), NS(MID_PrintWriter_INIT), stringWriter);
    (*env)->CallVoidMethod(env, ex, NS(MID_Throwable_printStackTrace), printWriter);
    message = (jstring) (*env)->CallObjectMethod(env, stringWriter, NS(MID_StringWriter_toString));

    // 2. Add java-error-message to MQ error
    if (message != NULL) {
      MQ_CST str = JO2C_START(env,message);
      MqErrorC(context, __func__, -1, str);
      JO2C_STOP(env,message,str);
    } else {
      MqErrorC(context, __func__, -1, "unknown Exception");
    }
  }
  (*env)->ExceptionClear(env);
}
Beispiel #25
0
enum http_rc_e
action_admin_meta0_force(struct req_args_s *args)
{
	GError *err = NULL;
	GSList *m0_lst = NULL;

	err = conscience_get_services(NS(), NAME_SRVTYPE_META0, FALSE, &m0_lst);
	if (!err) {
		for (GSList *l = m0_lst; l; l = l->next) {
			g_clear_error(&err);
			service_info_t *m0 = l->data;
			gchar m0_url[STRLEN_ADDRINFO] = {0};
			grid_addrinfo_to_string(&(m0->addr), m0_url, sizeof(m0_url));

			err = meta0_remote_force(m0_url, (gchar*) args->rq->body->data);

			if (!err) {
				err = meta0_remote_cache_refresh(m0_url);
				break;
			} else if (!CODE_IS_NETWORK_ERROR(err->code)) {
				break;
			}
		}
		g_slist_free_full(m0_lst, (GDestroyNotify)service_info_clean);
	}
	if (err)
		return _reply_common_error(args, err);
	return _reply_nocontent(args);
}
Beispiel #26
0
// TODO: factorize the two following functions
enum http_rc_e
action_admin_meta0_list(struct req_args_s *args)
{
	GError *err = NULL;
	GSList *m0_lst = NULL;
	GSList *m1_lst = NULL;
	GString *json = NULL;

	err = conscience_get_services(NS(), NAME_SRVTYPE_META0, FALSE, &m0_lst);
	if (!err) {
		for (GSList *l = m0_lst; l; l = l->next) {
			g_clear_error(&err);
			service_info_t *m0 = l->data;
			gchar m0_url[STRLEN_ADDRINFO] = {0};
			grid_addrinfo_to_string(&(m0->addr), m0_url, sizeof(m0_url));

			err = meta0_remote_get_meta1_all(m0_url, &m1_lst);

			if (!err || !CODE_IS_NETWORK_ERROR(err->code))
				break;
		}
		g_slist_free_full(m0_lst, (GDestroyNotify)service_info_clean);
	}

	if (m1_lst) {
		json = _m0_mapping_from_m1_list(m1_lst);
		meta0_utils_list_clean(m1_lst);
		return _reply_json(args, HTTP_CODE_OK, "OK", json);
	}
	return _reply_common_error(args, err);
}
Beispiel #27
0
static int FASTCALL
NS(initScanContent)(const ENCODING * const enc, const char *ptr, const char *end,
                    const char **nextTokPtr)
{
  return initScan(NS(encodings), (const INIT_ENCODING *)enc,
                  XML_CONTENT_STATE, ptr, end, nextTokPtr);
}
Beispiel #28
0
static int FASTCALL
NS(initScanProlog)(const ENCODING * const enc, const char *ptr, const char *end,
                   const char **nextTokPtr)
{
  return initScan(NS(encodings), (const INIT_ENCODING *)enc,
                  XML_PROLOG_STATE, ptr, end, nextTokPtr);
}
Beispiel #29
0
static void
NS(test_main)(void *arg)
{
  int expected, actual;
  (void)arg;

  NS_MOCK(tls_get_write_overhead_ratio);
  NS_MOCK(we_are_hibernating);
  NS_MOCK(public_server_mode);
  NS_MOCK(get_uptime);
  NS_MOCK(get_bytes_read);
  NS_MOCK(get_bytes_written);
  NS_MOCK(logv);
  NS_MOCK(server_mode);

  log_global_min_severity_ = LOG_DEBUG;

  expected = 0;
  actual = log_heartbeat(0);

  tt_int_op(actual, OP_EQ, expected);
  tt_int_op(NS(n_msgs), OP_EQ, 1);

  done:
    NS_UNMOCK(tls_get_write_overhead_ratio);
    NS_UNMOCK(we_are_hibernating);
    NS_UNMOCK(public_server_mode);
    NS_UNMOCK(get_uptime);
    NS_UNMOCK(get_bytes_read);
    NS_UNMOCK(get_bytes_written);
    NS_UNMOCK(logv);
    NS_UNMOCK(server_mode);
}
Beispiel #30
0
/** \brief create the \b $dump tcl command
 *
 *  \tclmsgque
 *
 * \param[in] clientData command specific data, \e ContextS in this case
 * \param[in] interp the current Tcl interpreter
 * \param[in] objc number of items in the \e objv array
 * \param[in] objv array with arguments of the \c $CTX 'Tcl' command
 * \return Tcl error-code
 **/
static int NS(MqDumpS_Cmd) (
  ClientData clientData,
  Tcl_Interp * interp,
  int objc,
  Tcl_Obj * const objv[]
)
{
  int index;
  struct MqDumpS * dump = (struct MqDumpS *) clientData;

  const static struct LookupKeyword keys[] = {
    { "Size",	    NS(Size)	  },
    { NULL,	    NULL	  }
  };

  if (objc != 2) {
    Tcl_WrongNumArgs (interp, 1, objv, "Get...");
    return TCL_ERROR;
  }

  TclErrorCheck (Tcl_GetIndexFromObjStruct (interp, objv[1], &keys, 
      sizeof(struct LookupKeyword), "subcommand", 0, &index));

  return (*keys[index].keyF) (interp, dump);
}