Search Results

Search found 362 results on 15 pages for 'semantics'.

Page 2/15 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • NHibernate and objects with value-semantics

    - by Groo
    Problem: If I pass a class with value semantics (Equals method overridden) to NHibernate, NHibernate tries to save it to db even though it just saved an entity equal by value (but not by reference) to the database. What am I doing wrong? Here is a simplified example model for my problem: Let's say I have a Person entity and a City entity. One thread (producer) is creating new Person objects which belong to a specific existing City, and another thread (consumer) is saving them to a repository (using NHibernate as DAL). Since there is lot of objects being flushed at a time, I am using Guid.Comb id's to ensure that each insert is made using a single SQL command. City is an object with value-type semantics (equal by name only -- for this example purposes only): public class City : IEquatable<City> { public virtual Guid Id { get; private set; } public virtual string Name { get; set; } public virtual bool Equals(City other) { if (other == null) return false; return this.Name == other.Name; } public override bool Equals(object obj) { return Equals(obj as City); } public override int GetHashCode() { return this.Name.GetHashCode(); } } Fluent NH mapping is something like: public class PersonMap : ClassMap<Person> { public PersonMap() { Id(x => x.Id) .GeneratedBy.GuidComb(); References(x => x.City) .Cascade.SaveUpdate(); } } public class CityMap : ClassMap<City> { public CityMap() { Id(x => x.Id) .GeneratedBy.GuidComb(); Map(x => x.Name); } } Right now (with my current NHibernate mapping config), my consumer thread maintains a dictionary of cities and replaces their references in incoming person objects (otherwise NHibernate will see a new, non-cached City object and try to save it as well), and I need to do it for every produced Person object. Since I have implemented City class to behave like a value type, I hoped that NHibernate would compare Cities by value and not try to save them each time -- i.e. I would only need to do a lookup once per session and not care about them anymore. Is this possible, and if yes, what am I doing wrong here?

    Read the article

  • LEFT OUTER JOIN in NHibernate with SQL semantics

    - by Yuval
    Hi, Is it possible to use HQL/ICritera to produce a query with the same semantics as the following SQL query: select table1.A, table2.B, count(*) from table1 left join (select table2.parent_id, table2.B from table2 where table2.C = 'Some value') as table2 on table2.parent_id = table1.id group by table1.A, table2.B order by table1.A In particular, what I'd like is to receive rows (that is, objects) from table1 that have no matching rows in table2. However, I only get the rows from table1 that have matches in table2. Is this the meaning of 'LEFT JOIN' in HQL? And if so, how can I get it to join on a subquery? Tnx.

    Read the article

  • Rails has_one vs belongs_to semantics

    - by Anurag
    I have a model representing a Content item that contains some images. The number of images are fixed as these image references are very specific to the content. For example, the Content model refers to the Image model twice (profile image, and background image). I am trying to avoid a generic has_many, and sticking to multiple has_one's. The current database structure looks like: contents - id:integer - integer:profile_image_id - integer:background_image_id images - integer:id - string:filename - integer:content_id I just can't figure out how to setup the associations correctly here. The Content model could contain two belongs_to references to an Image, but that doesn't seem semantically right cause ideally an image belongs to the content, or in other words, the content has two images. This is the best I could think of (by breaking the semantics): class Content belongs_to :profile_image, :class_name => 'Image', :foreign_key => 'profile_image_id' belongs_to :background_image, :class_name => 'Image', :foreign_key => 'background_image_id' end Am I way off, and there a better way to achieve this association?

    Read the article

  • Where do you hang your semantic information, html?

    - by bobobobo
    Well, I keep putting semantic information about what an element means for the page logically in the class attribute <li class="phone-number">555-5555</li> It seems to work for this dual purpose of hanging semantic information and a pointer to how to style it. I'm not sure if this is the best idea, I'm trying to see if others have other ways of doing it. I also started to use a hidden input: <li>555-5555 <input class="semantics" type="hidden" value="phone-number" /></li> inside an element, so with jQuery, I can retrieve additional information about the element using li.find( '.semantics' ).val() To get an element's semantics from JavaScript

    Read the article

  • Const-correctness semantics in C++

    - by thirtythreeforty
    For fun and profit™, I'm writing a trie class in C++ (using the C++11 standard.) My trie<T> has an iterator, trie<T>::iterator. (They're all actually functionally const_iterators, because you cannot modify a trie's value_type.) The iterator's class declaration looks partially like this: template<typename T> class trie<T>::iterator : public std::iterator<std::bidirectional_iterator_tag, T> { friend class trie<T>; struct state { state(const trie<T>* const node, const typename std::vector<std::pair<typename T::value_type, std::unique_ptr<trie<T>>>>::const_iterator& node_map_it ) : node{node}, node_map_it{node_map_it} {} // This pointer is to const data: const trie<T>* node; typename std::vector<std::pair<typename T::value_type, std::unique_ptr<trie<T>>>>::const_iterator node_map_it; }; public: typedef const T value_type; iterator() =default; iterator(const trie<T>* node) { parents.emplace(node, node->children.cbegin()); // ... } // ... private: std::stack<state> parents; // ... }; Notice that the node pointer is declared const. This is because (in my mind) the iterator should not be modifying the node that it points to; it is just an iterator. Now, elsewhere in my main trie<T> class, I have an erase function that has a common STL signature--it takes an iterator to data to erase (and returns an iterator to the next object). template<typename T> typename trie<T>::iterator trie<T>::erase(const_iterator it) { // ... // Cannot modify a const object! it.parents.top().node->is_leaf = false; // ... } The compiler complains because the node pointer is read-only! The erase function definitely should modify the trie that the iterator points to, even though the iterator shouldn't. So, I have two questions: Should iterator's constructors be public? trie<T> has the necessary begin() and end() members, and of course trie<T>::iterator and trie<T> are mutual friends, but I don't know what the convention is. Making them private would solve a lot of the angst I'm having about removing the const "promise" from the iterator's constructor. What are the correct const semantics/conventions regarding the iterator and its node pointer here? Nobody has ever explained this to me, and I can't find any tutorials or articles on the Web. This is probably the more important question, but it does require a good deal of planning and proper implementation. I suppose it could be circumvented by just implementing 1, but it's the principle of the thing!

    Read the article

  • CSS semantics; selecting elements directly or via order

    - by Joshua Cody
    Perhaps this question has been asked elsewhere, but I'm unable to find it. With HTML5 and CSS3 modules inching closer, I'm getting interested in a discussion about the way we write CSS. Something like this where selection is done via element order and type is particularly fascinating. The big advantage to this method seems to be complete modularization of HTML and CSS to make tweaks and redesigns simpler. At the same time, semantic IDs and classes seem advantageous for sundry reasons. Particularly, direct linking, JS targeting, and shorter CSS selectors. Also, it seems selector length might be an issue. For instance, I just wrote the following, which would be admittedly easier using some semantic HTML5 elements: body>div:nth-child(2)>div:nth-child(2)>ul:nth-child(2)>li:last-child So what say you, Stack Overflow? Is the future of CSS writing focused on element order and type? Or are IDs and classes and the current ways here to stay? (I'm well aware the IDs and classes have their place, although I am interested to hear more ways you think they'll continue to be necessary. The discussion I'm interested in is bigger-picture and the ways writing CSS is changing.)

    Read the article

  • How to maintain the HTML semantics when HTML is used for drawing diagrams (like organizational chart

    - by Vijay
    I have created an organizational chart using ASP.NET on web page. The web page is using strict DOCTYPE and following W3C standards. The chart has a hierarchical layout decided by the manager field in the table that contains employees in the organization. The chart layout has nodes with employee image and other details like job title, department and contact details. Nodes are beautifully arranged and connected by lines (only horizontal or vertical or both). A lot of DIV elements are used (to avoid table) for connecting lines and arranging the chart properly. As suggested by my friend, using DIVs for connecting lines in the chart is semantically wrong. Is there a way by which I can make it semantically correct? Or, am I using HTML for the wrong purpose?

    Read the article

  • .Net Finalizer Order / Semantics in Esent and Ravendb

    - by mattcodes
    Help me understand. I've read that "The time and order of execution of finalizers cannot be predicted or pre-determined" Correct? However looking at RavenDB source code TransactionStorage.cs I see this ~TransactionalStorage() { try { Trace.WriteLine( "Disposing esent resources from finalizer! You should call TransactionalStorage.Dispose() instead!"); Api.JetTerm2(instance, TermGrbit.Abrupt); } catch (Exception exception) { try { Trace.WriteLine("Failed to dispose esent instance from finalizer because: " + exception); } catch { } } } The API class (which belongs to Managed Esent) which presumable takes handles on native resources presumably using a SafeHandle? So if I understand correctly the native handles SafeHandle can be finalized before TransactionStorage which could have undesired effects, perhaps why Ayende has added an catch all clause around this? Actually diving into Esent code, it does not use SafeHandles. According to CLR via C# this is dangerous? internal static class SomeType { [DllImport("Kernel32", CharSet=CharSet.Unicode, EntryPoint="CreateEvent")] // This prototype is not robust private static extern IntPtr CreateEventBad( IntPtr pSecurityAttributes, Boolean manualReset, Boolean initialState, String name); // This prototype is robust [DllImport("Kernel32", CharSet=CharSet.Unicode, EntryPoint="CreateEvent")] private static extern SafeWaitHandle CreateEventGood( IntPtr pSecurityAttributes, Boolean manualReset, Boolean initialState, String name) public static void SomeMethod() { IntPtr handle = CreateEventBad(IntPtr.Zero, false, false, null); SafeWaitHandle swh = CreateEventGood(IntPtr.Zero, false, false, null); } } Managed Esent (NativeMEthods.cs) looks like this (using Ints vs IntPtrs?): [DllImport(EsentDll, CharSet = EsentCharSet, ExactSpelling = true)] public static extern int JetCreateDatabase(IntPtr sesid, string szFilename, string szConnect, out uint dbid, uint grbit); Is Managed Esent handling finalization/dispoal the correct way, and second is RavenDB handling finalizer the corret way or compensating for Managed Esent?

    Read the article

  • URL "fragment identifier" semantics for HTML documents

    - by Pointy
    I've been working with a new installation of the "MoinMoin" wiki software. As I was playing with it, typing in mostly random test pages, I created a link with a fragment blah blah see also [[SomeStuff#whatever|some other stuff about whatever]] Then I needed to figure out how to create the anchor for that "whatever" fragment identifier. I don't recall having to do that with MediaWiki, so I had to dig around, but finally I found that MoinMoin has an "Anchor" macro: == Whatever == <<Anchor(whatever)>> Looking at the generated HTML, I was surprised to see an empty <span> tag with an "id" value of "whatever". I expected that it'd be an <a> tag with a "name" attribute of "whatever". I dug around and found the source, and there's a comment that says they changed it from an <a> tag in order to avoid some IE problem with <pre> sections. This confused me — not because of the IE thing, but because it looked to me as if their "fix" had left the whole anchor mechanism completely broken. Much to my surprise, however, further testing indicated that it worked fine. I wrote a test page with 300 <span> tags all with "id" values, and I further shocked myself when Firefox behaved exactly as I would have expected it to had I used <a> tags. It also worked when I changed all the <span> tags to <em>. So by this time, you're either as surprised as I was, or else you're thinking "how can somebody that dumb have so many reputation points?" If you're in the second category, is it really the case that I've been typing in HTML for about 15 years now — a lot of HTML — and it's somehow escaped my notice that browsers use the HTML fragment to find any sort of element with a matching "id"? mind status: blown

    Read the article

  • Basic question on retain/release semantics from Apple's reference library

    - by davetron5000
    I have done Objective-C way back when, and have recently (i.e. just now) read the documentation on Apple's site regarding the use of retain and release. However, there is a bit of code in their Creating an iPhone Application page that has me a bit confused: - (void)setUpPlacardView { // Create the placard view -- it calculates its own frame based on its image. PlacardView *aPlacardView = [[PlacardView alloc] init]; self.placardView = aPlacardView; [aPlacardView release]; // What effect does this have on self.placardView?! placardView.center = self.center; [self addSubview:placardView]; } Not seeing the entire class, it seems that self.placardView is also a PlacardView * and the assignment of it to aPlacardView doesn't seem to indicate it will retain a reference to it. So, it appears to me that the line I've commented ([aPlacardView release];) could result in aPlacardView having a retain count of 0 and thus being deallocated. Since self.placardView points to it, wouldn't that now point at deallocated memory and cause a problem?

    Read the article

  • What are the semantics of [myThing.myProperty release]?

    - by dugla
    I clearly have not fully grocked properties. I have an instance of a class, myThing. myThing has a property that has be synthesized: // .h @property(nonatomic,retain)MyCoolType *coolType; // .m @synthesize coolType; In my program I call: // The retain count on MyCoolType is 1. [myThing.coolType release]; The reference count on MyCoolType is now zero and dealloc should fire. So, shouldn't myThing.coolType now be nil? In my code that is not the case. How do a correctly release and force the property to return nil? Thanks, Doug

    Read the article

  • Semantics of repeated acknowledgments in JMS

    - by Lajos Nagy
    Suppose I decide to call acknowledgment() on a JMS message several times. Say the first call fails (for non-permanent reason). Does the success of the second (or any subsequent) call guarantee that the message is now acknowledged? Is the exact behavior of acknowledgement() specified anywhere?

    Read the article

  • H1 tags, SEO and semantics

    - by dazhall
    Hi guys, I'm using the H1 tag in my document as the main title, as you do. The text in the H1 is the title of the company, which needs to be shown on every page. I'm using the H2 tag for the title of the main content on each page. So the H1 is the same on every page, and the H2 changes. I know that a lot of sites use the H1 to do what I'm doing with the H2, am I losing out by not doing this? I know that semantically I can't make the H1 into a H2 and vice versa, so I'm wondering what the best option is. Does it matter that my H1 is always the same? Any advice is appreciated! Thanks! Darren.

    Read the article

  • Semantics of setting cookies and redirecting without getting header error

    - by salmane
    I would like to do the following in php : setcookie('name', $value, $Cookie_Expiration,'/'); then some action header("location:http://www.example.com") the problem is that I get : warning: Cannot modify header information - headers already sent by (...etc ) could you please let me know what i am doing wrong and if there is a way to do this? by the way , this code is before any output is made ...the cookie setting part works fine on its own and so does the redirection code....the combination fails thank you

    Read the article

  • How to get Ponter/Reference semantics in Scala.

    - by Lukasz Lew
    In C++ I would just take a pointer (or reference) to arr[idx]. In Scala I find myself creating this class to emulate a pointer semantic. class SetTo (val arr : Array[Double], val idx : Int) { def apply (d : Double) { arr(idx) = d } } Isn't there a simpler way? Doesn't Array class have a method to return some kind of reference to a particular field?

    Read the article

  • C++ const-reference semantics?

    - by Kristoffer
    Consider the sample application below. It demonstrates what I would call a flawed class design. #include <iostream> using namespace std; struct B { B() : m_value(1) {} long m_value; }; struct A { const B& GetB() const { return m_B; } void Foo(const B &b) { // assert(this != &b); m_B.m_value += b.m_value; m_B.m_value += b.m_value; } protected: B m_B; }; int main(int argc, char* argv[]) { A a; cout << "Original value: " << a.GetB().m_value << endl; cout << "Expected value: 3" << endl; a.Foo(a.GetB()); cout << "Actual value: " << a.GetB().m_value << endl; return 0; } Output: Original value: 1 Expected value: 3 Actual value: 4 Obviously, the programmer is fooled by the constness of b. By mistake b points to this, which yields the undesired behavior. My question: What const-rules should you follow when designing getters/setters? My suggestion: Never return a reference to a member variable if it can be set by reference through a member function. Hence, either return by value or pass parameters by value. (Modern compilers will optimize away the extra copy anyway.)

    Read the article

  • Trouble understanding the semantics of volatile in Java

    - by HungryTux
    I've been reading up about the use of volatile variables in Java. I understand that they ensure instant visibility of their latest updates to all the threads running in the system on different cores/processors. However no atomicity of the operations that caused these updates is ensured. I see the following literature being used frequently A write to a volatile field happens-before every read of that same field . This is where I am a little confused. Here's a snippet of code which should help me better explain my query. volatile int x = 0; volatile int y = 0; Thread-0: | Thread-1: | if (x==1) { | if (y==1) { return false; | return false; } else { | } else { y=1; | x=1; return true; | return true; } | } Since x & y are both volatile, we have the following happens-before edges between the write of y in Thread-0 and read of y in Thread-1 between the write of x in Thread-1 and read of x in Thread-0 Does this imply that, at any point of time, only one of the threads can be in its 'else' block(since a write would happen before the read)? It may well be possible that Thread-0 starts, loads x, finds it value as 0 and right before it is about to write y in the else-block, there's a context switch to Thread-1 which loads y finds it value as 0 and thus enters the else-block too. Does volatile guard against such context switches (seems very unlikely)?

    Read the article

  • An unusual type signature

    - by Travis Brown
    In Monads for natural language semantics, Chung-Chieh Shan shows how monads can be used to give a nicely uniform restatement of the standard accounts of some different kinds of natural language phenomena (interrogatives, focus, intensionality, and quantification). He defines two composition operations, A_M and A'_M, that are useful for this purpose. The first is simply ap. In the powerset monad ap is non-deterministic function application, which is useful for handling the semantics of interrogatives; in the reader monad it corresponds to the usual analysis of extensional composition; etc. This makes sense. The secondary composition operation, however, has a type signature that just looks bizarre to me: (<?>) :: (Monad m) => m (m a -> b) -> m a -> m b (Shan calls it A'_M, but I'll call it <?> here.) The definition is what you'd expect from the types; it corresponds pretty closely to ap: g <?> x = g >>= \h -> return $ h x I think I can understand how this does what it's supposed to in the context of the paper (handle question-taking verbs for interrogatives, serve as intensional composition, etc.). What it does isn't terribly complicated, but it's a bit odd to see it play such a central role here, since it's not an idiom I've seen in Haskell before. Nothing useful comes up on Hoogle for either m (m a -> b) -> m a -> m b or m (a -> b) -> a -> m b. Does this look familiar to anyone from other contexts? Have you ever written this function?

    Read the article

  • Can a stack have an exception safe method for returning and removing the top element with move seman

    - by Motti
    In an answer to a question about std::stack::pop() I claimed that the reason pop does not return the value is for exception safety reason (what happens if the copy constructor throws). @Konrad commented that now with move semantics this is no longer relevant. Is this true? AFAIK, move constructors can throw, but perhaps with noexcept it can still be achieved. For bonus points what thread safety guarantees can this operation supply?

    Read the article

  • "Strictly positive" in Agda

    - by Jason
    I'm trying to encode some denotational semantics into Agda based on a program I wrote in Haskell. data Value = FunVal (Value -> Value) | PriVal Int | ConVal Id [Value] | Error String In Agda, the direct translation would be; data Value : Set where FunVal : (Value -> Value) -> Value PriVal : N -> Value ConVal : String -> List Value -> Value Error : String -> Value but I get an error relating to the FunVal because; Value is not strictly positive, because it occurs to the left of an arrow in the type of the constructor FunVal in the definition of Value. What does this mean? Can I encode this in Agda? Am I going about it the wrong way? Thanks.

    Read the article

  • Is std::move really needed on initialization list of constructor for heavy members passed by value?

    - by PiotrNycz
    Recently I read an example from cppreference.../vector/emplace_back: struct President { std::string name; std::string country; int year; President(std::string p_name, std::string p_country, int p_year) : name(std::move(p_name)), country(std::move(p_country)), year(p_year) { std::cout << "I am being constructed.\n"; } My question: is this std::move really needed? My point is that compiler sees that this p_name is not used in the body of constructor, so, maybe, there is some rule to use move semantics for it by default? That would be really annoying to add std::move on initialization list to every heavy member (like std::string, std::vector). Imagine hundreds of KLOC project written in C++03 - shall we add everywhere this std::move? This question: move-constructor-and-initialization-list answer says: As a golden rule, whenever you take something by rvalue reference, you need to use it inside std::move, and whenever you take something by universal reference (i.e. deduced templated type with &&), you need to use it inside std::forward But I am not sure: passing by value is rather not universal reference?

    Read the article

  • Making swap faster, easier to use and exception-safe

    - by FredOverflow
    I could not sleep last night and started thinking about std::swap. Here is the familiar C++98 version: template <typename T> void swap(T& a, T& b) { T c(a); a = b; b = c; } If a user-defined class Foo uses external ressources, this is inefficient. The common idiom is to provide a method void Foo::swap(Foo& other) and a specialization of std::swap<Foo>. Note that this does not work with class templates since you cannot partially specialize a function template, and overloading names in the std namespace is illegal. The solution is to write a template function in one's own namespace and rely on argument dependent lookup to find it. This depends critically on the client to follow the "using std::swap idiom" instead of calling std::swap directly. Very brittle. In C++0x, if Foo has a user-defined move constructor and a move assignment operator, providing a custom swap method and a std::swap<Foo> specialization has little to no performance benefit, because the C++0x version of std::swap uses efficient moves instead of copies: #include <utility> template <typename T> void swap(T& a, T& b) { T c(std::move(a)); a = std::move(b); b = std::move(c); } Not having to fiddle with swap anymore already takes a lot of burden away from the programmer. Current compilers do not generate move constructors and move assignment operators automatically yet, but as far as I know, this will change. The only problem left then is exception-safety, because in general, move operations are allowed to throw, and this opens up a whole can of worms. The question "What exactly is the state of a moved-from object?" complicates things further. Then I was thinking, what exactly are the semantics of std::swap in C++0x if everything goes fine? What is the state of the objects before and after the swap? Typically, swapping via move operations does not touch external resources, only the "flat" object representations themselves. So why not simply write a swap template that does exactly that: swap the object representations? #include <cstring> template <typename T> void swap(T& a, T& b) { unsigned char c[sizeof(T)]; memcpy( c, &a, sizeof(T)); memcpy(&a, &b, sizeof(T)); memcpy(&b, c, sizeof(T)); } This is as efficient as it gets: it simply blasts through raw memory. It does not require any intervention from the user: no special swap methods or move operations have to be defined. This means that it even works in C++98 (which does not have rvalue references, mind you). But even more importantly, we can now forget about the exception-safety issues, because memcpy never throws. I can see two potential problems with this approach: First, not all objects are meant to be swapped. If a class designer hides the copy constructor or the copy assignment operator, trying to swap objects of the class should fail at compile-time. We can simply introduce some dead code that checks whether copying and assignment are legal on the type: template <typename T> void swap(T& a, T& b) { if (false) // dead code, never executed { T c(a); // copy-constructible? a = b; // assignable? } unsigned char c[sizeof(T)]; std::memcpy( c, &a, sizeof(T)); std::memcpy(&a, &b, sizeof(T)); std::memcpy(&b, c, sizeof(T)); } Any decent compiler can trivially get rid of the dead code. (There are probably better ways to check the "swap conformance", but that is not the point. What matters is that it's possible). Second, some types might perform "unusual" actions in the copy constructor and copy assignment operator. For example, they might notify observers of their change. I deem this a minor issue, because such kinds of objects probably should not have provided copy operations in the first place. Please let me know what you think of this approach to swapping. Would it work in practice? Would you use it? Can you identify library types where this would break? Do you see additional problems? Discuss!

    Read the article

  • boost spirit semantic action parameters

    - by lurscher
    Hi, in this article about boost spirit semantic actions it is mentioned that There are actually 2 more arguments being passed: the parser context and a reference to a boolean ‘hit’ parameter. The parser context is meaningful only if the semantic action is attached somewhere to the right hand side of a rule. We will see more information about this shortly. The boolean value can be set to false inside the semantic action invalidates the match in retrospective, making the parser fail. All fine, but i've been trying to find an example passing a function object as semantic action that uses the other parameters (parser context and hit boolean) but i haven't found any. I would love to see an example using regular functions or function objects, as i barely can grok the phoenix voodoo

    Read the article

  • Is "map" a loop?

    - by DVK
    While answering this question, I came to realize that I was not sure whether Perl's map can be considered a loop or not? On one hand, it quacks/walks like a loop (does O(n) work, can be easily re-written by an equivalent loop, and sort of fits the common definition = "a sequence of instructions that is continually repeated"). On the other hand, map is not usually listed among Perl's control structures, of which loops are a subset of. E.g. http://en.wikipedia.org/wiki/Perl_control_structures#Loops So, what i'm looking for is a formal reason to be convinced of one side vs. the other. So far, the former (it is a loop) sounds a lot more convincing to me, but I'm bothered by the fact that I never saw "map" mentioned in a list of Perl loops.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >