Search Results

Search found 49 results on 2 pages for 'object2 0'.

Page 1/2 | 1 2  | Next Page >

  • creative & complex vs simple and readable

    - by Shirish11
    Which is a better option? Its not always that when you have something creative your code is going to look ugly. But at times it does go a bit ugly. e.g. if ( (object1(0)==object2(0) && (object1(1)==object2(1) && (object1(2)==object2(2) && (object1(3)==object2(3)){ retval = true; else retval = false; is simple and readable bool retValue = (object1(0)==object2(0)) && (object1(1)==object2(1)) && (object1(2)==object2(2)) && (object1(3)==object2(3)); but having something like this will make some newbies scratch their heads. So what do I go for? including simple code everywhere might sometime hamper my performance. what I could think of was commenting wherever necessary but at times u get too curious to know what is actually happening. Any suggestions are welcome.

    Read the article

  • Changing the material on an object on click in unity

    - by user1509674
    Iam working on unity2d.I have six game object Object1,Object1,Object1,(these are images) ObjectImage1,ObjectImage2,ObjectImage3(these are images). I have arranged the object in the scene as a list one below another Object1 Object2 Object3 When I click the Object1 --- should change to ObjectImage1 Object2 ----should change to ObjectImage2, but the above image of object1(objectImage1) at present should change to Object1 Object3 ----? should change to ObjectImage3,but the above image on object2(objectImage2) should change to Object2 These is similar to selection.I have coded Like when I click of Object2 its changing to ObjectIamge2 but the first object is not changing to object1 from objectImage1.Can anybody help me coding it out. Edit: public GameObject newSprite; private Vector3 currentSpritePosition; void Start() { newSprite.renderer.enabled = false; currentSpritePosition = transform.position; //then make it invisible renderer.enabled = false; //give the new sprite the position of the latter newSprite.transform.position = currentSpritePosition; //then make it visible newSprite.renderer.enabled = true; } void OnMouseExit(){ //just the reverse process renderer.enabled = true; newSprite.renderer.enabled = false; } This is the code used to change the material: public GameObject newSprite; private Vector3 currentSpritePosition; void Start(){ newSprite.renderer.enabled = false; } void OnMouseEnter(){ //getting the current position of the current sprite if ever it can move; currentSpritePosition = transform.position; //then make it invisible renderer.enabled = false; //give the new sprite the position of the latter newSprite.transform.position = currentSpritePosition; //then make it visible newSprite.renderer.enabled = true; } void OnMouseExit(){ //just the reverse process renderer.enabled = true; newSprite.renderer.enabled = false; }

    Read the article

  • Is it any loose coupling mechanism in Objective-C + Cocoa like C# delegates or C++Qt signals+slots?

    - by Eye of Hell
    Hello. For a large programs, the standard way to chalenge a complexity is to divide a program code into small objects. Most of the actual programming languages offer this functionality via classes, so is Objective-C. But after source code is separated into small object, the second challenge is to somehow connect them with each over. Standard approaches, supported by most languages are compositon (one object is a member field of another), inheritance, templates (generics) and callbacks. More cryptic techniques include method-level delagates (C#) and signals+slots (C++Qt). I like the delegates / signals idea, since while connecting two objects i can connect individual methods with each over, without objects knowing anything of each over. For C#, it will look like this: var object1 = new CObject1(); var object2 = new CObject2(); object1.SomethingHappened += object2.HandleSomething; In this code, is object1 calls it's SomethingHappened delegate (like a normal method call) the HandleSomething method of object2 will be called. For C++Qt, it will look like this: var object1 = new CObject1(); var object2 = new CObject2(); connect( object1, SIGNAL(SomethingHappened()), object2, SLOT(HandleSomething()) ); The result will be exactly the same. This technique has some advantages and disadvantages, but generally i like it more than interfaces since if program code base grows i can change connections and add new ones without creating tons of interfaces. After examination of Objective-C i havn't found any way to use this technique i like :(. It seems that Objective-C supports message passing perfectly well, but it requres for object1 to have a pointer to object2 in order to pass it a message. If some object needs to be connected to lots of other objects, in Objective-C i will be forced to give him pointers to each of the objects it must be connected. So, the question :). Is it any approach in Objective-C programming that will closely resemble delegate / signal+slot types of connection, not a 'give first object an entire pointer to second object so it can pass a message to it'. Method-level connections are a bit more preferable to me than object-level connection ^_^.

    Read the article

  • Board Game Design in Cocos2d

    - by object2.0
    Hi folks i am going to start a chess like board game. and for that i have reviewed a number to things available. one is http://www.mapeditor.org/ , using which you can create a grid base games. another option is geekgameboard for iphone available at http://mooseyard.lighthouseapp.com/projects/23201-geekgameboard now i want your expert opinion that would it be better to make a game in cocos2d using the first option or the second option? both looks promising to me and give good control over board design. ps: sorry for duplicates, i found about the http://gamedev.stackexchange.com/ lately after posting it on stackexchange. so i am just posting it here again as i feel its more relevant board.

    Read the article

  • JavaScript: How to create a new instance of a class without using the new keyword?

    - by Alessandro Vernet
    I think the following code will make the question clear. // My class var Class = function() { console.log("Constructor"); }; Class.prototype = { method: function() { console.log("Method");} } // Creating an instance with new var object1 = new Class(); object1.method(); console.log("New returned", object1); // How to write a factory which can't use the new keyword? function factory(clazz) { // Assume this function can't see "Class", but only sees its parameter "clazz". return clazz.call(); // Calls the constructor, but no new object is created return clazz.new(); // Doesn't work because there is new() method }; var object2 = factory(Class); object2.method(); console.log("Factory returned", object2);

    Read the article

  • Scripts won't affect clones - Unity3d

    - by user3666251
    I made a script which swaps two game objects on click.But the script won't work because the objects are actualy clones of the original prefab. This is the script (UnityScript): #pragma strict var object1 : GameObject; var object2 : GameObject; function OnMouseDown () { Instantiate(object2,object1.transform.position,object1.transform.rotation); Destroy(object1); } I use this script to create other game objects (clones)[c#] : using UnityEngine; using System.Collections; public class Spawner : MonoBehaviour { public GameObject[] obj; public float spawnMin = 1f; public float spawnMax = 2f; // Use this for initialization void Start () { Spawn (); } void Spawn() { Instantiate(obj[Random.Range(0, obj.GetLength(0))],transform.position, Quaternion.identity); Invoke ("Spawn", Random.Range (spawnMin, spawnMax)); } } The objects get renamed to NAME (Clone). What I wanna do is make the script affect clones too.So they will swap when I click on them.

    Read the article

  • WIA Automation for scanner color intent is not working

    - by Mike Nicholson
    I cannot get my Canon Pixma MP150 to scan a color scan from c# code. The following code is resulting in a black and white image, or if I change the value of 6146 to 2 then a grayscale image is created. I would like to be able to have a color scan from code. I know the scanner does color images because I can do one through the xp wizard in "scanners and camera". Can anyone help me figure out what value I am not setting for a color scan. All documentation and examples I can find just say to change the value of 6146. Thank you for taking the time to read this! private void ScanAndSaveOnePage () { WIA.CommonDialog Dialog1 = new WIA.CommonDialogClass(); WIA.DeviceManager DeviceManager1 = new WIA.DeviceManagerClass(); System.Object Object1 = null; System.Object Object2 = null; WIA.Device Scanner = null; Scanner = Dialog1.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, false, false); WIA.Item Item1 = Scanner.Items[1]; setItem(Item1, "6146", 1); setItem(Item1, "6147", 150); setItem(Item1, "6148", 150); setItem(Item1, "6151", 150 * 8.5); setItem(Item1, "6152", 150 * 11); WIA.ImageFile Image1 = new WIA.ImageFile(); WIA.ImageProcess ImageProcess1 = new WIA.ImageProcess(); Object1 = (Object)"Convert"; ImageProcess1.Filters.Add(ImageProcess1.FilterInfos.get_Item(ref Object1).FilterID, 0); Object1 = (Object)"FormatID"; Object2 = (Object)WIA.FormatID.wiaFormatBMP; ImageProcess1.Filters[1].Properties.get_Item(ref Object1).set_Value(ref Object2); Object1 = null; Object2 = null; Image1 = (WIA.ImageFile)Item1.Transfer(WIA.FormatID.wiaFormatBMP); string DestImagePath = @"C:\test.bmp"; File.Delete(DestImagePath); Image1.SaveFile(DestImagePath); } private void setItem (IItem item, object property, object value) { WIA.Property aProperty = item.Properties.get_Item(ref property); aProperty.set_Value(ref value); }

    Read the article

  • The "is" in JUnit 4 assertions

    - by Space_C0wb0y
    Is there any semantic difference between writing assertThat(object1, is(equalTo(object2))); and writing assertThat(object1, equalTo(object2))); ? If not, I would prefer the first version, because it reads better. Are there any other considerations here?

    Read the article

  • Date Sorting - Latest to Oldest

    - by Erika Szabo
    Collections.sort(someList, new Comparator<SomeObject>() { public int compare(final SomeObject object1, final SomeObject object2) { return (object1.getSomeDate()).compareTo(object2.getSomeDate()); }} ); Would it give me the objects with latest dates meaning the list will contain the set of objects with latest date to oldest date?

    Read the article

  • Good patterns for loose coupling in Java?

    - by Eye of Hell
    Hello. I'm new to java, and while reading documentation so far i can't find any good ways for programming with loose coupling between objects. For majority of languages i know (C++, C#, python, javascript) i can manage objects as having 'signals' (notification about something happens/something needed) and 'slots' (method that can be connected to signal and process notification/do some work). In all mentioned languages i can write something like this: Object1 = new Object1Class(); Object2 = new Object2Class(); Connect( Object1.ItemAdded, Object2.OnItemAdded ); Now if object1 calls/emits ItemAdded, the OnItemAdded method of Object2 will be called. Such loose coupling technique is often referred as 'delegates', 'signal-slot' or 'inversion of control'. Compared to interface pattern, technique mentioned don't need to group signals into some interfaces. Any object's methods can be connected to any delegate as long as signatures match ( C++Qt even extends this by allowing only partial signature match ). So i don't need to write additional interface code for each methods / groups of methods, provide default implementation for interface methods not used etc. And i can't see anything like this in Java :(. Maybe i'm looking a wrong way?

    Read the article

  • Given 4 objects, how to figure out whether exactly 2 have a certain property

    - by Cocorico
    Hi guys! I have another question on how to make most elegant solution to this problem, since I cannot afford to go to computer school right so my actual "pure programming" CS knowledge is not perfect or great. This is basically an algorhythm problem (someone please correct me if I am using that wrong, since I don't want to keep saying them and embarass myself) I have 4 objects. Each of them has an species property that can either be a dog, cat, pig or monkey. So a sample situation could be: object1.species=pig object2.species=cat object3.species=pig object4.species=dog Now, if I want to figure out if all 4 are the same species, I know I could just say: if ( (object1.species==object2.species) && (object2.species==object3.species) && (object3.species==object4.species) ) { // They are all the same animal (don't care WHICH animal they are) } But that isn't so elegant right? And if I suddenly want to know if EXACTLY 3 or 2 of them are the same species (don't care WHICH species it is though), suddenly I'm in spaghetti code. I am using Objective C although I don't know if that matters really, since the most elegant solution to this is I assume the same in all languages conceptually? Anyone got good idea? Thanks!!

    Read the article

  • C++ Namespaces & templates question

    - by Kotti
    Hi! I have some functions that can be grouped together, but don't belong to some object / entity and therefore can't be treated as methods. So, basically in this situation I would create a new namespace and put the definitions in a header file, the implementation in cpp file. Also (if needed) I would create an anonymous namespace in that cpp file and put all additional functions that don't have to be exposed / included to my namespace's interface there. See the code below (probably not the best example and could be done better with another program architecture, but I just can't think of a better sample...) Sample code (header) namespace algorithm { void HandleCollision(Object* object1, Object* object2); } Sample code (cpp) #include "header" // Anonymous namespace that wraps // routines that are used inside 'algorithm' methods // but don't have to be exposed namespace { void RefractObject(Object* object1) { // Do something with that object // (...) } } namespace algorithm { void HandleCollision(Object* object1, Object* object2) { if (...) RefractObject(object1); } } So far so good. I guess this is a good way to manage my code, but I don't know what should I do if I have some template-based functions and want to do basically the same. If I'm using templates, I have to put all my code in the header file. Ok, but how should I conceal some implementation details then? Like, I want to hide RefractObject function from my interface, but I can't simply remove it's declaration (just because I have all my code in a header file)... The only approach I came up with was something like: Sample code (header) namespace algorithm { // Is still exposed as a part of interface! namespace impl { template <typename T> void RefractObject(T* object1) { // Do something with that object // (...) } } template <typename T, typename Y> void HandleCollision(T* object1, Y* object2) { impl::RefractObject(object1); // Another stuff } } Any ideas how to make this better in terms of code designing?

    Read the article

  • Sorting and Re-arranging List of HashMaps

    - by HonorGod
    I have a List which is straight forward representation of a database table. I am trying to sort and apply some magic after the data is loaded into List of HashMaps. In my case this is the only hard and fast way of doing it becoz I have a rules engine that actually updates the values in the HashMap after several computations. Here is a sample data representation of the HashMap (List of HashMap) - {fromDate=Wed Mar 17 10:54:12 EDT 2010, eventId=21, toDate=Tue Mar 23 10:54:12 EDT 2010, actionId=1234} {fromDate=Wed Mar 17 10:54:12 EDT 2010, eventId=11, toDate=Wed Mar 17 10:54:12 EDT 2010, actionId=456} {fromDate=Sat Mar 20 10:54:12 EDT 2010, eventId=20, toDate=Thu Apr 01 10:54:12 EDT 2010, actionId=1234} {fromDate=Wed Mar 24 10:54:12 EDT 2010, eventId=22, toDate=Sat Mar 27 10:54:12 EDT 2010, actionId=1234} {fromDate=Wed Mar 17 10:54:12 EDT 2010, eventId=11, toDate=Fri Mar 26 10:54:12 EDT 2010, actionId=1234} {fromDate=Sat Mar 20 10:54:12 EDT 2010, eventId=11, toDate=Wed Mar 31 10:54:12 EDT 2010, actionId=1234} {fromDate=Mon Mar 15 10:54:12 EDT 2010, eventId=12, toDate=Wed Mar 17 10:54:12 EDT 2010, actionId=567} I am trying to achieve couple of things - 1) Sort the list by actionId and eventId after which the data would look like - {fromDate=Wed Mar 17 10:54:12 EDT 2010, eventId=11, toDate=Wed Mar 17 10:54:12 EDT 2010, actionId=456} {fromDate=Mon Mar 15 10:54:12 EDT 2010, eventId=12, toDate=Wed Mar 17 10:54:12 EDT 2010, actionId=567} {fromDate=Wed Mar 24 10:54:12 EDT 2010, eventId=22, toDate=Sat Mar 27 10:54:12 EDT 2010, actionId=1234} {fromDate=Wed Mar 17 10:54:12 EDT 2010, eventId=21, toDate=Tue Mar 23 10:54:12 EDT 2010, actionId=1234} {fromDate=Sat Mar 20 10:54:12 EDT 2010, eventId=20, toDate=Thu Apr 01 10:54:12 EDT 2010, actionId=1234} {fromDate=Wed Mar 17 10:54:12 EDT 2010, eventId=11, toDate=Fri Mar 26 10:54:12 EDT 2010, actionId=1234} {fromDate=Sat Mar 20 10:54:12 EDT 2010, eventId=11, toDate=Wed Mar 31 10:54:12 EDT 2010, actionId=1234} 2) If we group the above list by actionId they would be resolved into 3 groups - actionId=1234, actionId=567 and actionId=456. Now here is my question - For each group having the same eventId, I need to update the records so that they have wider fromDate to toDate. Meaning, if you consider the last two rows they have same actionId = 1234 and same eventId = 11. Now we can to pick the least fromDate from those 2 records which is Wed Mar 17 10:54:12 and farther toDate which is Wed Mar 31 10:54:12 and update those 2 record's fromDate and toDate to Wed Mar 17 10:54:12 and Wed Mar 31 10:54:12 respectively. Any ideas? PS: I already have some pseudo code to start with. import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; import org.apache.commons.lang.builder.CompareToBuilder; public class Tester { boolean ascending = true ; boolean sortInstrumentIdAsc = true ; boolean sortEventTypeIdAsc = true ; public static void main(String args[]) { Tester tester = new Tester() ; tester.printValues() ; } public void printValues () { List<HashMap<String,Object>> list = new ArrayList<HashMap<String,Object>>() ; HashMap<String,Object> map = new HashMap<String,Object>(); map.put("actionId", new Integer(1234)) ; map.put("eventId", new Integer(21)) ; map.put("fromDate", getDate(1) ) ; map.put("toDate", getDate(7) ) ; list.add(map); map = new HashMap<String,Object>(); map.put("actionId", new Integer(456)) ; map.put("eventId", new Integer(11)) ; map.put("fromDate", getDate(1)) ; map.put("toDate", getDate(1) ) ; list.add(map); map = new HashMap<String,Object>(); map.put("actionId", new Integer(1234)) ; map.put("eventId", new Integer(20)) ; map.put("fromDate", getDate(4) ) ; map.put("toDate", getDate(16) ) ; list.add(map); map = new HashMap<String,Object>(); map.put("actionId", new Integer(1234)) ; map.put("eventId", new Integer(22)) ; map.put("fromDate",getDate(8) ) ; map.put("toDate", getDate(11)) ; list.add(map); map = new HashMap<String,Object>(); map.put("actionId", new Integer(1234)) ; map.put("eventId", new Integer(11)) ; map.put("fromDate",getDate(1) ) ; map.put("toDate", getDate(10) ) ; list.add(map); map = new HashMap<String,Object>(); map.put("actionId", new Integer(1234)) ; map.put("eventId", new Integer(11)) ; map.put("fromDate",getDate(4) ) ; map.put("toDate", getDate(15) ) ; list.add(map); map = new HashMap<String,Object>(); map.put("actionId", new Integer(567)) ; map.put("eventId", new Integer(12)) ; map.put("fromDate", getDate(-1) ) ; map.put("toDate",getDate(1)) ; list.add(map); System.out.println("\n Before Sorting \n "); for(int j = 0 ; j < list.size() ; j ++ ) System.out.println(list.get(j)); Collections.sort ( list , new HashMapComparator2 () ) ; System.out.println("\n After Sorting \n "); for(int j = 0 ; j < list.size() ; j ++ ) System.out.println(list.get(j)); } public static Date getDate(int days) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DATE, days); return cal.getTime() ; } public class HashMapComparator2 implements Comparator { public int compare ( Object object1 , Object object2 ) { if ( ascending == true ) { return new CompareToBuilder() .append(( ( HashMap ) object1 ).get ( "actionId" ), ( ( HashMap ) object2 ).get ( "actionId" )) .append(( ( HashMap ) object2 ).get ( "eventId" ), ( ( HashMap ) object1 ).get ( "eventId" )) .toComparison(); } else { return new CompareToBuilder() .append(( ( HashMap ) object2 ).get ( "actionId" ), ( ( HashMap ) object1 ).get ( "actionId" )) .append(( ( HashMap ) object2 ).get ( "eventId" ), ( ( HashMap ) object1 ).get ( "eventId" )) .toComparison(); } } } }

    Read the article

  • iphone - mutableArray cannot store nil objects

    - by Mike
    I have a mutable array that is retained and storing several objects. At some point, one object may become nil. When this happens the app will crash, because arrays cannot have nil objects. Imagine something like [object1, object2, object3, nil]; then, object2 = nil [object1, nil, object3, nil]; that is not possible because nil is the end of array marker. So, how can I solve that? thanks for any help.

    Read the article

  • Calling one DAO from another DAO?

    - by es11
    Can this ever make sense? Say I need to fetch an object from the DB which has a relation to another object (represented by a foreign key in the DB, and by a composition in my domain object). If in my first DAO I fetch the data for object 1, then call the dao for object 2, and finally (from within the first DAO, call the setter in object 1 and give it the previously fetched object 2). I know I could do a join instead, but it just seems more logical to me to decouple the functionality (which is why I am skeptical about calling one dao from another). Or should I move some of the logic to the service layer? Thanks Update: I think I solved the problem with help from the answers: all I needed to do was add the following to my mapping of Object 1: <one-to-one name="Object2" fetch="join" class="com...Object2"></one-to-one> I didn't have to change anything else. Thanks for the help!

    Read the article

  • Sort ArrayList of custom Objects by property

    - by Samuel
    Hello World!! :D I had a question which is pretty easy if you know the answer I guess. I read about sorting ArrayLists using a Comparator but somehow in all of the examples people used compareTo which according to some research is a method working on Strings... I wanted to sort an ArrayList of custom objects by one of their properties: a Date object (getStartDay()). Normally I compare them by item1.getStartDate().before(item2.getStartDate()) so I was wondering whether I could write something like: public class customComparator { public boolean compare(Object object1, Object object2) { return object1.getStartDate().before(object2.getStartDate()); } } public class randomName { ... Collections.sort(Database.arrayList, new customComparator); ... } I just started with Java so please forgive my ignorance :) Thanks in advance!! -Samuel

    Read the article

  • Complex Entity Framework linked-graphs issue: how to limit change set / break the graph?

    - by Hightechrider
    I have an EDMX containing Sentences, and Words, say and a Sentence contains three Words, say. Appropriate FK relationships exist between the tables. I create some words: Word word1 = new Word(); Word word2 = ... I build a Sentence: Sentence x = new Sentence (word1, word2, word3); I build another Sentence: Sentence y = new Sentence (word1, word4, word5); I try to save x to the database, but EF builds a change set that includes everything, including y, word4 and word5 that aren't ready to save to the database. When SaveChanges() happens it throws an exception: Unable to determine the principal end of the ... relationship. Multiple added entities may have the same primary key. I think it does this because Word has an EntityCollection<Sentence> on it from the FK relationship between the two tables, and thus Sentence y is inextricably linked to Sentence x through word1. So I remove the Navigation Property Sentences from Word and try again. It still tries to put the entire graph into the change set. What suggestions do the Entity Framework experts have for ways to break this connection. Essentially what I want is a one-way mapping from Sentence to Word; I don't want an EntityCollection<Sentence> on Word and I don't want the object graph to get intertwined like this. Code sample: This puts two sentences into the database because Verb1 links them and EF explores the entire graph of existing objects and added objects when you do Add/SaveChanges. Word subject1 = new Word(){ Text = "Subject1"}; Word subject2 = new Word(){ Text = "Subject2"}; Word verb1 = new Word(){ Text = "Verb11"}; Word object1 = new Word(){ Text = "Object1"}; Word object2 = new Word(){ Text = "Object2"}; Sentence s1 = new Sentence(){Subject = subject1, Verb=verb1, Object=object1}; Sentence s2 = new Sentence(){Subject=subject2, Verb=verb1, Object=object2}; context.AddToSentences(s1); context.SaveChanges(); foreach (var s in context.Sentences) { Console.WriteLine(s.Subject + " " + s.Verb + " " + s.Object); }

    Read the article

  • WebTextEdit ClientSideEvent Javascript - Can't Eval

    - by ismail
    Hi, I urgently need help, please. WebtextEdit ClientSideEvent execute javascript statement on mousemove event. I can successfully change the style of another object type on this WebTextEdit ClientSide MouseMove event: document.getElementById("Object2").style.backgroundColor = '#F0F5F7'; But when I want to change the style of the WebTextEdit control: document.getElementById("WebTextEdit1").style.backgroundColor = '#F0F5F7'; Then nothing happens. When I execute the script on the same WebTextEdit Clientside for another object which is not a WebtextEdit: Object2.style.border='1px solid #FFE6A0'; Then it works. But when I want to change the WebtextEdit Clientside style: WebTextEdit1.style.border='1px solid #FFE6A0'; Then I get Error: Can't Eval WebTextEdit1.style.border='1px solid #FFE6A0';

    Read the article

  • How created method with signature as List

    - by London
    Hi all, I'm very new to Java programming language so this is probably dumb question but I have to ask it because I can't figure it out on my own. Here is the deal. I want to create method which extracts certain object type from a list. So the method should receive List as argument, meaning list should contain either Object1 or Object2. I've tried like this : public Object1 extractObject(List<?>){ //some pseudo-code ... loop trough list and check if list item is instance of object one return that instance } The problem with declaring method with List<?> as method argument is that I receive compilation error from eclipse Syntax error on token ">", VariableDeclaratorId expected after this token. How do I set the method signature properly to accept object types either Object1 or Object2 ? Thank you

    Read the article

  • Loop through custom template hooking thing

    - by tarnfeld
    Hi, I am building a template system for emailing people that currently works in the format of: $array['key1'] = "text; $array['key2'] = "more text"; <!--key1--> // replaced with *text* <!--key2--> // replaced with *more text* For this particular project I have a nested array with this kind of structure: $array['object1']['nest1']['key1'] = "text"; $array['object2']['next1']['key1'] = "more text"; <!--[object1][nest1][key1]--> // replaced with *text* <!--[object2][nest1][key1]--> // replaced with *more text* What would be the best way to do this in PHP? I thought I could loop through the arrays but then I just lost my trail of thought and got lost in what I was doing! All help would be appreciated!! Thanks

    Read the article

  • Function signature-like expressions as C++ template arguments

    - by Jeff Lee
    I was looking at Don Clugston's FastDelegate mini-library and noticed a weird syntactical trick with the following structure: TemplateClass< void( int, int ) > Object; It almost appears as if a function signature is being used as an argument to a template instance declaration. This technique (whose presence in FastDelegate is apparently due to one Jody Hagins) was used to simplify the declaration of template instances with a semi-arbitrary number of template parameters. To wit, it allowed this something like the following: // A template with one parameter template<typename _T1> struct Object1 { _T1 m_member1; }; // A template with two parameters template<typename _T1, typename _T2> struct Object2 { _T1 m_member1; _T2 m_member2; }; // A forward declaration template<typename _Signature> struct Object; // Some derived types using "function signature"-style template parameters template<typename _Dummy, typename _T1> struct Object<_Dummy(_T1)> : public Object1<_T1> {}; template<typename _Dummy, typename _T1, typename _T2> struct Object<_Dummy(_T1, _T2)> : public Object2<_T1, _T2> {}; // A. "Vanilla" object declarations Object1<int> IntObjectA; Object2<int, char> IntCharObjectA; // B. Nifty, but equivalent, object declarations typedef void UnusedType; Object< UnusedType(int) > IntObjectB; Object< UnusedType(int, char) > IntCharObjectB; // C. Even niftier, and still equivalent, object declarations #define DeclareObject( ... ) Object< UnusedType( __VA_ARGS__ ) > DeclareObject( int ) IntObjectC; DeclareObject( int, char ) IntCharObjectC; Despite the real whiff of hackiness, I find this kind of spoofy emulation of variadic template arguments to be pretty mind-blowing. The real meat of this trick seems to be the fact that I can pass textual constructs like "Type1(Type2, Type3)" as arguments to templates. So here are my questions: How exactly does the compiler interpret this construct? Is it a function signature? Or, is it just a text pattern with parentheses in it? If the former, then does this imply that any arbitrary function signature is a valid type as far as the template processor is concerned? A follow-up question would be that since the above code sample is valid code, why doesn't the C++ standard just allow you to do something like the following, which is does not compile? template<typename _T1> struct Object { _T1 m_member1; }; // Note the class identifier is also "Object" template<typename _T1, typename _T2> struct Object { _T1 m_member1; _T2 m_member2; }; Object<int> IntObject; Object<int, char> IntCharObject;

    Read the article

  • @Autowire strange problem

    - by Javi
    Hello, I have a strange behaviour when autowiring I have a similar code like this one, and it works @Controller public class Class1 { @Autowired private Class2 object2; ... } @Service @Transactional public class Class2{ ... } The problem is that I need that the Class2 implements an interface so I've only changed the Class2 so it's now like: @Controller public class Class1 { @Autowired private Class2 object2; ... } @Service @Transactional public class Class2 implements IServiceReference<Class3, Long>{ ... } public interface IServiceReference<T, PK extends Serializable> { public T reference(PK id); } with this code I get a org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type for Class2. It seems that @ Transitional annotation is not compatible with the interface because if I remove the @Transitional annotation or the "implements IServiceReference" the problem disapears and the bean is injected (though I need to have both in this class). It also happens if I put the annotation @Transitional in the methods instead of in the Class. I use Spring 3.0.2 if this helps. Is not compatible the interface with the transactional method? May it be a Spring bug? Thanks

    Read the article

  • can I acces a struct inside of a struct without using the dot operator?

    - by yan bellavance
    I have 2 structures that have 90% of their fields the same. I want to group those fields in a structure but I do not want to use the dot operator to access them. The reason is I already coded with the first structure and have just created the second one. before: struct{ int a; int b; int c; object1 name; }str1; struct{ int a; int b; int c; object2 name; }str2; now I would create a third struct: struct{ int a; int b; int c; }str3; and would change the str1 and atr2 to this: struct{ str3 str; object1 name; }str1; struct { str3 str; object2 name; }str2; Finally I would like to be able to access a,b and c by doing: str1 myStruct; myStruct.a; myStruct.b; myStruct.c; and not: myStruct.str.a; myStruct.str.b; myStruct.str.c; Is there a way to do such a thing. The reason for doing this is I want keep the integrety of the data if chnges to the struct were to occur and to not repeat myself and not have to change my existing code and not have fields nested too deeply.

    Read the article

1 2  | Next Page >