コード例 #1
0
ファイル: wjeunit.c プロジェクト: kketch/wjelement
static int GetValueTest(WJElement doc)
{
	char	*v;

	if (1 != WJENumber(doc, "one",			WJE_GET, -1))	return(__LINE__);
	if (2 != WJENumber(doc, "two",			WJE_GET, -1))	return(__LINE__);
	if (3 != WJENumber(doc, "three",		WJE_GET, -1))	return(__LINE__);
	if (-1!= WJENumber(doc, "four",			WJE_GET, -1))	return(__LINE__);

	if (0 != WJENumber(doc, "digits[0]",	WJE_GET, -1))	return(__LINE__);
	if (1 != WJENumber(doc, "digits[1]",	WJE_GET, -1))	return(__LINE__);
	if (9 != WJENumber(doc, "digits[-1]",	WJE_GET, -1))	return(__LINE__);
	if (9 != WJENumber(doc, "digits[$]",	WJE_GET, -1))	return(__LINE__);
	if (-1!= WJENumber(doc, "digits[10]",	WJE_GET, -1))	return(__LINE__);


	if (!WJEBool(doc, "a.b.balloon",		WJE_GET, 0))	return(__LINE__);
	if ( WJEBool(doc, "a.b.aardvark",		WJE_GET, 1))	return(__LINE__);
	if (!WJEBool(doc, "a.b.bull",			WJE_GET, 1))	return(__LINE__);
	if ( WJEBool(doc, "a.b.another",		WJE_GET, 0))	return(__LINE__);

	if (!(v = WJEString(doc, "a.names[-1]",		WJE_GET, NULL)) ||
		stricmp(v, "a"))									return(__LINE__);
	if (!(v = WJEString(doc, "a.b.names[-1]",	WJE_GET, NULL)) ||
		stricmp(v, "b"))									return(__LINE__);
	if ( (v = WJEString(doc, "a.b.nonames[-1]",	WJE_GET, NULL)))
															return(__LINE__);

	return(0);
}
コード例 #2
0
ファイル: wjeunit.c プロジェクト: kketch/wjelement
static int SetValueTest(WJElement doc)
{
	char	*v;

	/*
		WJE_SET will update the value if it already exists, or create the
		element if it doesn't exist.

		Do a WJE_SET on values that do and do not already exist, and verify the
		result.  Then do a WJE_GET to verify that the element does exist.
	*/

	/* Replace existing number values */
	if (-1!= WJENumber(doc, "one",			WJE_SET, -1))	return(__LINE__);
	if (-1!= WJENumber(doc, "one",			WJE_GET,  1))	return(__LINE__);
	if (-1!= WJENumber(doc, "two",			WJE_SET, -1))	return(__LINE__);
	if (-1!= WJENumber(doc, "two",			WJE_GET,  2))	return(__LINE__);
	if (-1!= WJENumber(doc, "three",		WJE_SET, -1))	return(__LINE__);
	if (-1!= WJENumber(doc, "three",		WJE_GET,  3))	return(__LINE__);

	/* Insert a new number value */
	if (-1!= WJENumber(doc, "four",			WJE_SET, -1))	return(__LINE__);
	if (-1!= WJENumber(doc, "four",			WJE_GET,  4))	return(__LINE__);

	/* Replace existing boolean values */
	if ( WJEBool(doc, "a.b.balloon",		WJE_SET, 0))	return(__LINE__);
	if ( WJEBool(doc, "a.b.balloon",		WJE_GET, 1))	return(__LINE__);
	if (!WJEBool(doc, "a.b.aardvark",		WJE_SET, 1))	return(__LINE__);
	if (!WJEBool(doc, "a.b.aardvark",		WJE_GET, 0))	return(__LINE__);

	/* Insert a new boolean value */
	if (!WJEBool(doc, "a.b.bull",			WJE_SET, 1))	return(__LINE__);
	if (!WJEBool(doc, "a.b.bull",			WJE_GET, 0))	return(__LINE__);

	/* Replace an existing string value */
	if (!(v = WJEString(doc, "a.names[-1]",	WJE_SET, "aardvark")))
															return(__LINE__);
	if (!(v = WJEString(doc, "a.names[-1]",	WJE_GET, NULL)) ||
		stricmp(v, "aardvark"))
															return(__LINE__);

	/* Insert a new string value */
	if (!(v = WJEString(doc, "a.x.q",		WJE_SET, "queen")))
															return(__LINE__);
	if (!(v = WJEString(doc, "a.x.q",		WJE_GET, NULL)) ||
		stricmp(v, "queen"))
															return(__LINE__);
	return(0);
}
コード例 #3
0
    void initialize(PLCContext *plContext, WJElement node) {
        this->plContext = plContext;

        if( node == NULL )
        {
            measureName = 
                plContext->strategyParams.FetchNameValueDef("scene_measure", 
                                                            "NULL");
            // Do we have rescaling values to try to bring this into 0.0 to 1.0?
            CPLString minPrefix = "scale_min:";
            scaleMin = 
                atof(plContext->strategyParams.FetchNameValueDef(
                         (minPrefix + measureName).c_str(), "0.0"));
            CPLString maxPrefix = "scale_max:";
            scaleMax = 
                atof(plContext->strategyParams.FetchNameValueDef(
                         (maxPrefix + measureName).c_str(), "1.0"));
        }
        else
        {
            measureName = WJEString(node, "scene_measure", WJE_GET, "");
            scaleMin = WJEDouble(node, "scale_min", WJE_GET, 0.0);
            scaleMax = WJEDouble(node, "scale_max", WJE_GET, 1.0);
        }
    }
コード例 #4
0
ファイル: wjeunit.c プロジェクト: kketch/wjelement
static int PutValueTest(WJElement doc)
{
	char	*v;

	/*
		WJE_PUT will update the value if the element exists.  If it does not
		exist then it will NOT create it.

		Do a WJE_PUT on values that do and do not already exist, and verify the
		result.  Then use WJEGet() to verify that new elements where not
		created.
	*/

	/* Replace existing number values */
	if (-1!= WJENumber(doc, "one",			WJE_PUT, -1))	return(__LINE__);
	if (-1!= WJENumber(doc, "one",			WJE_GET,  1))	return(__LINE__);
	if (-1!= WJENumber(doc, "two",			WJE_PUT, -1))	return(__LINE__);
	if (-1!= WJENumber(doc, "two",			WJE_GET,  2))	return(__LINE__);
	if (-1!= WJENumber(doc, "three",		WJE_PUT, -1))	return(__LINE__);
	if (-1!= WJENumber(doc, "three",		WJE_GET,  3))	return(__LINE__);

	/* Insert a new number value */
	if (-1== WJENumber(doc, "four",			WJE_PUT, -1))	return(__LINE__);
	if (WJEGet(doc, "four", NULL))							return(__LINE__);

	/* Replace existing boolean values */
	if ( WJEBool(doc, "a.b.balloon",		WJE_PUT, 0))	return(__LINE__);
	if (!WJEBool(doc, "a.b.aardvark",		WJE_PUT, 1))	return(__LINE__);

	/* Insert a new boolean value */
	if ( WJEBool(doc, "a.b.bull",			WJE_PUT, 1))	return(__LINE__);
	if (WJEGet(doc, "a.b.bull", NULL))						return(__LINE__);

	/* Replace an existing string value */
	if (!(v = WJEString(doc, "a.names[-1]",	WJE_PUT, "aardvark")) ||
		stricmp(v, "aardvark"))
															return(__LINE__);
	if (!(v = WJEString(doc, "a.names[-1]",	WJE_GET, NULL)) ||
		stricmp(v, "aardvark"))
															return(__LINE__);

	/* Insert a new string value */
	if ((v = WJEString(doc, "a.x.q",		WJE_PUT, "queen")))
															return(__LINE__);
	if (WJEGet(doc, "a.x.q", NULL))							return(__LINE__);
	return(0);
}
コード例 #5
0
ファイル: wjeunit.c プロジェクト: kketch/wjelement
static int NewValueTest(WJElement doc)
{
	char	*v;

	/*
		WJE_NEW will not leave the original value if it already exists, or
		create the element if it doesn't.

		Do a WJE_NEW on values that do and do not already exist, and verify the
		result.  Then do a WJE_GET to verify that the creation of elements
		actually worked.
	*/

	/* Replace existing number values */
	if ( 1!= WJENumber(doc, "one",			WJE_NEW, -1))	return(__LINE__);
	if ( 2!= WJENumber(doc, "two",			WJE_NEW, -1))	return(__LINE__);
	if ( 3!= WJENumber(doc, "three",		WJE_NEW, -1))	return(__LINE__);

	/* Insert a new number value */
	if (-1!= WJENumber(doc, "four",			WJE_NEW, -1))	return(__LINE__);
	if (-1!= WJENumber(doc, "four",			WJE_GET,  4))	return(__LINE__);

	/* Replace existing boolean values */
	if (!WJEBool(doc, "a.b.balloon",		WJE_NEW, 0))	return(__LINE__);
	if ( WJEBool(doc, "a.b.aardvark",		WJE_NEW, 1))	return(__LINE__);

	/* Insert a new boolean value */
	if (!WJEBool(doc, "a.b.bull",			WJE_NEW, 1))	return(__LINE__);
	if (!WJEBool(doc, "a.b.bull",			WJE_GET, 0))	return(__LINE__);

	/* Replace an existing string value */
	if (!(v = WJEString(doc, "a.names[-1]",	WJE_NEW, "aardvark")) ||
		stricmp(v, "a"))
															return(__LINE__);
	if (!(v = WJEString(doc, "a.names[-1]",	WJE_GET, NULL)) ||
		stricmp(v, "a"))
															return(__LINE__);

	/* Insert a new string value */
	if (!(v = WJEString(doc, "a.x.q",		WJE_NEW, "queen")) ||
		stricmp(v, "queen"))
															return(__LINE__);
	if (!(v = WJEString(doc, "a.x.q",		WJE_GET, NULL)) ||
		stricmp(v, "queen"))
															return(__LINE__);
	return(0);
}
コード例 #6
0
ファイル: element.c プロジェクト: AydinSakar/wjelement
static WJElement _WJECopy(_WJElement *parent, WJElement original, WJECopyCB copycb, void *data, const char *file, const int line)
{
	_WJElement	*l = NULL;
	_WJElement	*o;
	WJElement	c;
	char		*tmp;

	if (!(o = (_WJElement *) original)) {
		return(NULL);
	}

	if (copycb && !copycb((WJElement) parent, (WJElement) original, data, file, line)) {
		/* The consumer has rejected this item */
		return(NULL);
	}

	if ((l = _WJENew(parent, original->name, original->name ? strlen(original->name) : 0, file, line))) {
		switch ((l->pub.type = original->type)) {
			default:
			case WJR_TYPE_UNKNOWN:
			case WJR_TYPE_NULL:
				break;

			case WJR_TYPE_OBJECT:
			case WJR_TYPE_ARRAY:
				for (c = original->child; c; c = c->next) {
					_WJECopy(l, c, copycb, data, file, line);
				}
				break;

			case WJR_TYPE_STRING:
				if ((tmp = WJEString(original, NULL, WJE_GET, ""))) {
					l->value.string = MemStrdup(tmp);
					l->pub.length = original->length;
				} else {
					l->value.string = MemStrdup("");
					l->pub.length = 0;
				}
				break;

			case WJR_TYPE_NUMBER:
				l->value.number.negative		= o->value.number.negative;
				l->value.number.i				= o->value.number.i;
				l->value.number.d				= o->value.number.d;
				l->value.number.hasDecimalPoint	= o->value.number.hasDecimalPoint;
				break;

			case WJR_TYPE_TRUE:
			case WJR_TYPE_BOOL:
			case WJR_TYPE_FALSE:
				l->value.boolean = WJEBool(original, NULL, WJE_GET, FALSE);
				break;
		}
	}

	return((WJElement) l);
}
コード例 #7
0
ファイル: plccontext.cpp プロジェクト: barrycug/plcompositor
void PLCContext::initializeFromJson(WJElement doc)

{
    outputFilename = WJEString(doc, "output_file", WJE_GET, outputFilename);
    sourceTraceFilename = 
        WJEString(doc, "source_trace", WJE_GET, sourceTraceFilename);
    qualityFilename = 
        WJEString(doc, "quality_output", WJE_GET, qualityFilename);

    initializeQualityMethods( WJEArray(doc, "compositors", WJE_GET) );
    
    WJElement input_def = NULL;
    while( (input_def = _WJEObject(doc, "inputs[]", WJE_GET, &input_def)) )
    {
        // Consume a whole PLCInput definition.
        PLCInput *input = new PLCInput(inputFiles.size());
        input->ConsumeJson(input_def);
        inputFiles.push_back(input);
    }
}
コード例 #8
0
ファイル: example.c プロジェクト: Markchill/wjelement
int main(int argc, char **argv) {
	WJElement doc = NULL;
	WJElement person = NULL;

	doc = WJEObject(NULL, NULL, WJE_NEW);
	WJEString(doc, "name", WJE_SET, "Serenity");
	WJEString(doc, "class", WJE_SET, "firefly");
	WJEArray(doc, "crew", WJE_SET);

	WJEObject(doc, "crew[$]", WJE_NEW);
	WJEString(doc, "crew[-1].name", WJE_SET, "Malcolm Reynolds");
	WJEString(doc, "crew[-1].job", WJE_SET, "captain");
	WJEInt64(doc, "crew[-1].born", WJE_SET, 2468);

	WJEObject(doc, "crew[$]", WJE_NEW);
	WJEString(doc, "crew[-1].name", WJE_SET, "Kaywinnet Lee Fry");
	WJEString(doc, "crew[-1].job", WJE_SET, "mechanic");
	WJEInt64(doc, "crew[-1].born", WJE_SET, 2494);

	WJEObject(doc, "crew[$]", WJE_NEW);
	WJEString(doc, "crew[-1].name", WJE_SET, "Jayne Cobb");
	WJEString(doc, "crew[-1].job", WJE_SET, "public relations");
	WJEInt64(doc, "crew[-1].born", WJE_SET, 2485);

	WJEBool(doc, "shiny", WJE_SET, TRUE);

	WJEInt64(doc, "crew[].born == 2468", WJE_SET, 2486);  /* note: awesome! */
	WJECloseDocument(WJEGet(doc, "shiny", NULL));

	while((person = _WJEObject(doc, "crew[]", WJE_GET, &person))) {
		printf("%s (%s) is %d\n",
			   WJEString(person, "name", WJE_GET, ""),
			   WJEString(person, "job", WJE_GET, ""),
			   2517 - WJEInt64(person, "born", WJE_GET, 0));
	}

	WJEDump(doc);
	WJECloseDocument(doc);
	return 0;
}
コード例 #9
0
ファイル: hash.c プロジェクト: netmail-open/wjelement
static void _WJEHash(WJElement document, int depth, WJEHashCB update, void *context)
{
	WJElement	child;
	char		*s;
	int32		n;
	uint32		b;

	if (!document) {
		return;
	}

	switch (document->type) {
		default:
		case WJR_TYPE_UNKNOWN:
			break;

		case WJR_TYPE_NULL:
			update(context, "", 1);
			break;

		case WJR_TYPE_OBJECT:
			update(context, &depth, sizeof(depth));

			for (child = document->child; child; child = child->next) {
				if (child->name) {
					update(context, child->name, strlen(child->name) + 1);
				}
				_WJEHash(child, depth + 1, update, context);
			}

			update(context, &depth, sizeof(depth));
			break;

		case WJR_TYPE_ARRAY:
			update(context, &depth, sizeof(depth));

			for (child = document->child; child; child = child->next) {
				update(context, "", 1);
				_WJEHash(child, depth + 1, update, context);
			}

			update(context, &depth, sizeof(depth));
			break;

		case WJR_TYPE_STRING:
			if ((s = WJEString(document, NULL, WJE_GET, ""))) {
				update(context, s, strlen(s) + 1);
			}

			break;

		case WJR_TYPE_NUMBER:
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
		case WJR_TYPE_INTEGER:
#endif
			n = WJENumber(document, NULL, WJE_GET, 0);
			update(context, &n, sizeof(n));

			break;

		case WJR_TYPE_TRUE:
		case WJR_TYPE_BOOL:
		case WJR_TYPE_FALSE:
			b = WJEBool(document, NULL, WJE_GET, FALSE);
			update(context, &b, sizeof(b));
			break;
	}
}
コード例 #10
0
ファイル: plccontext.cpp プロジェクト: barrycug/plcompositor
void PLCContext::initializeQualityMethods(WJElement compositors)

{
    // Backward compatability mode
    if( compositors == NULL )
    {
        QualityMethodBase *method = NULL;
        CPLDebug("PLC", "initializeQualityMethods() - pre-json mode.");

        if( getStratParam("cloud_quality") != NULL )
        {
            method = QualityMethodBase::CreateQualityFunction(
                this, NULL,
                strategyParams.FetchNameValue("cloud_quality"));
            CPLAssert( method != NULL );
            qualityMethods.push_back(method);
        }

        method = 
            QualityMethodBase::CreateQualityFunction(
                this, NULL, 
                strategyParams.FetchNameValueDef("quality", "darkest"));
        
        CPLAssert( method != NULL );
        qualityMethods.push_back(method);

        if(getStratParam("quality_file") != NULL)
        {
            method = QualityMethodBase::CreateQualityFunction(
                this, NULL, "qualityfromfile");
            CPLAssert( method != NULL );
            qualityMethods.push_back(method);
        }

        if( EQUAL(getStratParam("compositor",""),"median")
            || getStratParam("median_ratio") != NULL
            || getStratParam("quality_percentile") != NULL )
        {
            method = QualityMethodBase::CreateQualityFunction(
                this, NULL, "percentile");
            CPLAssert( method != NULL );
            qualityMethods.push_back(method);
        }

        return;
    }

    WJElement method_def = NULL;
    while( (method_def = _WJEObject(compositors, "[]", WJE_GET, &method_def)) )
    {
        CPLString methodClass = WJEString(method_def, "class", WJE_GET, NULL);

        CPLAssert(strlen(methodClass) > 0);

        QualityMethodBase *method = 
            QualityMethodBase::CreateQualityFunction(
                this, method_def, methodClass);
        CPLAssert( method != NULL );
        qualityMethods.push_back(method);
    }
}
コード例 #11
0
ファイル: example.c プロジェクト: AdvancedC/wjelement
int main(int argc, char **argv) {
	WJElement doc = NULL;
	WJElement person = NULL;
	WJElement cameo = NULL;

	doc = WJEObject(NULL, NULL, WJE_NEW);
	WJEString(doc, "name", WJE_SET, "Serenity");
	WJEString(doc, "class", WJE_SET, "firefly");
	WJEArray(doc, "crew", WJE_SET);

	WJEObject(doc, "crew[$]", WJE_NEW);
	WJEString(doc, "crew[-1].name", WJE_SET, "Malcolm Reynolds");
	WJEString(doc, "crew[-1].job", WJE_SET, "captain");
	WJEInt64(doc, "crew[-1].born", WJE_SET, 2468);

	WJEObject(doc, "crew[$]", WJE_NEW);
	WJEString(doc, "crew[-1].name", WJE_SET, "Kaywinnet Lee Fry");
	WJEString(doc, "crew[-1].job", WJE_SET, "mechanic");
	WJEInt64(doc, "crew[-1].born", WJE_SET, 2494);

	WJEObject(doc, "crew[$]", WJE_NEW);
	WJEString(doc, "crew[-1].name", WJE_SET, "Jayne Cobb");
	WJEString(doc, "crew[-1].job", WJE_SET, "public relations");
	WJEInt64(doc, "crew[-1].born", WJE_SET, 2485);

	WJEArray(doc, "cameo", WJE_SET);
	WJEString(doc, "cameo[$]", WJE_NEW, "Battlestar Galactica");
	WJEString(doc, "cameo[$]", WJE_NEW, "Star Wars Evasive Action");
	WJEString(doc, "cameo[$]", WJE_NEW, "Dr. Horrible's Sing-Along Blog");
	WJEString(doc, "cameo[$]", WJE_NEW, "Ready Player One");

	WJEBool(doc, "shiny", WJE_SET, TRUE);

	WJEInt64(doc, "crew[].born == 2468", WJE_SET, 2486);  /* note: awesome! */
	WJECloseDocument(WJEGet(doc, "shiny", NULL));

	while((person = _WJEObject(doc, "crew[]", WJE_GET, &person))) {
		printf("%s (%s) is %"PRId64"\n",
			   WJEString(person, "name", WJE_GET, ""),
			   WJEString(person, "job", WJE_GET, ""),
			   (2517 - WJEInt64(person, "born", WJE_GET, 0)));
	}
	while((cameo = WJEGet(doc, "cameo[]", cameo))) {
		printf("Cameo: %s\n", WJEString(cameo, NULL, WJE_GET, ""));
	}

	WJEDump(doc);
	WJECloseDocument(doc);
	return 0;
}
コード例 #12
0
ファイル: wjeunit.c プロジェクト: kketch/wjelement
/*
	A | may be used to indicate that the remaining portion of the selector is
	optional if the match up to that point is valid and has no children.
*/
static int OptionalsTest(WJElement doc)
{
	/* Make sure simple things behave as expected */
	if (!WJEString(doc, "string",		WJE_GET, NULL))		return(__LINE__);
	if ( WJEString(doc, "strings",		WJE_GET, NULL))		return(__LINE__);

	if (!WJEString(doc, "strings[0]",	WJE_GET, NULL))		return(__LINE__);
	if (!WJEString(doc, "strings[$]",	WJE_GET, NULL))		return(__LINE__);
	if (!WJEString(doc, "strings[]",	WJE_GET, NULL))		return(__LINE__);

	if ( WJEString(doc, "string[0]",	WJE_GET, NULL))		return(__LINE__);
	if ( WJEString(doc, "string[$]",	WJE_GET, NULL))		return(__LINE__);
	if ( WJEString(doc, "string[]",		WJE_GET, NULL))		return(__LINE__);

	/*
		Now for the fun part, add the | to get the same results for an array of
		strings as we get for a single string.
	*/
	if (!WJEString(doc, "strings|[0]",	WJE_GET, NULL))		return(__LINE__);
	if (!WJEString(doc, "strings|[$]",	WJE_GET, NULL))		return(__LINE__);
	if (!WJEString(doc, "strings|[]",	WJE_GET, NULL))		return(__LINE__);

	if (!WJEString(doc, "string|[0]",	WJE_GET, NULL))		return(__LINE__);
	if (!WJEString(doc, "string|[$]",	WJE_GET, NULL))		return(__LINE__);
	if (!WJEString(doc, "string|[]",	WJE_GET, NULL))		return(__LINE__);

	return(0);
}