How get and output description of VarDecl in clang? - output

I'm writing OCLint rule based on VisitBlockDecl using clang.
How can I output to console value of VarDecl *var variable?
static SmallVector<VarDecl *, 4> blockVars;
for (int i=0; i < blockVars.size(); i++) {
VarDecl *var = blockVars[i];
}

Related

Write a JSON file with cubePosition Data to spawn a 10x10x10 cube

Here I'm trying to write a code that can write and create a JSON File for me with the data I provide like row, column and depth.
For example, I need to spawn a 10 x 10 x 10 cube. And I give this data in unity Inspector also in the code when I'm serializing it.
I tried achieving this in a for loop and writing the JSON file. But I'm not getting the output I wanted. I am expecting output where the cube locations are different and in place what happens instead is all the data or cube position in my data is the one before the number I give. that is if I gave my row, column, and depth to be 10. So my data is like x: 9, y: 9, z:9 for the whole 1000 elements.Better explained in image down below.I know I'm doing a mistake at some point just not able to figure out where. Thanks for the help in Advance
public class JSONWriter : MonoBehaviour
{
[SerializeField] int rows , columns, depth = 10;
[SerializeField] float padding;
public enum CubeType
{
white,
yellow,
blue,
red,
green
}
private readonly IReadOnlyDictionary<CubeType, Color> colors = new Dictionary<CubeType, Color>
{
{CubeType.white, Color.white},
{CubeType.yellow, Color.yellow},
{CubeType.blue, Color.blue},
{CubeType.red, Color.red},
{CubeType.green, Color.green}
};
[System.Serializable]
public class CubeData
{
public Vector3 cubePosition;
public CubeType Cube;
}
[System.Serializable]
public class CubeDataList
{
public CubeData[] cubeDatas;
}
public void outputJSON()
{
string strOutput = JsonUtility.ToJson(myCubeDataList);
File.WriteAllText(Application.dataPath + "/Resources/10x10x10.txt", strOutput);
}
//CubeData myCubeData = new CubeData();
public CubeDataList myCubeDataList = new CubeDataList();
void Start()
{
for (int x = 0; x < myCubeDataList.cubeDatas.Length; x++)
{
//Debug.Log(myCubeDataList.cubeDatas.Length);
for (int i = 0; i < depth; i++)
{
for (int j = 0; j < columns; j++)
{
for (int k = 0; k < rows; k++)
{
myCubeDataList.cubeDatas[x].cubePosition = new Vector3(i, j, k) * padding;
//myCubeDataList.cubeDatas[x].Cube = Random.Range(CubeType, 3f);
}
}
}
}
}
}
You do not want to go through all i, j, k for each and every element x!
What you are doing is basically overwriting each and every element with the values for i=9, j=9, k=9.
Instead of an array I would rather simply use a dynamic List like
[Serializable]
public class CubeDataList
{
public List<CubeData> cubeDatas;
}
and then dynamically add them via
myCubeDataList.cubeDatas = new List<CubeData>(i * j * k);
for (int i = 0; i < depth; i++)
{
for (int j = 0; j < columns; j++)
{
for (int k = 0; k < rows; k++)
{
var data = new CubeData();
data.cubePosition = new Vector3(i, j, k) * padding;
data.Cube = Random.Range(CubeType, 3f);
myCubeDataList.cubeDatas.Add(data);
}
}
}
Or if you really want to go with an array
for (int i = 0; i < depth; i++)
{
for (int j = 0; j < columns; j++)
{
for (int k = 0; k < rows; k++)
{
var data = new CubeData();
myCubeDataList.cubeDatas[x].cubePosition = new Vector3(i, j, k) * padding;
myCubeDataList.cubeDatas[x].Cube = Random.Range(CubeType, 3f);
x++;
}
}
}
Though, from your previous question I know you actually do not want to fill the cube completely!
You actually only want the external shape (like a wall) and leave the cube empty on the inside.
So what you actually want would probably rather be
myCubeDataList.cubeDatas = new List<CubeData>(i * j * k);
for (int i = 0; i < depth; i++)
{
for (int j = 0; j < columns; j++)
{
for (int k = 0; k < rows; k++)
{
if(i == 0 || i == depth - 1
|| j == 0 || j == depth - 1
|| k == 0 || k == depth - 1)
{
var data = new CubeData();
data.cubePosition = new Vector3(i, j, k) * padding;
// TODO random enum (see below)
myCubeDataList.cubeDatas.Add(data);
}
}
}
}
For the random enum vlaue see e.g. this answer and do
private Random random = new Random();
and then where it says // TODO insert
var values = Enum.GetValues(typeof(Bar));
data.Cube = (CubeType)values.GetValue(random.Next(values.Length));

double ** int function parameter

Can somebody explain me why does the parameter has double "**"? Like, I know it's the equivalent of the "by reference" in C++, but I need more explanations, please.
int crearevect(int **v)
{
int nr,i;
scanf("%d",&nr);
*v=(int *)(malloc(nr*sizeof(int)));
for (i=0; i<nr; i++)
printf("%p ",((*v)+i));
printf("%p",v);
return nr;
}
// v[i] = *(v+i)
// *(v)[i] = *(*(v)+i)
void creareMATRICE(int ***a, int *n, int *m)
{
scanf("%d",n);
scanf("%d",m);
*a=(int **)(malloc(*n*sizeof(int)));
int i,j;
for (i=0; i<*n; i++)
(*a)[i]=(int *)(malloc(*m*sizeof(int)));
for (i=0; i<*n; i++)
for (j=0; j<*m; j++)
scanf("%d",&(*a)[i][j]);
return;
}
in C refers to pointer. A * refers to a variable that holds memory address, similarly ** refers to a variable that hold memory address of a memory address, likewise *** and so on. You can read more about pointers from https://www.tutorialspoint.com/cprogramming/c_pointers.htm or any other online reference. But in general you can link a * with variable that can be used to address 1D array (v[i] = *(v+i)), ** with variable that can be used to address 2D array (v[i][j] = ((v+i) + j)) and so on.

Why is this AS3 code generating an "Error #2006: The supplied index is out of bounds"?

So what I'm trying to do is go through each element of the array "maps" which contains 4 movieclips and look and the children within each of those movieclips to see which are of type "Block". However I'm getting a #2006 error and I'm not sure why, can anyone help please?
function findBlocks()
{
trace("findBlocks()");
for (i=0; maps.length; i++)
{
for (var j=0; maps[i].numChildren; j++)
{
var mc = maps[i].getChildAt(j);
if (mc is Block)
{
blocks.push(mc);
}
}
}
trace("blocks array: " + blocks);
}
Your for loop conditions are incorrect, try this :
for (var i=0; i < maps.length; i++){
for (var j=0; j < maps[i].numChildren; j++){
var mc = maps[i].getChildAt(j);
if (mc is Block){
blocks.push(mc);
}
}
}
You have to remember that arrays and the display list start at 0, so the index of the last element in your lists is length-1, and in the case of a display list numChildren-1
i < maps.length
and
j < maps[i].numChildren
are what solve the problem

Parse specific format json array in Qt4, no external libraries

I need extract data from a JSON array, format '[[[1,2,3]],[[1,2,3],[1,2,3]],"string"]' in Qt. logically it's '[[[x-values]],[[y1-values],[y2-values]],"comments"]'.
Edit: x,y1,y2 arrays can be up to 1000+ elements large.
I know that that's the exact format (without the single quotes) and that it's not going to change.
What I really want is QVector xval, y1val; .
How would I parse that?
(I'm new to Qt so please forgive me if I'm missing the obvious.)
Quick and dirty solution:
QString s = "[[[1,2,3]],[[4,5,6],[7,8,9]],\"string\"]";
QStringList parts = s.remove("[").remove("]").split(',');
QVector<int> xval, yval;
if (parts.size() >= 6)
{
xval << parts[0].toInt() << parts[1].toInt() << parts[2].toInt();
yval << parts[3].toInt() << parts[4].toInt() << parts[5].toInt();
}
Edit: Now supporting variable length arrays:
QVector<int> ToIntList(const QString& s)
{
QVector<int> result;
QStringList parts = s.trimmed().split(",");
for (int i = 0; i < parts.size(); ++i)
result << parts[i].toInt();
return result;
}
QString s = "[[[1,2,3,4,5,6, 7, 8]],[[9\n,10], [11,12,13]],\"string\"]";
QStringList lists = s.remove(" ").split("],[");
for (int i = 0; i < lists.size(); ++i)
lists[i] = lists[i].remove("[").remove("]");
QVector<int> xval, yval;
if (lists.size() >= 2)
{
xval = ToIntList(lists[0]);
yval = ToIntList(lists[1]);
}

Convert Java Array Object to JSON using Jackson

I need to conver java array object to JSON, i am using jackson for this. I can only think that for every field name i have to iterate from the array which means i have to iterate the same array object for each field. Is there any efficient way of doing it?
JsonGenerator jGenerator = jfactory.createJsonGenerator(out);
jGenerator.writeStartObject();
jGenerator.writeFieldName("images");
jGenerator.writeStartArray();
for(int i=0; i < topicBean.getTopicVOArray().length; i++){
jGenerator.writeString(topicBean.getTopicVOArray()[i].getBody());
}
for(int i=0; i < topicBean.getTopicVOArray().length; i++){
jGenerator.writeString(topicBean.getTopicVOArray()[i].getTopicGuid()());
}
Depends on what you want the resulting json to look. Right now you're going to get {"images":["bodystring","bodystring","guidstring","guidstring"]} but you could also make it {"images":["bodystring","guidstring","bodystring","guidstring"]} or, even better, {"images":[{"body":"bodystring","guid":"guidstring"},{"body":"bodystring","guid":"guidstring"}]}
First solution:
for(int i=0; i < topicBean.getTopicVOArray().length; i++){
jGenerator.writeString(topicBean.getTopicVOArray()[i].getBody());
jGenerator.writeString(topicBean.getTopicVOArray()[i].getTopicGuid()());
}
Second solution (object wrapper):
for(int i=0; i < topicBean.getTopicVOArray().length; i++){
jGenerator.writeStartObject();
jGenerator.writeFieldName("body");
jGenerator.writeString(topicBean.getTopicVOArray()[i].getBody());
jGenerator.writeFieldName("guid");
jGenerator.writeString(topicBean.getTopicVOArray()[i].getTopicGuid()());
jGenerator.writeEndObject();
}