小编gny*_*his的帖子

如何从包裹中正确读取可序列化文件?

我在Parcelable对象中有一个可序列化的对象(ArrayList)。我正在尝试读取可序列化的对象,但在读取后无法弄清楚如何精确地重建它:

public class WifiAP implements Parcelable {

public String _mac;
public String _mac2;
public String _ssid;
public boolean _dualband;
public int _band;  // kilohertz
public int _band2;
ArrayList<Integer> _rssis;

public Packet _beacon;

public void writeToParcel(Parcel out, int flags) {
    out.writeString(_mac);
    out.writeString(_mac2);
    out.writeString(_ssid);

    if(_dualband)
        out.writeInt(1);
    else
        out.writeInt(0);

    out.writeInt(_band);
    out.writeInt(_band2);
    out.writeSerializable(_rssis);
}

private WifiAP(Parcel in) {
    _mac = in.readString();
    _mac2 = in.readString();
    _ssid = in.readString();

    if(in.readInt()==1)
        _dualband=true;
    else
        _dualband=false;

    _band = in.readInt();
    _band2 = in.readInt();
    _rssis = in.readSerializable(); // help here, this …
Run Code Online (Sandbox Code Playgroud)

java serialization parcelable

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

无法超载虚拟功能

我有一个Network类,我想要两个虚拟函数,我将要重载:airtime()airtime(std::vector<int> freq_bins);

我定义了类,以及底部的函数:

class Network
{
  public:

    // Properties of the network protocol
    std::string _name;
    std::vector<float> _channels;
    float _bandwidth;
    float _txtime;

    // Properties of the specific network
    int _id;
    macs::mac_t _mac;
    protocols::protocol_t _protocol;
    bool _static;
    float _desired_airtime;
    float _act_airtime;
    bool _active;

    // Constructor
    Network();
    virtual float airtime() { };
    virtual float airtime(std::vector<int> freq_bins) { };
};
Run Code Online (Sandbox Code Playgroud)

现在,我有一个我想要重载它们的第二个类.这是这个类的标题:

#ifndef _CSMA_H_ 
#define _CSMA_H_ 

#include <string> 
#include <vector> 
#include <map> 
#include "MACs.h" 
#include "Protocols.h" 
#include "Network.h" 

class CSMA : …
Run Code Online (Sandbox Code Playgroud)

c++ virtual overloading

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

查询返回匿名类型列表,而不是列表值

我正在使用LINQ执行自定义查询,它根据我的语句返回一个匿名类型列表:

            var currUnitFaster = (from unit in pacificRepo.Units
                                 join loc in pacificRepo.GeoLocations on new { unit.geo_location.Latitude, unit.geo_location.Longitude } equals new { loc.geo_location.Latitude, loc.geo_location.Longitude }
                                 join st in pacificRepo.UnitStatuses on unit.c_number equals st.c_number
                                 select new { 
                                    index = "0", 
                                    unit.c_number, 
                                    unit.serial_number, 
                                    unused = "0", 
                                    unit.ip_address, 
                                    unit.build_version,
                                    status = (st.status == Pacific.Domain.Entities.UnitStatus.Statuses.COMPLETE) ? "<font color=\"green\">" + st.stage + "</font>" : "<font color=\"red\">" + st.stage + "</font>", 
                                    location = (loc==null) ? "Unknown" : loc.city + ", " + loc.state_abbrv,
                                    unit.location_at_address,
                                    latitude = unit.geo_location.Latitude, …
Run Code Online (Sandbox Code Playgroud)

.net c# linq asp.net

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

加快这个matlab代码?

有没有一种很好的方法n可以使用矩阵运算加速这个matlab代码块(特别是可能很大)?超过1/4的执行时间是在这个小代码块中.

% Get the bin indexes that we will place the network in
bins = [];
for n=low_freq:0.5:high_freq;
    bins = [bins, (n-spec_start)/spec_bin_size+1];
end
Run Code Online (Sandbox Code Playgroud)

测试代码:

spec_start=2400
spec_bin_size=0.5
low_freq = 2437
high_freq=2438

bins = [];
for n=low_freq:0.5:high_freq;
    bins = [bins, (n-spec_start)/spec_bin_size+1];
end

bins  % 75 76 77

bins = [];
bins = (low_freq:0.5:high_freq - spec_start)./spec_bin_size + 1;

bins  % empty?
Run Code Online (Sandbox Code Playgroud)

optimization performance matlab

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

无法在C++中为指针向量创建自定义排序

我试图通过使用排序谓词为类指针向量创建自定义排序:

struct sort_by_airtime                                                                                            
{                                                                                                                 
    inline bool operator() (const Network *n1, const Network *n2)                                                 
    {                                                                                                             
      return (n1->airtime() < n2->airtime());                                                                     
    }                                                                                                             
};      
Run Code Online (Sandbox Code Playgroud)

对于每个网络,我们按airtime()返回的float进行排序.

现在,我尝试使用如下:

std::vector<Network *> Simulator::sort_networks(std::vector<Network *> netlist, bool sort_airtime) {

  std::vector<Network *> new_netlist = netlist;

  if(sort_airtime) {
    sort(new_netlist.begin(), new_netlist.end(), sort_by_airtime());
  }

}
Run Code Online (Sandbox Code Playgroud)

但是,我得到了很多这样的错误:

In file included from Simulator.cpp:7:
Simulator.h: In member function ‘bool Simulator::sort_by_airtime::operator()(const Network*, const Network*)’:
Simulator.h:48: error: passing ‘const Network’ as ‘this’ argument of ‘virtual float Network::airtime()’ discards qualifiers
Simulator.h:48: error: passing ‘const Network’ as ‘this’ argument of …
Run Code Online (Sandbox Code Playgroud)

c++ sorting vector

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

正则表达式中的误解群体,这可能吗?

我认为我误解了小组如何在正则表达式和C#中工作.但是,我仍然想知道我想要的是否可能.

我们采取以下字符串

:::name(uploadFileName)
Run Code Online (Sandbox Code Playgroud)

哪个与表达式匹配

\A:::[a-zA-Z0-9_-]+\([a-zA-Z0-9_-]+\)
Run Code Online (Sandbox Code Playgroud)

我希望能够做的就是方便地提取出来像什么property = name,然后value = uploadFileName.

我认为,这将与组,其中发生match.Groups[0].Valuenamematch.Groups[1].ValueuploadFileName.根据群体的定义,我认为这是真的:

分组构造描述正则表达式的子表达式并捕获输入字符串的子字符串.

但是,match.Groups[0].Value简直就是整个字符串:::name(uploadFileName)

c# regex

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