What's the best value representation for boolean in DICOM? - dicom

AFAIK there's no boolean value representation, and I need to specify a boolean true/false in a private tag.
I thought of a SH (SHort string), saying TRUE or FALSE. Is there a standard or widely used way to specify it?

You can use a Coded String (CS) VR with TRUE and FALSE as coded values.
This is done in the standard for the Time of Flight Information Used element (0018, 9755) in the enhanced PET acquisition module.

Related

Why does FreeMarkers built-in "?is_string" return true for an Object?

If I pass an Object into the model and test it with the "?is_string" built-in, it will falsely return a true value.
Is it possible (without checking the class name) to have a proper type checks on Objects?
FreeMarker: 2.3.28
Code to reproduce:
public class Test {}
// In Test Controller
ModelAndView mv = new ModelAndView("test");
mv.addObject("test", new Test());
// In test.ftl
<#if test?is_string>
${test} - is a string!
</#if>
// Result
Test#455b31c - is a string
The problem is that that approach isn't really supported by FreeMarker. The Java objects are mapped to some template language values via Configuration.objectWrapper, and the template only sees the result of that mapping. Furthermore the template language has a different type system than Java, a simplistic one, without classes. (It was a design goal back then that the data-model is just some simple tree, and the templates will work no mater what objects are behind, as far as it still gives the same tree.) ?is_... doesn't check the Java type, but the type according the template language. As with the usual ObjectWrapper-s a "generic" object (means, nothing recognized like List, Map, Date, etc.) can be used as a strings whose value is whatever toString() returns, it's a string as far as the template language is concerned. It's kind of duck typed...
A workaround I can think of is that first check the value with ?is_hash, as that will catch the said generic objects (as they support ., they are hashes as well, not just strings). Or instead just check the property you expect to be present in a Test. Then on the "else" branch you can continue with ?is_string.

Swift 3 - how to determine that key and value type in run time?

How can we find out at runtime that key and value type of a NSDictionary variable at runtime?
e.g.
var dict:NSDictionary = [:]
// How to find out what the type is for the key and value?
It is extremely rare that you should be using NSDictionary in Swift. There is no "key and value type" for an NSDictionary. Each individual element can potentially have a different type (ObjC dictionaries are only consistent by convention, not by requirement). Generally if you need this, you're on the wrong path. You almost always want to use Swift's Dictionary rather than NSDictionary.
That said, the answer in this case is that the key is AnyHashable and the value is AnyObject. That's all the type information you have. Beyond that, you'd just have to interrogate the objects.

Property with validation and convertion

This might be a basic question, but I would like to know best practice.
I have a public property which takes in a value as an Integer. If that
value by accident would be a String, could I in my property do validation
and convertion on the fly, so the output becomes an Integer, without
my script failing? Or is it best to make shure to operate with the
right datatype before passing it in the property?
This is my property:
Public Property Quantity() As Integer
Get
Return m_Quantity
End Get
Set(value As Integer)
m_Quantity = value
End Set
End Property
Best regards!
If that value by accident would be a String,
Such accident cannot happen in a strongly typed language because the compiler will tell you that you cannot assign a string value to an integer property. Actually you could shorten your code a little by using an Auto-Implemented Property:
Property Quantity As Integer
The property cannot be a string. Either the code will not compile, or if you don't have Option Strict/Infer on (and you really should!) the runtime conversion to Integer will fail, causing an exception.

Change Default Integer Value Of C++ Dictionary TryGetValue() Method?

Quick question which I fear has a short and disappointing answer but alas I shall ask anyway..
In the C++ Dictionary method TryGetValue() is there any way to change the default value that will be returned for an integer (to -1 instead for example) when the key is not present? The problem is that 0 is the default and this is not suitable because a value of 0 would make sense in the context of my program.
If not, is the ContainsKey() method that much slower? Or is it splitting hairs and nothing to worry about seeing as in all likelihood I have no choice..
Many thanks
PS I don't need to perform any hashing function (though this might be in the implementation for Dictionary anyway!), nor have any particular ordering to my collection, I just want lookup and adding to be as fast as possible. Is Dictionary a sound choice?
Why don't you create a class that inherits from Dictionary(Of TKey, TValue) and override the TryGetValue function. You could then use your own class and it would behave just as you would want it to...

A little vb.net interface explaination

Can anyone explain the (of Out T) component to this interface? I'm familar enough with how interfaces work. I also understand that T refers to a type... Whats going on with the Out portion.
Public Interface IPageOfItems(Of Out T)
Inherits IEnumerable(Of T)
Property PageNumber() As Integer
Property PageSize() As Integer
Property TotalItemCount() As Integer
ReadOnly Property TotalPageCount() As Integer
ReadOnly Property StartPosition() As Integer
ReadOnly Property EndPosition() As Integer
End Interface
.NET 4.0 introduced covariance and contravariance of generic types. Here's what this means.
Covariance
The Out keyword here indicates that the type is covariant. A covariant type T(Of D) can be cast to a type T(Of B) where D derives from B. This is possible when the type T(Of D) only ever uses D values as output (hence the word Out).
For example, the IEnumerable(Of Out T) interface is covariant because none of its methods accepts any parameters of type T. Therefore, an IEnumerable(Of String) can be cast as an IEnumerable(Of Object) -- if it provides enumerable access to strings, then it provides enumerable access to objects (since strings are objects).
Contravariance
Conversely, the In keyword may be applied to a type that is eligible for contravariance. A contravariant type T(Of B) can be cast to a type T(Of D) where D derives from B. This is possible when the type T(Of B) only uses B values as input (hence the word In). In other words, contravariance is the exact opposite of covariance.
A good example of a contravariant type would be the IComparer(Of In T) interface. This interface provides no methods that return T values; therefore an IComparer(Of Object) could be cast as an IComparer(Of String) -- after all, if it can compare objects, it can compare strings.
This is new .NET 4 feature that allows you to specify variance with generic arguments. Pretty much everything you need to know:
http://msdn.microsoft.com/en-us/library/dd799517.aspx
This is to indicate the interface is covariant in generic parameter T. Check Generic Variance heading in this article that explains new features in VB.NET 2010 (.NET Fx 4.0).
In short covariance will allow to substitute smaller type (such as subclass) instead of larger type. For example, if Tiger is inherited from Animal then we can use IEnumerable(Of Tiger) in place of IEnumerable (Of Animal). Eric Lippert has explained variance (in context C#) very well in series of blog posts.

Resources