|
I don't know if I understood you correctly, but how about something like this
class StatusWord<T, U> where T : struct where U : struct
{
U val;
public StatusWord(U val)
{
this.val = val;
}
public bool this[T t]
{
set { val = val | 0x001; }
}
public U Val
{
get { return val; }
}
}
|
|
|
|
|
The code you show seems more or less OK (other than the doubled < and >), but I don't understand what you want to accomplish.
carbon_golem wrote: where every bit in the word corresponds to a boolean named flag
Will the FlagsAttribute be of use?
|
|
|
|
|
I put the double <<>> to make the CP html generator show at least that it was generic. What I want to do is define named bits in a generic way. The named bits would be of standard lengths, 8, 16, 32, 64. I hoped to use an enum to provide a templating mechanism to do this, but so far no luck, and the solutions I have worked out aren't very type safe. What this is for is representing bit fields in embedded device logs. Here is my latest. A lot of it is shetchy, but...
public class StatusField<t>
where T : struct {
#region Members
private T template;
private ValueType sword;
#endregion
private StatusField(ValueType initialValue) {
template = new T();
if (template is Enum) {
Type t = template.GetType();
if (t.GetCustomAttributes(typeof(FlagsAttribute), false).Length == 0) {
throw new System.InvalidCastException("Requires Enum that defines FlagsAttribute");
}
sword = initialValue;
} else {
throw new System.InvalidCastException("Could not convert generic type");
}
}
public Object UnderlyingValue {
get {
return sword;
}
set {
sword = (ValueType)value;
}
}
public Boolean this[T index] {
get {
if (Enum.IsDefined(typeof(T), index)) {
Object x = Convert.ChangeType(index, typeof(Int64));
Int64 temp1 = (Int64)x;
Object y = Convert.ChangeType(sword, typeof(Int64));
Int64 temp2 = (Int64)y;
return (temp1 & temp2) == temp1;
} else {
throw new IndexOutOfRangeException("Field is not defined");
}
}
set {
if (Enum.IsDefined(typeof(T), index)) {
} else {
throw new IndexOutOfRangeException("Field is not defined");
}
}
}
public static StatusField<t> New(ValueType value) {
return new StatusField<t>(value);
}
}
</t></t></t>
And Usage:
StatusField<alarms> field = StatusField<alarms>.New(Alarms.Battery | Alarms.Motion);
Console.WriteLine(field.UnderlyingValue);
Console.WriteLine(field[Alarms.Battery]);
Console.ReadLine();
</alarms></alarms>
Thanks for the attention!
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
I suspect you need the FlagsAttribute, but I'm still unclear on what you are trying to do.
|
|
|
|
|
I would like to add some meta tags to a JPEG after it has been taken, unfortunately it is not possible to add the tags at the time the picture is taken. What I have found (best is here[^]) says it is not possible to add tags, so it is necessary to fool the JPEG by opening a current tag changing the values and than saving. While this work around does do the job it isn't very clean and seems like a problem waiting to happen. Does anyone know of a better way to add EXIF metadata after the picture has been taken?
Please let me know if it would be more appropriate to post this in the graphics form.
this thing looks like it was written by an epileptic ferret
Dave Kreskowiak
|
|
|
|
|
AFAIK there is no solution other than restuffing an existing JPEG file that already has
all the required tags.
|
|
|
|
|
Hi
Can someone help me. I need to convert a excel file into PDF format?
S
|
|
|
|
|
|
I need a code snippet to triple numbers.
Oluwayomi Ige
MCP MCAD
|
|
|
|
|
Seriously??
no. you have got tobe kidding? right? please...?
|
|
|
|
|
Did you notice he's Microsoft certified ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
nevermind he was checking us...xD
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Oluwayomi wrote: I need a code snippet to triple numbers.
Oluwayomi wrote: MCP MCAD
And people ask me why I don't value certifications.....
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
here you go:
.<br />
.<br />
.<br />
number anyNumber;<br />
console.writeline("Computer...triple the number above or i will shoot");<br />
.<br />
.<br />
.<br />
.
My idea of ideal life : Eat, Sleep, Repeat
|
|
|
|
|
OK then. Here's a choice for you:
public int Triple(int value)
{
}
public long Triple(long value)
{
} .. and so on. Obviously you'll want to implement exception handling and validation to take care of those cases where the return values are outside min/max values. To call them you would do:
int value = Triple(10);
|
|
|
|
|
When you say "triple", do you mean:
1) Multiply it by 3
2) Multiply it by itself 3 times
3) Display it three times like "101010"
4) Chop off your neighbor's head and put it on a pike in your front yard
5) Post a programming question in the Lounge
6) Herd elephants to their doom
7) Offer a starving muslim a pork sandwich
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
You can use the following classes
public class Single
{
private int _iValue;
public int Value
{
get { return _iValue; }
}
public Single() : this(0) {}
public Single(int iValue)
{
_iValue = iValue;
}
};
public class Double
{
private int _iValue;
public int Value
{
get
{
Single sinA = new Single(_iValue);
Single sinB = new Single(_iValue);
return sinA.Value + sinB.Value;
}
}
public Double() : this(0) {}
public Double(int iValue)
{
_iValue = iValue;
}
};
public class Tripple
{
private int _iValue;
public int Value
{
get
{
Double douA = new Double(_iValue);
Single sinB = new Single(_iValue);
return douA.Value + sinB.Value;
}
}
public Tripple() : this(0) { }
public Tripple(int iValue)
{
_iValue = iValue;
}
};
You can use it like this;
Tripple tripNumber = new Tripple(5);
int iData = tripNumber.Value;
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
Great answer, but you have too much time on your hands!
|
|
|
|
|
J4amieC wrote: Great answer, but you have too much time on your hands!
This is not correct. If I would have too much time on my hands I would have come
with something Generic like this:
MultiType<Double, Double> mul4 = new MultiType<Double, Double>(5);
int iData = mul4.Value;
MultiType<Double, MultiType<Double, Single>> mul5 = new MultiType<Double, MultiType<Double, Single>>(5);
iData = mul5.Value;
And the classes:
public class Single
{
protected int _iValue;
public int Value
{
get { return Data(); }
}
public void setValue(int IValue)
{
_iValue = IValue;
}
protected virtual int Data()
{
return _iValue;
}
public Single() : this(0) {}
public Single(int iValue)
{
_iValue = iValue;
}
};
public class Null : Single
{
public Null() : this(0) { }
public Null(int iValue)
{
_iValue = 0;
}
protected override int Data()
{
return 0;
}
};
public class Double : Single
{
protected override int Data()
{
Single sinA = new Single(_iValue);
Single sinB = new Single(_iValue);
return sinA.Value + sinB.Value;
}
public Double() : this(0) {}
public Double(int iValue)
{
_iValue = iValue;
}
};
public class MultiType<TL, TR> : Single
where TL : Single, new()
where TR : Single, new()
{
public MultiType() : this(0) { }
public MultiType(int iValue)
{
_iValue = iValue;
}
protected override int Data()
{
Single baseLeft = new TL();
baseLeft.setValue(_iValue);
Single baseRight = new TR();
baseRight.setValue(_iValue);
return baseLeft.Value + baseRight.Value;
}
};
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
|
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
What about http://www.careerchange.com/[^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I myself made an assembly (TripleMachine.dll) that I just import whenever I need to triple a number. It has support for multithreading, for when I need to tripple large chunks of data.
boolean dontNotCancel = ((!false && true) != (!true || false)) ? ((false == false || (true && (false == true ? true : false))) ? true : false) : (true != false && false);
|
|
|
|
|
hey, looks like my signature o.o
betonglasermur.FeedDwarf(pur_is, 17);
ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);
Morgonen är tröttmans mecka
|
|
|
|
|
hey, that does not look like it isn't my signature
boolean dontNotCancel = ((!false && true) != (!true || false)) ? ((false == false || (true && (false == true ? true : false))) ? true : false) : (true != false && false);
|
|
|
|