I want to make a tree class like NSArray with CFTree.
(Actually NSTree doesn't exist so I'm trying to make 'NSTree like tree'.)
But CFTree seems to request certain type class.
I want to make a general class that can deal in various class like NSArray.
Here is iPhone dev site's example.
static CFTreeRef CreateMyTree(CFAllocatorRef allocator) {
MyTreeInfo *info;
CFTreeContext ctx;
info = CFAllocatorAllocate(allocator, sizeof(MyTreeInfo), 0);
info->address = 0;
info->symbol = NULL;
info->countCurrent = 0;
info->countTotal = 0;
ctx.version = 0;
ctx.info = info;
ctx.retain = AllocTreeInfo;
ctx.release = FreeTreeInfo;
ctx.copyDescription = NULL;
return CFTreeCreate(allocator, &ctx);
}
I want to use general class instead of "MyTreeInfo".
Is there any way?
Thanks.
Sure, CFTree can hold any data you want. If you want to store instances of CFType, then just set the retain and release of the context to CFRetain and CFRelease. You can also then set copyDescription to CFCopyDescription. Something like this:
static CFTreeRef CreateMyTree(CFTypeRef rootObject) {
CFTreeContext ctx;
ctx.version = 0;
ctx.info = rootObject;
ctx.retain = CFRetain;
ctx.release = CFRelease;
ctx.copyDescription = CFCopyDescription;
return CFTreeCreate(NULL, &ctx);
}
...
CFStringRef string = CFSTR("foo");
CFTreeRef tree = CreateMyTree(string);
NSLog(#"%#", tree);
CFRelease(tree);
Related
I'm trying to use UA-.NETStandardLibrary by OPC Foundation to create my own OPC UA Server that will maintain some variables.
I've created a server class inherited from StandardServer and node manager inherited from CustomNodeManager2.
There were some node managers in their examples, I removed them and add my own one. The server starts normally and doesn't contain any nodes except from standard ones, as planned. So, my problem is how to create my own variable node from code (not from xml, as in examples) and be able update its value on demand.
For example, I want to add a folder with couple of nodes inside.
Does anyone have a code snippet which demonstrates how to do it? I don't want anybody write it for me, I will appreciate only if you just tell me about a right way to make it.
Thanks a lot.
I am pretty sure the snippets you are looking for are included. Here is my testing code and I am 100% positive, I didn't write the second piece of code. Anyway, if this helps you...
{
var ticker_seq = createVariable(myFolder, "MyFolder/Ticker", "Ticker", BuiltInType.UInt64, ValueRanks.Scalar);
variables.Add(ticker_seq);
subscriptions.Add(clock.Ticker.Subscribe(val =>
{
lock (Lock)
{
ticker_seq.Value = val;
ticker_seq.Timestamp = DateTime.UtcNow;
ticker_seq.ClearChangeMasks(SystemContext, false);
}
}));
}
and creation
private BaseDataVariableState createVariable(NodeState parent, string path, string name, NodeId dataType, int valueRank)
{
BaseDataVariableState variable = new BaseDataVariableState(parent);
variable.SymbolicName = name;
variable.ReferenceTypeId = ReferenceTypes.Organizes;
variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType;
variable.NodeId = new NodeId(path, NamespaceIndex);
variable.BrowseName = new QualifiedName(path, NamespaceIndex);
variable.DisplayName = new LocalizedText("en", name);
variable.WriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
variable.UserWriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
variable.DataType = dataType;
variable.ValueRank = valueRank;
variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
variable.Historizing = false;
variable.Value = 0;
variable.StatusCode = StatusCodes.Good;
variable.Timestamp = DateTime.UtcNow;
if (parent != null)
{
parent.AddChild(variable);
}
return variable;
}
creating the folder:
private FolderState CreateFolder(NodeState parent, string path, string name)
{
FolderState folder = new FolderState(parent);
folder.SymbolicName = name;
folder.ReferenceTypeId = ReferenceTypes.Organizes;
folder.TypeDefinitionId = ObjectTypeIds.FolderType;
folder.NodeId = new NodeId(path, NamespaceIndex);
folder.BrowseName = new QualifiedName(path, NamespaceIndex);
folder.DisplayName = new LocalizedText("en", name);
folder.WriteMask = AttributeWriteMask.None;
folder.UserWriteMask = AttributeWriteMask.None;
folder.EventNotifier = EventNotifiers.None;
if (parent != null)
{
parent.AddChild(folder);
}
return folder;
}
I want to add variable to mobile node class in Ns2; which this variable get initial value in TCL.
For each mobile node we assign a special value to this variable. How can i add this variable to mobile node class?
Go to your ns2 directory, and open mobilenode.h first. For
example if you have ns-2.35, go to
ns-allinone-2.35/ns-2.35/common/ and open it from here.
Find the line that says :
class MobileNode : public Node
and go to the last line of the public: that may look like MobileNode* prevX_; and add your variable here.
Example :
/* For list-keeper */
MobileNode* nextX_;
MobileNode* prevX_;
// My variables
int32_t NodeQueue;
protected:
Now to give them an initial value, you can open the file mobilenode.cc and fine the constructor of class mobilenode that may look like MobileNode::MobileNode(void) : and simply give your variable an initial value...
Example :
/* ======================================================================
Mobile Node
====================================================================== */
MobileNode::MobileNode(void) :
pos_handle_(this)
{
X_ = Y_ = Z_ = speed_ = 0.0;
dX_ = dY_ = dZ_ = 0.0;
destX_ = destY_ = 0.0;
random_motion_ = 0;
base_stn_ = -1;
T_ = 0;
log_target_ = 0;
next_ = 0;
radius_ = 0;
position_update_interval_ = MN_POSITION_UPDATE_INTERVAL;
position_update_time_ = 0.0;
LIST_INSERT_HEAD(&nodehead, this, link_); // node list
LIST_INIT(&ifhead_); // interface list
bind("X_", &X_);
bind("Y_", &Y_);
bind("Z_", &Z_);
bind("speed_", &speed_);
NodeQueue = 0; // Initial value
}
And then you need to cd in your ns2 directory from terminal and type make and click 'Enter'.
I am dynamically creating images in my QML. This is the code I am using:
for (var n = 0; n < 3 * numberOfTiles; n ++) {
var image = imageDefinition.createObject();
image.translationX = getX(n);
image.translationY = getY(n);
image.objectName = ("image"+n)
drawContainer.add(image);
}
Image creating works well, except I don't know how to call those images afterdawrds. I can't set them an ID, and I don't know if setting objectName like that works.
I don't get any errors, and if this work, how can I call "image3" from QML to move it? I don't want to use c++.
Found out a solution on my own. First I add this to have global access
property list<ImageView> images
And then I create images in array and copy them over
onCreationCompleted: {
//you need a tmp variable, since you can't do that with property variant
var imagesTmp = Array();
for (var n = 0; n < 3 * numberOfTiles; n ++) {
imagesTmp[n] = imageDefinition.createObject()
imagesTmp[n].translationX = getX(n);
imagesTmp[n].translationY = getY(n);
drawContainer.add(imagesTmp[n]);
}
images = imagesTmp;
images[3].translationX = 10; //as example, this works!
}
As it turns out images keeps reference to the image
I want to create a basic CFTree with some string info in Objective-C.
This is my code
//CFtree attempt
NSString *info;
CFTreeContext ctx;
NSString *treeString = [[NSString alloc] initWithFormat:#"the tree string"];
info = treeString;
ctx.info = info;
CFTreeRef myTree = CFTreeCreate(NULL, &ctx);
I get an "EXC_BAD_ACESS" error on the last line.
Can someone please tell me how to configure this properly.
It seems that ctx should be initialized.
ctx.version = 0;
ctx.info = info;
ctx.retain = CFRetain;
ctx.release = CFRelease;
ctx.copyDescription = CFCopyDescription;
You may want to initialize the ctx struct to 0 before using it since there are members in it that otherwise may cause erratic behavior as the CFTreeCreate thinks they are pointing to something relevant.
see
Is it possible to do the same using Lambda
for (int i = 0; i < objEntityCode.Count; i++)
{
options.Attributes[i] = new EntityCodeKey();
options.Attributes[i].EntityCode = objEntityCode[i].EntityCodes;
options.Attributes[i].OrganizationCode = Constants.ORGANIZATION_CODE;
}
I mean to say to rewrite the statement using lambda. I tried with
Enumerable.Range(0,objEntityCode.Count-1).Foreach(i=> {
options.Attributes[i] = new EntityCodeKey();
options.Attributes[i].EntityCode = objEntityCode[i].EntityCodes;
options.Attributes[i].OrganizationCode = Constants.ORGANIZATION_CODE; }
);
but not working
I am using C#3.0
Well you can make it simpler with object initializers, to start with:
for (int i = 0; i < objEntityCode.Count; i++)
{
options.Attributes[i] = new EntityCodeKey
{
EntityCode = objEntityCode[i].EntityCodes,
OrganizationCode = Constants.ORGANIZATION_CODE
};
}
I would probably leave it at that though... there's currently no ForEach extension method on IEnumerable<T> - and for good reasons, although I know it's not a universally held opinion ;)
In this case, you'd still need to know i in order to set options.Attributes[i] - unless you could set the whole of options.Attributes in one go, of course... without knowing about the types involved, it's pretty hard to advise further.
If options.Attributes is a writable property (e.g. an array), you could use:
options.Attributes = objEntityCode.Select(code => new EntityCodeKey
{
EntityCode = code.EntityCodes,
OrganizationCode = Constants.ORGANIZATION_CODE
}).ToArray();
If options.Attributes is actually just a property which returns a type with an indexer, that won't work.
Enumerable.Range(0, objEntityCode.Count - 1).ToList().ForEach(i =>
{
options.Attributes[i] = new EntityCodeKey();
options.Attributes[i].EntityCode = objEntityCode[i].EntityCodes;
}
);
Enumerable.Range(0, objEntityCode.Count - 1).ToList().ForEach(i =>
{
options.Attributes[i] = new EntityCodeKey
{
EntityCode = objEntityCode[i].EntityCodes
, OrganizationCode = Constants.ORGANIZATION_CODE
};
}
);