예제 #1
0
파일: jsonobj.cpp 프로젝트: rtucker/jsonapi
std::string 
JsonValue::ToJson(std::string &str)
{
    char buf[128];
    JsonTuple *tup;

    switch(GetType()) {
    case JsonType_Bool:
        if (m_boolVal == true) {
            str += "true";
        } else {
            str += "false";
        }
        break;
    case JsonType_Null:
        str += "null";
        break;
    case JsonType_Double:
        sprintf(buf, "%g", m_dblVal);
        str += buf;
        break;
    case JsonType_Number:
        sprintf(buf, "%ld", m_longVal);
        str += buf;
        break;
    case JsonType_String:
        snprintf(buf, sizeof(buf), "%s", m_strVal.c_str());
        str += buf;
        break;
    case JsonType_Object:
        str += "{"; 
        str = DumpChildren(str);
        str += "}";
        break;
    case JsonType_Array:
        str += "["; 
        str = DumpChildren(str);
        str += "]";
        break;
    case JsonType_Tuple:
        tup = static_cast<JsonTuple *>(this);
        str += tup->GetKey();
        str += " : ";
        str = tup->GetKeyValue()->ToJson(str);
        break;
    case JsonType_Root:
        str = DumpChildren(str);
        break;
    } 
    return str;
}
예제 #2
0
// -----------------------------------------------------------------------------------------
//	DumpChildren
// -----------------------------------------------------------------------------------------
void DumpChildren (ICAObject    object,
                   UInt32		indent,
                   char*		blanks)
{
    ICAGetChildCountPB 	countPB;
    OSErr				err;
    char 				localBuffer[256];

    memset(&countPB, 0, sizeof(ICAGetChildCountPB));
    countPB.object = object;
    err = ICAGetChildCount(&countPB, NULL);
    if (err == noErr)
    {
        UInt32				childLoop;
        ICAGetNthChildPB	nPB;
        UInt32				localIndex;

        for (childLoop = 0; childLoop < countPB.count; childLoop++)
        {
            memset(&nPB, 0, sizeof(ICAGetNthChildPB));
            nPB.parentObject = object;
            nPB.index        = childLoop;
            err = ICAGetNthChild(&nPB, NULL);

            if (err == noErr)
            {
                memcpy(localBuffer, blanks, 255);
                localIndex = indent * kINDENT + 1;
                localBuffer[localIndex++] = '|';
                localBuffer[localIndex] = 0;
                printf("  %s\n", localBuffer);

                memcpy(localBuffer, blanks, 255);
                localIndex = indent * kINDENT + 1;
                localBuffer[localIndex++] = '+';
                memset(&localBuffer[localIndex], '-', kINDENT - 1);
                localIndex += kINDENT - 1;
                localBuffer[localIndex] = 0;

                printf("  %s[%4.4s]  [%4.4s]  [%08lX]\n", localBuffer, (char*)&nPB.childInfo.objectType, (char*)&nPB.childInfo.objectSubtype, (long)nPB.childObject);

                if ((nPB.childInfo.objectType == kICADirectory) || (nPB.childInfo.objectType == kICADevice))
                {
                    if (childLoop < countPB.count-1)
                        blanks[indent * kINDENT + 1] = '|';
                    DumpChildren(nPB.childObject, indent+1, blanks);
                    blanks[indent * kINDENT + 1] = ' ';
                }
            }
        }
    }
}// -----------------------------------------------------------------------------------------
예제 #3
0
// -----------------------------------------------------------------------------------------
//	main
// -----------------------------------------------------------------------------------------
int main (int 			argc,
          const char * 	argv[])
{
    ICAGetDeviceListPB 	pb;
    char 				blanks[255];
    int					c;
    int					printAll = false;
    
	while ((c=getopt(argc, argv, "ha"))!=-1)
    {
        switch (c)
        {
            case 'h':
                PrintHelp();
                return 0;
                break;
            case 'a':
                printAll = true;
                break;
        }
        //printf("option = %c\n", c);
    }

    printf("==========================\n");
    printf("=    ICAObjectDumper     =\n");
    printf("==========================\n\n");

    memset(&pb, 0, sizeof(ICAGetDeviceListPB));

    ICAGetDeviceList(&pb, NULL);

    printf("devicelist [%08lX]\n", (long)pb.object);
    memset(blanks, ' ', 255);
    if (printAll)
        DumpChildrenWithProperties(pb.object, 1, blanks);
    else
        DumpChildren(pb.object, 1, blanks);
    return 0;
}