多平台统一管理软件接口,如何实现多平台统一管理软件接口
226
2023-05-12
自定义的Troop<T>泛型类( c++, java和c#)的实现代码
Troop
//for more information, please access http://one-lab.net
using System;
using System.Collections.Generic;
using System.Text;
namespace onelab
{
public interface ISortable
{
void sort(bool decending);
}
public interface IStringable
{
int fromString(String input);
String toString();
}
public class Troop
{
public override int GetHashCode()
{
return base.GetHashCode();
}
public override bool Equals(object obj) { return this == (Troop
public object Clone()
{
Troop
oValue.cloneFrom(this);
return oValue;
}
protected bool equalsTo(Troop
{
int len = aValue.length();
if (len == this.length())
{
for (int n = 0; n < len; n++)
{
if (!aValue.data[n].Equals(data[n]))
return false;
}
return true;
}
return false;
}
protected void cloneFrom(Troop
{
data.Clear();
data.AddRange(aValue.data);
}
public static bool operator ==(Troop
public static bool operator !=(Troop
private bool mHasError = false;
public bool hasError() { return mHasError; }
public List
public T get(int index)
{
mHasError = false;
if (index >= 0 && index < data.Count)
return data[index];
mHasError = true;
return default(T);
}
public bool set(int index, T value)
{
if (index >= 0 && index < data.Count)
{
data[index] = value;
return true;
}
return false;
}
public void ahttp://ppend(T value)
{
data.Add(value);
}
public bool insert(int index, T value)
{
if (index >= 0 && index < data.Count)
{
data.Insert(index, value);
return true;
}
return false;
}
public void appendRange(ref List
{
data.AddRange(range);
}
public bool insertRange(int index, ref List
{
if (index >= 0 && index < data.Count)
{
data.InsertRange(index, range);
return true;
}
return false;
}
public void clear()
{
data.Clear();
}
public bool remove(int index)
{
if (index >= 0 && index < data.Count)
{
data.RemoveAt(index);
return true;
}
return false;
}
public bool removeRange(int index, int count)
{
if (count > 0 && index >= 0 && ((index + count) <= data.Count))
{
data.RemoveRange(index, count);
return true;
}
return false;
}
public int length()
{
return data.Count;
}
public void enqueue(T value)
{
data.Insert(0, value);
}
public T dequeue()
{
mHasError = false;
int length = data.Count;
if (length > 0)
{
T b = data[length - 1];
data.RemoveAt(length - 1);
return b;
}
mHasError = true;
return default(T);
}
public void push(T value)
{
data.Add(value);
}
public T pop()
{
NcEusQiTdreturn dequeue();
}
public Troop
{
Troop
mHasError = true;
if (count > 0 && index >= 0 && ((index + count) <= data.Count))
{
output.data = data.GetRange(index, count);
mHasError = false;
}
return output;
}
public void reverse()
{
data.Reverse();
}
public bool swap(int index0, int index1)
{
int length = data.Count;
if (index0 >= 0 && index0 < length && index1 >= 0 && index1 < length)
{
T v = data[index0];
data[index0] = data[index1];
data[index1] = v;
return true;
}
return false;
}
public T take(int index)
{
mHasError = false;
if (index >= 0 && index < data.Count)
{
T v = data[index];
data.RemoveAt(index);
return v;
}
mHasError = true;
return default(T);
}
public void rollForward(int offset)
{
if (offset >= data.Count) return;
List
List
data.Clear();
data.AddRange(left);
data.AddRange(right);
}
public void rollBackward(int offset)
{
if (offset >= data.Count) return;
List
List
data.Clear();
data.AddRange(left);
data.AddRange(right);
}
}
}
//for more information, please access http://one-lab.net
#ifndef VALUES_H
#define VALUES_H
#include
#include
namespace onelab
{
class ISortable
{
public:
virtual void sort(bool decending) = 0;
};
template <NcEusQiTd;typename T>
class Troop
{
private:
bool mHasError;
static bool equals(const Troop
public:
QList
Troop();
T get(int index);
bool set(int index, T value);
void append(T value);
bool insert(int index, T value);
void appendRange(const QList
bool insertRange(int index, const QList
void clear();
bool remove(int index);
bool removeRange(int index, int count);
int length() const;
void enqueue(T value);
T dequeue();
void push(T value);
T pop();
bool getRange(int index, int count, Troop
void reverse();
bool swap(int index0, int index1);
T take(int index);
void rollForward(int offset);
void rollBackward(int offset);
bool operator==(const Troop& input) const;
bool operator!=(const Troop& input) const;
bool hasError() const;
virtual QString toString();
virtual int fromString(const QString& input);
};
}
#endif // VALUES_H
//for more information, please access http://one-lab.net
#include "values.h"
#include
#include
namespace onelab
{
template
bool Troop
{
int len = from.length();
if (len == to.length())
{
for (int n = 0; n < len; n++)
{
if (from.data[n] != to.data[n])
return false;
}
return true;
}
return false;
}
template
Troop
{
mHasError = false;
}
template
T Troop
{
mHasError = false;
if (index >= 0 && index < data.length())
return data[index];
mHasError = true;
return (T)0;
}
template
bool Troop
{
if (index >= 0 && index < data.length())
{
data[index] = value;
return true;
}
return false;
}
template
void Troop
{
data.append(value);
}
template
bool Troop
{
if (index >= 0 && index < data.length())
{
data.insert(index, value);
return true;
}
return false;
}
template
void Troop
{
data.append(range);
}
template
bool Troop
{
int length = data.length();
if (index >= 0 && index < length)
{
QList
QList
left.append(range);
data.clear();
data.append(left);
data.append(right);
return true;
}
return false;
}
template
void Troop
{
data.clear();
}
template
bool Troop
{
if (index >= 0 && index < data.length())
{
data.removeAt(index);
return true;
}
return false;
}
template
bool Troop
{
if (count > 0 && index >= 0 && ((index + count) <= data.length()))
{
for (int n = 0; n < count; n++)
data.removeAt(index);
return true;
}
return false;
}
template
int Troop
{
return data.length();
}
template
void Troop
{
data.insert(0, value);
}
template
T Troop
{
mHasError = false;
int length = data.length();
if (length > 0)
{
T b = data[length - 1];
data.removeAt(length - 1);
return b;
}
mHasError = true;
return (T)0;
}
template
void Troop
{
data.append(value);
}
template
T Troop
{
return dequeue();
}
template
bool Troop
{
mHasError = true;
if (count > 0 && index >= 0 && ((index + count) <= data.length()))
{
output.data = data.mid(index, count);
mHasError = false;
}
return mHasError;
}
template
void Troop
{
int length = data.length();
QList
for (int n = length - 1; n >= 0; n--)
newData.append(data[n]);
data.clear();
data = newData;
}
template
bool Troop
{
int length = data.length();
if (index0 >= 0 && index0 < length && index1 >= 0 && index1 < length)
{
T v = data[index0];
data[index0] = data[index1];
data[index1] = v;
return true;
}
return false;
}
template
T Troop
{
mHasError = false;
if (index >= 0 && index < data.length())
{
T v = data[index];
data.removeAt(index);
return v;
}
mHasError = true;
return (T)0;
}
template
void Troop
{
if (offset >= data.length()) return;
QList
QList
data.clear();
data.append(left);
data.append(right);
}
template
void Troop
{
if (offset >= data.length()) return;
QList
QList
data.clear();
data.append(left);
data.append(right);
}
template
bool Troop
{
return !equals(input, *this);
}
template
bool Troop
{
return mHasError;
}
template
QString Troop
{
return QString();
}
template
int Troop
{
return 0;
}
template
bool Troop
{
return equals(input, *this);
}
}
//for more information, please access http://one-lab.net
package net.onelab;
import java.util.ArrayList;
public class Troop
public Object clone() {
Troop
obj.data.addAll(data);
return obj;
}
private boolean mHasError = false;
public boolean hasError() { return mHasError; }
public ArrayList
public T get(int index) {
mHasError = false;
if (index >= 0 && index < data.size())
return data.get(index);
mHasError = true;
return null;
}
public boolean set(int index, T value) {
if (index >= 0 && index < data.size())
{
data.set(index, value);
return true;
}
return false;
}
public void append(T value) {
data.add(value);
}
public boolean insert(int index, T value) {
if (index >= 0 && index < data.size())
{
data.add(index, value);
return true;
}
return false;
}
public void appendRange(ArrayList
data.addAll(range);
}
public boolean insertRange(int index, ArrayList
if (index >= 0 && index < data.size())
{
data.addAll(index, range);
return true;
}
return false;
}
public void clear() {
data.clear();
}
public boolean remove(int index) {
if (index >= 0 && index < data.size())
{
data.remove(index);
return true;
}
return false;
}
public boolean removeRange(int index, int count) {
if (count > 0 && index >= 0 && ((index + count) <= data.size()))
{
for (int n = 0; n < count; n++)
data.remove(index);
return true;
}
return false;
}
public int length() {
return data.size();
}
public void enqueue(T value) {
data.add(0, value);
}
public T dequeue() {
mHasError = false;
int length = data.size();
if (length > 0)
{
T b = data.get(length - 1);
data.remove(length - 1);
return b;
}
mHasError = true;
return null;
}
public void push(T value) {
data.add(value);
}
public T pop() {
return dequeue();
}
public Troop
mHasError = true;
Troop
if (count > 0 && index >= 0 && ((index + count) <= data.size()))
{
output.data.addAll(data.subList(index, index + count));
mHasError = false;
}
return output;
}
public void reverse() {
int length = data.size();
ArrayList
for (int n = length - 1; n >= 0; n--)
newData.add(data.get(n));
data.clear();
data = newData;
}
boolean swap(int index0, int index1) {
int length = data.size();
if (index0 >= 0 && index0 < length && index1 >= 0 && index1 < length)
{
T v = data.get(index0);
data.set(index0, data.get(index1));
data.set(index1, v);
return true;
}
return false;
}
T take(int index)
{
mHasError = false;
if (index >= 0 && index < data.size())
{
T v = data.get(index);
data.remove(index);
return v;
}
mHasError = true;
return null;
}
void rollForward(int offset)
{
if (offset >= data.size()) return;
ArrayList
left.addAll(data.subList(offset - 1, data.size()));
ArrayList
right.addAll(data.subList(0, offset - 1));
data.clear();
data.addAll(left);
data.addAll(right);
}
void rollBackward(int offset)
{
if (offset >= data.size()) return;
ArrayList
left.addAll(data.subList(offset, data.size()));
ArrayList
right.addAll(data.subList(0, offset));
data.clear();
data.addAll(left);
data.addAll(right);
}
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~