Calling a 'C' function inside yang file - ietf-netmod-yang

Can we call a 'C' function in yang file ? Or is there any way to accomplish this ? Basically I want to call a 'C' fun which will return a integer value and use that in my .yang file.
Below is my leaf structure :
leaf memory {
type int16;
default 100;
}
I don't want static default value which is 100 here.
I want the value in default field to be picked up from "C" function.
Is there any way to accomplish this ?
Thanks

YANG doesn't define implementation details, it just defines the schema of the data that a server and a client exchange.
A possible way to achieve YANG model to implementation references is to use YANG extensions.
These allow for the data model to include extra information that the YANG standard doesn't recognize, but that the YANG agent does.
That means:
define an extension on a YANG file
use that extension instead of the default keyword
in your implementation, have a mechanism that whenever a YANG defined value is initialized, if the extension is present, call a method with that name in order to retrieve a default value, instead of using the default value that the model describes directly.
So as you can see, first two steps are easy, third step is harder, as that requires adaptation of a YANG parser, either at compile time or runtime, so that the C function mentioned by the extension is invoked. This requires some kind of engine that is able to process the extension, and keep it in memory so that the data is correctly initialized.
Here's an example on how that would look like in YANG
module extensions {
namespace "http://example.com/extensions";
prefix ext;
extension default-function {
argument function-name;
description "Describes that this leaf has its default value defined by this function.";
}
}
import extensions { prefix ext; }
(...)
leaf memory {
type int16;
ext:default-function 100;
}

Related

override equals method in protobuf generated files in flutter

I am using protocol buffers in flutter. I have several objects, one of them is:
message LogTag{
string name = 1;
int32 color = 2;
int32 icon = 3;
}
I have generated necessary dart files using protoc compiler. But, what I want is that its equals method should check only name field to compare 2 LogTag objects in my project.
How can I do this?
Altering the protoc-generated sources will potentially break the generated code's ability to (un)marshal the types into protobuf messages and is strongly discouraged.
If you wish to create user-defined methods that leverage the underlying (generated) types, you should create user-defined classes and convert these to|from the protoc-generated types.
Not only does this permit you to add arbitrary methods but the classes are less tightly-coupled.

Why can't I declare a variable or function more than once with different types?

Okay I know "One Definition Rule", but when I try to declare a variable with different types subsequently in source code, I run into some mistake like following:
int fkc();
void fkc();
enter image description here
I mean these two statements are just two declarations, not definitions. Alright, Does every declaration have to have only one unique definition?
In C++, you can't overload functions based on return type.
Overload resolution takes into account the function name , cv-qualifiers , the number of parameters and their types.
You could do something like:
auto fck()
{
if constexpr(...) return my_int;
else /* do smth without return */
}
but that's not function overloading of course.
Because you cannot overload the method just by changing return type . It is not allowed. The compiler distinguishes function invocations based on signature.and the signature of function includes only function name and arugments like
func(int x....) which does not include return type

When I should define operations-type-traits for a USTRUCT

For some USTRUCT structs within UnrealEngine, type traits TStructOpsTypeTraits<T> are defined. These provide a list of bools (encapsulated in an enumeration) about the implemented capabilities of struct T.
What is the usage of those traits?
When I should define those traits for my custom USTRUCTs within my project?
*Example usage from within the Engine:
struct TStructOpsTypeTraitsBase2
{
enum
{
WithZeroConstructor = false, // struct can be constructed as a valid object by filling its memory footprint with zeroes.
WithNoInitConstructor = false, // struct has a constructor which takes an EForceInit parameter which will force the constructor to perform initialization, where the default constructor performs 'uninitialization'.
WithNoDestructor = false, // struct will not have its destructor called when it is destroyed.
WithCopy = !TIsPODType<CPPSTRUCT>::Value, // struct can be copied via its copy assignment operator.
// ...
}
}
Which is used like
template<>
struct TStructOpsTypeTraits<FGameplayEffectContextHandle> : public TStructOpsTypeTraitsBase2<FGameplayEffectContextHandle>
{
enum
{
WithCopy = true, // Necessary so that TSharedPtr<FGameplayEffectContext> Data is copied around
WithNetSerializer = true,
WithIdenticalViaEquality = true,
};
};
It seems that traits are used for USTRUCTs that are used in blueprints; and that they are required for structs which have a NetSerialize() function. I made spot checks:
WithIdenticalViaEquality -> UScriptStruct::HasIdentical() -> EStructFlags::STRUCT_IdenticalNative is used only in ::IdenticalHelper() which is intended for Blueprints
EStructFlags::STRUCT_NetSerializeNative is used for error messages (when the structs are used in blueprints) and in FObjectReplicator and FRepLayout, where this trait is required to be present for custom property replication
the description of TStructOpsTypeTraitsBase2 seems to tell, that these traits are only important, when the USTRUCTs are used within blueprints
type traits to cover the custom aspects of a script struct
UnrealEngine defines also a number of specialized traits for its container classes (e.g. TTypeTraitsBase). A comparison with c++ type_traits might be meaningful.
Many of the features available "out-of-the-box" in Unreal Engine 4 (e.g. replication, initialization, serialization, etc.) rely on information specific to each class. This allows different classes to - for example - customize how to serialize their own data.
For classes inheriting from the base UObject class, all the needed information are stored into properties or returned by overridable methods. For example, if you want to customize how your UObject-derived class manages serialization, you can simply override its virtual Serialize() method. This is enough for UE4 to be able to invoke your custom implementation when it need to serialize an instance of your class.
The problem with structs in UE4, is that they don't inherit from a common base class/interface. So UE4 doesn't have any pre-declare property or method to call. Trying to call an undeclared method will of course cause a compilation error in C++. Following the previous example on the custom serialization - UE4 can't in general invoke the Serialize() method on structs because some/most of them will not have such method and the compiler will report it as an error.
TStructOpsTypeTraitsBase2 is the solution to the above problem. You declare a specialization of it for your custom structs to inform UE4 of which methods are available. When done, using a mix of template meta-programming and auto-generated code, UE4 will be able to call such methods to provide again out-of-the-box services or allow you to customize default behaviors. For example, declaring WithSerializer = true you're informing UE4 that your struct has a custom Serialize() method and so UE4 will be able to automatically call it every time it needs to serialize an instance of your struct.
TStructOpsTypeTraitsBase2 is not limited to structs used with Blueprints, but is used also with USTRUCT() used in C++.
On when to use it, you need to declare a custom specialization of TStructOpsTypeTraitsBase2 when the default behavior of UE4 on your structure is not what you want (e.g. you want to serialize its data in a different way while the default implementation serializes all the not-transient UPROPERTY() using "standard" formats).
While the "form" is similar, the scope of TStructOpsTypeTraitsBase2 is different than C++ type_traits: type_traits is used by the compiler to inform the program/programmer about platform characteristics. TStructOpsTypeTraitsBase2 is used by the programmer to inform UE4 about available "extra" features of a custom struct.

How to specify a List<MyCustomType> as a "Return Type" for a UML Interface Property

In my Visio 2007 UML document I am unable to figure out how I can add an operation to an Interface that returns a generic List<MyCustomType> type.
For example:
Say I have a class named "MyClass" and an Interface named "IFace". IFace has a signature of a method that returns a Generic List of MyClass.
For clarity, here's an example of the C# code:
namespace StackO
{
public interface IFace
{
List<MyClass> SomeMethod(string data);
}
public class MyClass
{
}
}
Here's a screenshot of where I'm stuck:
It seems as though the only way to specify a List<MyClass> as my Return Type is to create another user-defined datatype that is explicitly written as List<MyClass>. If this is the case, so be it. However, I'm posting this in hopes that there is a better/proper way to do this.
How can I define the Return Type of an Operation of a Visio Interface to be a Generic List of a User-Defined Datatype?
In the Class diagram properties > Go to operations > select the return type you are interested in changing and click properties.
In the next dialog you will have option for setting prefix List< and suffix >.
This way you can specify the return type as List<>.
I see this option in Visio 2010. But I am not sure if this option is available in Visio 2007.
There is no such a thing as T1<T2> in UML class diagrams.
If you want to specify that the method returns several values, the correct notation is:
SomeMethod(data: String) : MyClass [*]
This notation is much more powerful than the one used by C#. List<MyClass> SomeMethod(string data) gives no information about the contract of the method. With UML, you know that in:
SomeMethod(data: String) : MyClass [*]
SomethingElse() : String [1..*]
LastExample(number: UnlimitedNatural) : Integer [0..1]
SomeMethod returns a sequence containing zero or more elements. SomethingElse returns a sequence of one or several elements: this sequence is never empty. Finally, LastExample returns an optional value. This could be expressed in C# as int? LastExample(uint number) — see, no IEnumerable here.
Also note that:
SomeMethod(data: String) : MyClass [0..*]
shouldn't be used, since [*] means the same thing and is shorter. As for:
SomeMethod(data: String) : MyClass [0..n]
is incorrect, despite being used a lot on the internet.

Limiting input to a vba class interface

I am trying to encapsulate the access of an XML configuration file within a (excel) vba custom class. A portion of the XML document is split into 4 or 5 repeated sections that are differentiated by an AreaID. MY question is: How can I limit the input of one of my class interfaces to the various AreaID's that may be read in from the XML document?
revision: what is the best way to control input into a class' interface from within the class (as it pertains to vba)? (i.e. public enum, secondary "helper" class, error handling from within the class, hard-coding...)
I wanted to follow up with #Tim's comment regarding enums and provide some further information as to why enums in the class code may be a good way to limit the input. According to Chip Pearson's site :
Enums cannot be declared within a procedure. They must be declared within the declarations part of a module, above and outside any procedure in the module. Class modules can declare Public Enum types but you cannot create a variable whose type is an Enum declared within a class module.
So as I understand this, if you declare the input on one of interfaces as a (public) enum that has been declared in the class itself, it will limit what values can go in based on that enum. Also the enum will still not be able to be used outside of the class structure.