16fdc50e4e49b031f566911bf0371d4942282d75
larrym
  Fri Apr 27 16:22:37 2012 -0700
use a union in jsonElement to simplify code and eliminate typecasts (per suggestion of angie and tim); rename jsonHash to jsonObject; fix some obsolete comments
diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c
index 231a287..16e8e81 100644
--- src/hg/hgTracks/hgTracks.c
+++ src/hg/hgTracks/hgTracks.c
@@ -114,31 +114,31 @@
     {
     "hide",
     "dense",
     "full"
     };
 
 char *protDbName;               /* Name of proteome database for this genome. */
 #define MAX_CONTROL_COLUMNS 6
 #define LOW 1
 #define MEDIUM 2
 #define BRIGHT 3
 #define MAXCHAINS 50000000
 boolean hgDebug = FALSE;      /* Activate debugging code. Set to true by hgDebug=on in command line*/
 int imagePixelHeight = 0;
 struct hash *oldVars = NULL;
-struct jsonHashElement *jsonForClient = NULL;
+struct jsonElement *jsonForClient = NULL;
 
 boolean hideControls = FALSE;		/* Hide all controls? */
 boolean trackImgOnly = FALSE;           /* caller wants just the track image and track table html */
 boolean ideogramToo =  FALSE;           /* caller wants the ideoGram (when requesting just one track) */
 
 /* Structure returned from findGenomePos.
  * We use this to to expand any tracks to full
  * that were found to contain the searched-upon
  * position string */
 struct hgPositions *hgp = NULL;
 
 /* Other global variables. */
 struct trackHub *hubList = NULL;	/* List of all relevant hubs. */
 struct group *groupList = NULL;    /* List of all tracks. */
 char *browserName;              /* Test, preview, or public browser */
@@ -2516,53 +2516,53 @@
         if(theImgBox)
             {
             // Set imgTrack in case any map items will be set
             sliceHeight      = trackPlusLabelHeight(track, fontHeight);
             sliceOffsetY     = y;
             curImgTrack = imgBoxTrackFind(theImgBox,track->tdb,NULL);
             }
         y = doTrackMap(track, hvg, y, fontHeight, trackPastTabX, trackPastTabWidth);
         }
     }
 
 /* Finish map. */
 hPrintf("</MAP>\n");
 
 // turn off inPlaceUpdate when rows in imgTbl can arbitrarily reappear and disappear (see redmine #7306 and #6944)
-jsonHashAddBoolean(jsonForClient, "inPlaceUpdate", withLeftLabels && withCenterLabels);
-jsonHashAddNumber(jsonForClient, "rulerClickHeight", rulerClickHeight);
+jsonObjectAdd(jsonForClient, "inPlaceUpdate", newJsonBoolean(withLeftLabels && withCenterLabels));
+jsonObjectAdd(jsonForClient, "rulerClickHeight", newJsonNumber(rulerClickHeight));
 if(newWinWidth)
     {
-    jsonHashAddNumber(jsonForClient, "newWinWidth", newWinWidth);
+    jsonObjectAdd(jsonForClient, "newWinWidth", newJsonNumber(newWinWidth));
     }
 
 /* Save out picture and tell html file about it. */
 if(hvgSide != hvg)
     hvGfxClose(&hvgSide);
 hvGfxClose(&hvg);
 
 #ifdef SUPPORT_CONTENT_TYPE
 char *type = cartUsualString(cart, "hgt.contentType", "html");
 if(sameString(type, "jsonp"))
     {
-    struct jsonHashElement *json = newJsonHash(newHash(8));
+    struct jsonElement *json = newJsonObject(newHash(8));
 
     printf("Content-Type: application/json\n\n");
-    jsonHashAddString(json, "track", cartString(cart, "hgt.trackNameFilter"));
-    jsonHashAddNumber(json, "height", pixHeight);
-    jsonHashAddNumber(json, "width", pixWidth);
-    jsonHashAddString(json, "img", gifTn.forHtml);
+    jsonObjectAdd(json, "track", newJsonString(cartString(cart, "hgt.trackNameFilter")));
+    jsonObjectAdd(json, "height", newJsonNumber(pixHeight));
+    jsonObjectAdd(json, "width", newJsonNumber(pixWidth));
+    jsonObjectAdd(json, "img", newJsonString(gifTn.forHtml));
     printf("%s(", cartString(cart, "jsonp"));
     hPrintEnable();
     jsonPrint((struct jsonElement *) json, NULL, 0);
     hPrintDisable();
     printf(")\n");
     return;
     }
 else if(sameString(type, "png") || sameString(type, "pdf") || sameString(type, "eps"))
     {
     // following code bypasses html and return png's directly - see redmine 4888
     char *file;
     if(sameString(type, "pdf"))
         {
         printf("Content-Disposition: filename=hgTracks.pdf\nContent-Type: application/pdf\n\n");
         file = convertEpsToPdf(psOutput);
@@ -4676,32 +4676,32 @@
 zoomedToBaseLevel = (winBaseCount <= insideWidth / tl.mWidth);
 zoomedToCodonLevel = (ceil(winBaseCount/3) * tl.mWidth) <= insideWidth;
 zoomedToCdsColorLevel = (winBaseCount <= insideWidth*3);
 
 if (psOutput != NULL)
    {
    hPrintDisable();
    hideControls = TRUE;
    withNextItemArrows = FALSE;
    withNextExonArrows = FALSE;
    hgFindMatches = NULL;
    }
 
 /* Tell browser where to go when they click on image. */
 hPrintf("<FORM ACTION=\"%s\" NAME=\"TrackHeaderForm\" id=\"TrackHeaderForm\" METHOD=\"GET\">\n\n", hgTracksName());
-jsonHashAddNumber(jsonForClient, "insideX", insideX);
-jsonHashAddBoolean(jsonForClient, "revCmplDisp", revCmplDisp);
+jsonObjectAdd(jsonForClient, "insideX", newJsonNumber(insideX));
+jsonObjectAdd(jsonForClient, "revCmplDisp", newJsonBoolean(revCmplDisp));
 
 if (hPrintStatus()) cartSaveSession(cart);
 clearButtonJavascript = "document.TrackHeaderForm.position.value=''; document.getElementById('suggest').value='';";
 
 /* See if want to include sequence search results. */
 userSeqString = cartOptionalString(cart, "ss");
 if (userSeqString && !ssFilesExist(userSeqString))
     {
     userSeqString = NULL;
     cartRemove(cart, "ss");
     }
 if (!hideControls)
     hideControls = cartUsualBoolean(cart, "hideControls", FALSE);
 if (measureTiming)
     measureTime("Time before getTrackList");
@@ -4851,33 +4851,33 @@
     }
 
 if(theImgBox)
     {
     // If a portal was established, then set the global dimensions back to the portal size
     if(imgBoxPortalDimensions(theImgBox,NULL,NULL,NULL,NULL,&winStart,&winEnd,&(tl.picWidth),NULL))
         {
         winBaseCount = winEnd - winStart;
         insideWidth = tl.picWidth-gfxBorder-insideX;
         }
     }
 /* Center everything from now on. */
 hPrintf("<CENTER>\n");
 
 // info for drag selection javascript
-jsonHashAddNumber(jsonForClient, "winStart", winStart);
-jsonHashAddNumber(jsonForClient, "winEnd", winEnd);
-jsonHashAddString(jsonForClient, "chromName", chromName);
+jsonObjectAdd(jsonForClient, "winStart", newJsonNumber(winStart));
+jsonObjectAdd(jsonForClient, "winEnd", newJsonNumber(winEnd));
+jsonObjectAdd(jsonForClient, "chromName", newJsonString(chromName));
 
 if(trackImgOnly && !ideogramToo)
     {
     struct track *ideoTrack = chromIdeoTrack(trackList);
     if (ideoTrack)
         {
         ideoTrack->limitedVisSet = TRUE;
         ideoTrack->limitedVis = tvHide; /* Don't draw in main gif. */
         }
     makeActiveImage(trackList, psOutput);
     fflush(stdout);
     return;  // bail out b/c we are done
     }
 
 
@@ -4994,31 +4994,31 @@
 		{
 		hPuts("Organism ");
 		printAssemblyListHtmlExtra(database, javascript);
 		}
 
 	sprintf(buf, "%s:%d-%d", chromName, winStart+1, winEnd);
 	position = cloneString(buf);
 #ifdef MERGE_GENE_SUGGEST
 	hPrintf("<span class='positionDisplay' id='positionDisplay' title='click to copy position to input box'>%s</span>", addCommasToPos(database, position));
 	hPrintf("<input type='hidden' name='position' id='position' value='%s'>\n", buf);
 	sprintLongWithCommas(buf, winEnd - winStart);
 	hPrintf(" <span id='size'>%s</span> bp. ", buf);
 	hPrintf("<input class='positionInput' type='text' name='hgt.positionInput' id='positionInput' size='60'>\n");
 	hWrites(" ");
 	hButtonWithOnClick("hgt.jump", "go", NULL, "imageV2.jumpButtonOnClick()");
-	jsonHashAddBoolean(jsonForClient, "assemblySupportsGeneSuggest", assemblySupportsGeneSuggest(database));
+	jsonObjectAdd(jsonForClient, "assemblySupportsGeneSuggest", newJsonBoolean(assemblySupportsGeneSuggest(database)));
 	if(assemblySupportsGeneSuggest(database))
 	    hPrintf("<input type='hidden' name='hgt.suggestTrack' id='suggestTrack' value='%s'>\n", assemblyGeneSuggestTrack(database));
 #else///ifndef MERGE_GENE_SUGGEST
 	hWrites("position/search ");
 	hTextVar("position", addCommasToPos(database, position), 30);
 	sprintLongWithCommas(buf, winEnd - winStart);
 	if(assemblySupportsGeneSuggest(database))
             hPrintf(" <a title='click for help on gene search box' target='_blank' href='../goldenPath/help/geneSearchBox.html'>gene</a> "
                     "<input type='text' size='8' name='hgt.suggest' id='suggest'>\n"
                     "<input type='hidden' name='hgt.suggestTrack' id='suggestTrack' value='%s'>\n", assemblyGeneSuggestTrack(database)
                     );
 	hWrites(" ");
 	hButtonWithOnClick("hgt.jump", "jump", NULL, "imageV2.jumpButtonOnClick()");
 	hOnClickButton(clearButtonJavascript,"clear");
 	hPrintf(" size <span id='size'>%s</span> bp. ", buf);
@@ -5962,32 +5962,32 @@
 
 char *configPageCall = cartCgiUsualString(cart, "hgTracksConfigPage", "notSet");
 
 /* Do main display. */
 
 if (cartUsualBoolean(cart, "hgt.trackImgOnly", FALSE))
     {
     trackImgOnly = TRUE;
     ideogramToo = cartUsualBoolean(cart, "hgt.ideogramToo", FALSE);
     hideControls = TRUE;
     withNextItemArrows = FALSE;
     withNextExonArrows = FALSE;
     hgFindMatches = NULL;     // XXXX necessary ???
     }
 
-jsonForClient = newJsonHash(newHash(8));
-jsonHashAddString(jsonForClient, "cgiVersion", CGI_VERSION);
+jsonForClient = newJsonObject(newHash(8));
+jsonObjectAdd(jsonForClient, "cgiVersion", newJsonString(CGI_VERSION));
 boolean searching = differentString(cartUsualString(cart, TRACK_SEARCH,"0"), "0");
 
 if(!trackImgOnly)
     {
     // Write out includes for css and js files
     hWrites(commonCssStyles());
     jsIncludeFile("jquery.js", NULL);
     jsIncludeFile("jquery-ui.js", NULL);
     jsIncludeFile("utils.js", NULL);
     jsIncludeFile("ajax.js", NULL);
 #ifdef MERGE_GENE_SUGGEST
     jsIncludeFile("jquery.watermarkinput.js", NULL);
 #endif///def MERGE_GENE_SUGGEST
     if(!searching)
         {
@@ -6078,21 +6078,21 @@
 else if (cartVarExists(cart, configShowEncodeGroups))
     {
     /* currently not used */
     cartRemove(cart, configShowEncodeGroups);
     struct grp *grp = NULL, *grps = hLoadGrps(database);
     for (grp = grps; grp != NULL; grp = grp->next)
         if (startsWith("encode", grp->name))
             collapseGroup(grp->name, FALSE);
     configPageSetTrackVis(-2);
     }
 else
     {
     tracksDisplay();
     }
 
-jsonHashAddBoolean(jsonForClient, "measureTiming", measureTiming);
+jsonObjectAdd(jsonForClient, "measureTiming", newJsonBoolean(measureTiming));
 hPrintf("<script type='text/javascript'>\n");
 jsonPrint((struct jsonElement *) jsonForClient, "hgTracks", 0);
 hPrintf("</script>\n");
 
 }