问题列表 - 第7791页

cmpxchg 64位整数的示例

我在i686架构中使用cmpxchg(比较和交换)进行32位比较和交换,如下所示.

(编者注:最初的32位示例是错误的,但问题不在于它.我相信这个版本是安全的,并且作为奖励也可以正确编译x86-64. 另请注意,内联asm不是需要或建议在此; __atomic_compare_exchange_n或旧的__sync_bool_compare_and_swap工作int32_tint64_t上的i486和x86-64但这个问题是关于与联汇编这样做,如果你仍然想).

// note that this function doesn't return the updated oldVal
static int CAS(int *ptr, int oldVal, int newVal)
{
    unsigned char ret;
    __asm__ __volatile__ (
            "  lock\n"
            "  cmpxchgl %[newval], %[mem]\n"
            "  sete %0\n"
            : "=q" (ret), [mem] "+m" (*ptr), "+a" (oldVal)
            : [newval]"r" (newVal)
            : "memory");    // barrier for compiler reordering around this

    return ret;   // ZF result, 1 on success else 0
}
Run Code Online (Sandbox Code Playgroud)

对于64位比较和交换,x86_64架构的等价物是什么

static int …
Run Code Online (Sandbox Code Playgroud)

assembly gcc x86-64 inline-assembly

5
推荐指数
1
解决办法
9730
查看次数

查找模块中可用的类

我有一个模块MyModule.我动态地将类加载到其中.如何获取其命名空间中定义的类的列表?

例:

def load_plugins
  Dir.glob(File.dirname(__FILE__) + '/plugins/*.rb') do |f|
    MyModule.class_eval File.read(f)
  end

  # now how can I find the new classes I've loaded into MyModule?
end
Run Code Online (Sandbox Code Playgroud)

我应该说每个都f包含类似"类Foo;结束"的内容.

您也可以这样想:在Rails中,我如何以编程方式查找ActiveRecord模块中定义的所有类?

ruby metaprogramming

70
推荐指数
1
解决办法
3万
查看次数

ms sql中脚本DB对象的免费实用程序

我正在尝试实现数据库源代码控制.

我需要的工具应该为数据库中的每个对象创建一个单独的文件,最好安排在文件夹中,如

存储过程函数视图表

如果能够转储某些查询的结果,以便跟踪几个配置表中的数据更改,那将会很棒...

我想知道是否已经有一种可以处理这种东西的工具......

-

只是为了清除一些事情......

我已经在使用sql delta来处理更新脚本......

我想拥有数据库的脚本以便与subversion一起使用,因此我可以跟踪每次提交时更改的对象,而无需研究更新脚本......

我正在使用SQL分布式管理对象(SQL-DMO)开发一个不错的vb脚本,我将告诉它如何...

有我自己的解决方案的好处是,我还可以包括查询或存储过程执行的输出,跟踪某些表中的更改,服务器配置,数据库的增长,以及我可以转储到文本文件的任何内容...

svn sql-server version-control

6
推荐指数
1
解决办法
1753
查看次数

屏幕坐标到纬度和经度

在开放图层库中,下面是用于将屏幕坐标转换为经纬度的方法。我无法弄清楚此方法封装的逻辑?

getLatLonFromPoint: function (point) {
    var center = this.getCenter();
    //map center lat/lon
    var res  = this.getResolution(); 
    //pre defined by the user. Represents the change in lat long per screen unit at the given zoom level
    var size = this.getSize(); 
    //this is the width and height of the div in which the map has to be displayed
    var delta_x = point.x - (size.w / 2);
    var delta_y = point.y - (size.h / 2);
    return new OpenLayers.LatLon(
        center.lat - delta_y * res, …

gis latitude-longitude openlayers

1
推荐指数
1
解决办法
5263
查看次数

如何使用DataTrigger覆盖绑定属性

我有以下XAML用于显示有关在列表视图中选择的项目的详细信息.我希望矩形显示文本后面的标准信息颜色,除非所选项目表示错误消息.下面的代码不能正常工作,并始终显示信息颜色.如果我没有Fill为根<Rectangle />元素指定a ,它的效果很好.

<Rectangle Fill="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" 
           RadiusX="4" RadiusY="4">
  <Rectangle.Style>
    <Style TargetType="{x:Type Rectangle}">
      <Style.Triggers>
        <DataTrigger Binding="{Binding Path=CurrentMessage.Severity"  
                     Value="Error" >
          <Setter Property="Fill" Value="#20FF0000" />
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </Rectangle.Style>
</Rectangle>
Run Code Online (Sandbox Code Playgroud)

该代码段并未反映它,但实际代码对于Severity具有相当多的可能状态级别,因此我不想为每种可能的严重性定义触发器.我想要的逻辑是"使用信息颜色,除非严重性是错误,然后使用红色".

我确信我误解了WPF的一些基本方面,但似乎无法确定它.有人能指出我正确的方向,以便我指定的数据触发器在条件为真时覆盖现有的Fill值吗?

.net wpf xaml binding datatrigger

8
推荐指数
1
解决办法
1899
查看次数

asp.net mvc中的整数验证

我正在使用服务器端验证

 public IEnumerable<RuleViolation> GetRuleViolations()
    {
        if (String.IsNullOrEmpty(Name))
            yield return new RuleViolation("Name is Required", "Name");
        if (Price == 0)
            yield return new RuleViolation("Price is Required", "Price");
        yield break;
    }
Run Code Online (Sandbox Code Playgroud)

当我将Price保留为空白时,则将0作为值.

所以我用0检查它.

在我的数据库中价格不能为空; 我正在使用LINQ-to-SQL类.

现在我的问题是,当我把价格留空时,它给了我两条消息

  • 需要一个数值.
  • 价格是必需的.

那么如何在不显示第一条错误消息的情况下进行自定义验证

Relpy to comment 我在这里提供Professional Asp.net MVC 1.0的书籍代码.

Book的HTML页面就在这里.

有用的页面.

public class RuleViolation
    {
        public string ErrorMessage { get; private set; }
        public string PropertyName { get; private set; }

        public RuleViolation(string errorMessage)
        {
            ErrorMessage = errorMessage;
        }

        public …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

1
推荐指数
1
解决办法
2333
查看次数

NHibernate SQL创建会导致错误

我有2个名为Order和Orderrow的类.我使用NHibernate来获取它的连接.

运行NUnit来测试查询时,我得到了一个ADOException:

Logica.NHibernate.Tests.NHibernateTest.SelectAllOrdersFromSupplierNamedKnorrTest:
NHibernate.ADOException : could not execute query
[ SELECT this_.OrderId as OrderId1_1_, this_.CreatedAt as CreatedAt1_1_, this_.ShippedAt as ShippedAt1_1_, this_.ContactId as ContactId1_1_, customer2_.ContactId as ContactId0_0_, customer2_.LastName as LastName0_0_, customer2_.Initials as Initials0_0_, customer2_.Address as Address0_0_, customer2_.City as City0_0_, customer2_.Country as Country0_0_ FROM Order this_ inner join Contact customer2_ on this_.ContactId=customer2_.ContactId ]
[SQL: SELECT this_.OrderId as OrderId1_1_, this_.CreatedAt as CreatedAt1_1_, this_.ShippedAt as ShippedAt1_1_, this_.ContactId as ContactId1_1_, customer2_.ContactId as ContactId0_0_, customer2_.LastName as LastName0_0_, customer2_.Initials as Initials0_0_, customer2_.Address as Address0_0_, customer2_.City as City0_0_, …
Run Code Online (Sandbox Code Playgroud)

c# nhibernate

4
推荐指数
3
解决办法
6511
查看次数

方便的F#片段

关于F#/功能片段已经存在两个 问题.

然而,我在这里寻找的是有用的片段,可重复使用的小"帮助"功能.或者模糊但又漂亮的模式,你永远不会记得.

就像是:

open System.IO

let rec visitor dir filter= 
    seq { yield! Directory.GetFiles(dir, filter)
          for subdir in Directory.GetDirectories(dir) do 
              yield! visitor subdir filter} 
Run Code Online (Sandbox Code Playgroud)

我想把它作为一个方便的参考页面.因此,没有正确的答案,但希望有很多好的答案.

EDIT Tomas Petricek专门为F#片段创建了一个网站http://fssnip.net/.

f# reference code-snippets

66
推荐指数
15
解决办法
1万
查看次数

为什么这个Haskell代码能够成功地使用无限列表?

我有一些Haskell代码是不会无限名单上正常工作,但我不明白为什么它可以做得很成功.(我修改了我原来的代码 - 没有处理无限列表 - 在网上加入其他代码的东西,突然间我发现它有效,但不知道为什么).

myAny :: (a -> Bool) -> [a] -> Bool
myAny p list = foldr step False list
   where
      step item acc = p item || acc
Run Code Online (Sandbox Code Playgroud)

我对foldr的理解是它将遍历列表中的每个项目(也许这种理解是不完整的).如果是这样,那么"步"函数的表达方式无关紧要......代码应该无法处理无限循环.

但是,以下工作:

*Main Data.List> myAny even [1..]
True
Run Code Online (Sandbox Code Playgroud)

请帮我理解:为什么?

haskell functional-programming infinite fold

32
推荐指数
2
解决办法
2389
查看次数

在Linux/POSIX系统上获取用户全名的最简单方法是什么?

我可以通过/ etc/passwd grep,但这似乎很麻烦.'finger'没有安装,我想避免这种依赖.这是一个程序,所以如果有一些命令让你只是访问用户信息会很好.

database linux shell posix user-accounts

35
推荐指数
6
解决办法
4万
查看次数