If we have three functions (foo, bar, and baz) that are composed like so...
foo(bar(), baz())
Is there any guarantee by the C++ standard that bar will be evaluated before baz?
I'm trying to expose a fairly simple C# class to COM which should be usable from VBScript (among others).
Some objects need to be created via COM calls and will be used in furter calls later on. The definition of the exposed classes and interfaces looks like this:
namespace Test
{
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IComInterface
{
IFoo CreateFoo();
void UseFoo(int x, IFoo f);
}
[ClassInterface(ClassInterfaceType.None)]
public sealed class CComInterface : IComInterface
{
public CComInterface() {}
public IFoo CreateFoo() { return new Foo(); }
public void UseFoo(int x, IFoo f) { f.Bar(); }
}
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IFoo
{
void Bar();
}
[ClassInterface(ClassInterfaceType.None)]
public class Foo : IFoo
{
internal Foo() {}
public void Bar() {}
}
}
The simplest thinkable COM client in VBScript does this:
Dim ci
Set ci = WScript.CreateObject("Test.CComInterface")
Dim foo
Set foo = ci.CreateFoo
foo.Bar
ci.UseFoo 0, foo
While the call to Bar succeeds, calling UseFoo fails with "Error 5: invalid procedure call or invalid argument"
The generated IDL seems ok to me:
dispinterface IComInterface {
properties:
methods:
[id(0x60020003)]
IFoo* CreateFoo();
[id(0x60020004)]
void UseFoo(
[in] long x,
[in] IFoo* f);
};
The vbs call succeeds when I wrap the second parameter in parentheses like this:
ci.UseFoo 0, (foo)
As far as I understand (I'm no VBScript expert however) this forces the reference to foo to be passed by value, i.e. a copy of the reference is being made.
How can I change the interface so that it can be called with the foo reference directly? Since this will be a public interface used by customers I don't like the idea of having to explain why all the objects created need to be passed back in an extra pair of parentheses...
Hello,
I have a model with nested attributes :
class Foo < ActiveRecord::Base
has_many :bar
accepts_nested_attributes_for :bar
end
It works fine. However I'd want to be sure that for every Foo, I have at least two Bar.
I can't access the bar_attributes in my validations so it seems I can't validate it.
Is there any clean way to do so ?
I have a class Foo which has_many Bars. Foo has an attribute, some_id. I want to Retrieve all Bar instances where the Foo has some_id = N. In SQL this translates into something like:
select * from bar inner join foo on foo.id = bar.foo_id WHERE foo.some_id = N
The default output of File.toURL() is
file:/c:/foo/bar
These don't appear to work on windows, and need to be changed to
file:///c:/foo/bar
Does the format
file:/c:/foo/bar
work correctly on Unix (I don't have a Unix machine to test on)? Is there a library that can take care of generating a URL from a File that is in the correct format for the current environment?
Can you help me adjust this code so it manages to parse the XML? If I drop the XML namespace it works:
String webXmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<foo xmlns=\"http://foo.bar/boo\"><bar>baz</bar></foo>";
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
org.w3c.dom.Document doc = builder.parse(new StringInputStream(webXmlContent));
NamespaceContextImpl namespaceContext = new NamespaceContextImpl();
namespaceContext.startPrefixMapping("foo", "http://www.w3.org/2001/XMLSchema-instance");
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(namespaceContext);
XPathExpression expr = xpath.compile("/foo/bar");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
System.out.println("Got " + nodes.getLength() + " nodes");
Suppose I have
val foo : Seq[Double] = ...
val bar : Seq[Double] = ...
and I wish to produce a seq where the baz(i) = foo(i) + bar(i). One way I can think of to do this is
val baz : Seq[Double] = (foo.toList zip bar.toList) map ((f: Double, b : Double) => f+b)
However, this feels both ugly and inefficient -- I have to convert both seqs to lists (which explodes with lazy lists), create this temporary list of tuples, only to map over it and let it be GCed. Maybe streams solve the lazy problem, but in any case, this feels like unnecessarily ugly. In lisp, the map function would map over multiple sequences. I would write
(mapcar (lambda (f b) (+ f b)) foo bar)
And no temporary lists would get created anywhere. Is there a map-over-multiple-lists function in Scala, or is zip combined with destructuring really the 'right' way to do this?
A note - the classes I have are EntityObject classes!
I have the following class:
public class Foo
{
public Bar Bar { get; set; }
}
public class Bar : IDataErrorInfo
{
public string Name { get; set; }
#region IDataErrorInfo Members
string IDataErrorInfo.Error
{
get { return null; }
}
string IDataErrorInfo.this[string columnName]
{
get
{
if (columnName == "Name")
{
return "Hello error!";
}
Console.WriteLine("Validate: " + columnName);
return null;
}
}
#endregion
}
XAML goes as follows:
<StackPanel Orientation="Horizontal" DataContext="{Binding Foo.Bar}">
<TextBox Text="{Binding Path=Name, ValidatesOnDataErrors=true}"/>
</StackPanel>
I put a breakpoint and a Console.Writeline on the validation there - I get no breaks. The validation is not executed. Can anybody just press me against the place where my error lies?
Hi,
In Java, on a text like foo <on> bar </on> thing <on> again</on> now, I should want a regex with groups wich give me with a find "foo", "bar", empty string, then "thing", "again", "now".
If I do (.*?)<on>(.*?)</on>(?!<on>), I get only two group (foo bar, thing again, and I've not the end "now").
if I do (.*?)<on>(.*?)</on>((?!<on>)) I get foo bar empty string, then thing again and empty string (here I should want "now").
Please what is the magical formula ?
Thanks.
I have a Perl module and I'd like to be able to pick out the parameters that my my module's user passed in the "use" call. Whichever ones I don't recognize I'd like to pass on. I tried to do this by overriding the "import" method but I'm not having much luck.
EDIT:
To clarify, as it is, I can use my module like this:
use MyModule qw/foo bar/;
which will import the foo and bar methods of MyModule. But I want to be able to say:
use MyModule qw/foo doSpecialStuff bar/;
and look for doSpecialStuff to check if I need to do some special stuff at the beginning of the program, then pass qw/foo bar/ to the Exporter's import
Hi there,
I am looking for an alternative to using an object/variable in global scope -- I would like to associate key/value pairs with specific DOM elements (eg, a DIV), so that I can use them as input for logic that processes other elements (eg, child elements of said DIV).
I tried something naive like: $('[foo=bar]').key='value' , and $('[foo=bar]')[key]='value', but it puked.
Doing something like: var foobar = $('[foo=bar]'); foobar.key = 'value' -- works, but the new property/value only affects the new object (ie, foobar, not $('[foo=bar]'))
Most likely there's something terribly basic I am overlooking. Any help is appreciated, thanks!
I've inherited an older database that was setup with a "on update CURRENT_TIMESTAMP" put on a field that should only describe an item's creation. With PHP I have been using "timestamp=timestamp" on UPDATE clauses, but in SQLAlchemy I can't seem to force the system to use the set timestamp.
Do I have no choice and need to update the MySQL table (millions of rows)?
foo = session.query(f).get(int(1))
ts = foo.timestamp
setattr(foo, 'timestamp', ts)
setattr(foo, 'bar', bar)
www_model.www_Session.commit()
I have also tried:
foo = session.query(f).get(int(1))
setattr(foo, 'timestamp', foo.timestamp)
setattr(foo, 'bar', bar)
www_model.www_Session.commit()
I'm using minitest in Rails to do testing, but I'm running into a problem that I hope a more seasoned tester can help me out with because I've tried looking everywhere for the answer, but it doesn't seem that anyone has run into this problem or if they have, they opted for an integration test.
Let's say I have a controller called Foo and action in it called bar. So the foo_controller.rb file looks like this:
class FooController < ApplicationController
def bar
render 'bar', :layout => 'application'
end
end
The thing is that I don't want people to access the "foo/bar" route directly. So I have a route that is get 'baz' => 'foo#bar'.
Now I want to test the FooController:
require 'minitest_helper'
class FooControllerTest < ActionController::TestCase
def test_should_get_index
get '/baz'
end
end
But the test results in an error that No route matches {:controller=>"foo", :action=>"/baz"}. How do I specify the controller for the GET request?
Sorry if this is a dumb question. It's been very hard for me to find the answer.
Why when I try to access a variable that don't exist, javascript throw an exception but when I try to access a property that don't exist in an object, javascript returns an undefined object?
For example, this case returns an undefined object:
function Foo(){
console.log(this.bar);
}
Foo();
But, in this other example, javascript throw an exception:
function Foo(){
console.log(bar);
}
Foo();
ReferenceError: bar is not defined
I am trying to figure out how FRIEND_TEST works in Google Tests.
http://code.google.com/p/googletest/wiki/AdvancedGuide#Private_Class_Members
I am looking at the following item, trying to implement it in my code:
// foo.h
#include "gtest/gtest_prod.h"
// Defines FRIEND_TEST.
class Foo {
...
private:
FRIEND_TEST(FooTest, BarReturnsZeroOnNull);
int Bar(void* x);
};
// foo_test.cc
...
TEST(FooTest, BarReturnsZeroOnNull) {
Foo foo;
EXPECT_EQ(0, foo.Bar(NULL));
// Uses Foo's private member Bar().
}
In the code above, the piece that I can't see, is that foo_test.cc must include foo.h, in order to have access to Foo and Bar(). [Perhaps it works differently for Google ? in my code, I must include it]
That will result in circular dependency...
Am I missing something ?
I'll try to be more descriptive here.
A Few Q's:
using:
var foo = new Foo() { Bar = new Bar() { Value = "Value" } };
var value = DataBinder.Eval(foo, "Bar.Value");
Or: This one
It is possible to retrieve an internal nested property using property path syntax. Is there a way to set/trigger a nested property (a regular property not DependencyProperty) easily with some kind of simple mechanisms as described here?
I want to acheive something like:
string newValue = "Hello World!";
DataBinder.EvalSet(foo, "Bar.Value", NewValue);
Is there any mechanism that support both property path (for nested objects) and XPATHs (if the objects are XPATH navigable of course) ?
again, that supports get and set options.
Thanks,
DD
I need a CSS selector that can find the 2nd div of 2 that has the same class. I've looked at nth-child() but it's not what I want since I can't see a way to further clarify what class I want. These 2 divs will be siblings in the document if that helps.
My HTML looks something like this:
<div class="foo">...</div>
<div class="bar">...</div>
<div class="baz">...</div>
<div class="bar">...</div>
And I want the 2nd div.bar (or the last div.bar would work too).
What is the syntax for the hash value for a Perl object member subroutine reference in a dispatch table?
use lib Alpha;
my $foo = new Alpha::Foo;
$foo->bar();
my %disp_table = ( bar => ??? );
I want ??? to be the code reference for $foo->bar().
I would like to write a binary image of a structure array to a binary file. I have tried this so far:
#include <stdio.h>
#include <string.h>
#define NUM 256
const char *fname="binary.bin";
typedef struct foo_s {
int intA;
int intB;
char string[20];
}foo_t;
void main (void)
{
foo_t bar[NUM];
bar[0].intA = 10;
bar[0].intB = 999;
strcpy(bar[0].string,"Hello World!");
Save(bar);
printf("%s written succesfully!\n",fname);
}
int Save(foo_t* pData)
{
FILE *pFile;
int ptr = 0;
int itr = 0;
pFile = fopen(fname, "w");
if (pFile == NULL) {
printf("couldn't open %s\n", fname);
return;
}
for (itr = 0; itr<NUM; itr++) {
for (ptr=0; ptr<sizeof(foo_t); ptr++)
{
fputc((unsigned char)*((&pData[itr])+ptr), pFile);
}
fclose(pFile);
}
}
but the compiler is saying aggregate value used where an integer was expected
fputc((unsigned char)*((&pData[itr])+ptr), pFile); and I don't quite understand why, what am I doing wrong?
Thanks!
I want to fetch the id of a one-to-one relationship without loading the entire object. I thought I could do this using lazy loading as follows:
class Foo {
@OneToOne(fetch = FetchType.LAZY, optional = false)
private Bar bar;
}
Foo f = session.get(Foo.class, fooId); // Hibernate fetches Foo
f.getBar(); // Hibernate fetches full Bar object
f.getBar().getId(); // No further fetch, returns id
I want f.getBar() to not trigger another fetch. I want hibernate to give me a proxy object that allows me to call .getId() without actually fetching the Bar object.
What am I doing wrong?
I am trying to do the following:
public class foo<T> where T : bar, new
{
_t = new T();
private T _t;
}
public abstract class bar
{
public abstract void someMethod();
// Some implementation
}
public class baz : bar
{
public overide someMethod(){//Implementation}
}
And I am attempting to use it as follows:
foo<baz> fooObject = new foo<baz>();
And I get an error explaining that 'T' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method. I fully understand why this must be, and also understand that I could pass a pre-initialized object of type 'T' in as a constructor argument to avoid having to 'new' it, but is there any way around this? any way to enforce classes that derive from 'bar' to supply parameterless constructors?
Hello,
In some Python unit tests of a program I'm working on we use in-memory zipfiles for end to end tests. In SetUp() we create a simple zip file, but in some tests we want to overwrite some archives. For this we do "zip.writestr(archive_name, zip.read(archive_name) + new_content)". Something like
import zipfile
from StringIO import StringIO
def Foo():
zfile = StringIO()
zip = zipfile.ZipFile(zfile, 'a')
zip.writestr(
"foo",
"foo content")
zip.writestr(
"bar",
"bar content")
zip.writestr(
"foo",
zip.read("foo") +
"some more foo content")
print zip.read("bar")
Foo()
The problem is that this works fine in Python 2.4 and 2.5, but not 2.6. In Python 2.6 this fails on the print line with "BadZipfile: File name in directory "bar" and header "foo" differ."
It seems that it is reading the correct file bar, but that it thinks it should be reading foo instead.
I'm at a loss. What am I doing wrong? Is this not supported? I tried searching the web but could find no mention of similar problems. I read the zipfile documentation, but could not find anything (that I thought was) relevant, especially since I'm calling read() with the filename string.
Any ideas?
Thank you in advance!
Hi,
I am working with a generic data structure, say MyGeneric<Type>.
There is a case where I have to iterate over all the values it holds
The code I am trying to do.
for ( all the keys in myGeneric ) {
// do lot of stuff here
}
Now the generic can hold base type as double and string and it can hold some user-defined type also.
There is a particular situation where I have to some specific work depending upon the type of the generic.
so the final code block looks something like this
for( all the keys in myGeneric ) {
if key is type foo then
//do foo foo
else if key is of type bar
//do bar bar
}
Now, as complexity sensitive as I am I do not like to have an if condition in the for loop.
So the next solution I did was
if myGeneric is of type foo
call fooIterator(myGeneric)
if myGenric is of type bar
call barItetrator(myGeneric)
function FooIterator() {
// .....
// foo work
//......
}
function BarItetrator() {
// .....
// bar work
//......
}
Then again when somebody sees my code then I am quite sure that they will shout where is the "refactoring".
What is the ideal thing to do in this situation ?
Thanks.