blob_id stringlengths 40 40 | directory_id stringlengths 40 40 | path stringlengths 4 201 | content_id stringlengths 40 40 | detected_licenses listlengths 0 85 | license_type stringclasses 2
values | repo_name stringlengths 7 100 | snapshot_id stringlengths 40 40 | revision_id stringlengths 40 40 | branch_name stringclasses 260
values | visit_date timestamp[us] | revision_date timestamp[us] | committer_date timestamp[us] | github_id int64 11.4k 681M ⌀ | star_events_count int64 0 209k | fork_events_count int64 0 110k | gha_license_id stringclasses 17
values | gha_event_created_at timestamp[us] | gha_created_at timestamp[us] | gha_language stringclasses 80
values | src_encoding stringclasses 28
values | language stringclasses 1
value | is_vendor bool 1
class | is_generated bool 2
classes | length_bytes int64 8 9.86M | extension stringclasses 52
values | content stringlengths 8 9.86M | authors listlengths 1 1 | author stringlengths 0 119 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4560ac26dc18c7452b0d8d31b23c72ebd18ff75d | 8514036949180b1432fa8807c1435b320cfdc857 | /src/qt/walletmodel.h | 87a4d58a76f119a3793d9a52ce85ab6a99345f10 | [
"MIT"
] | permissive | msgpo/Rodentcoin | 6a212290748a8f2cace728bcb9799fc6f192c9ea | 5c2d82cd23ec3dc714dd15ba2aaa39d0b4c67914 | refs/heads/master | 2021-05-28T22:38:59.132905 | 2015-03-10T12:56:53 | 2015-03-10T12:56:53 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,637 | h | #ifndef WALLETMODEL_H
#define WALLETMODEL_H
#include <QObject>
#include <vector>
#include <map>
#include "allocators.h" /* for SecureString */
#include "wallet.h"
#include "walletmodeltransaction.h"
class OptionsModel;
class AddressTableModel;
class TransactionTableModel;
class CWallet;
class WalletModelTransaction;
class CKeyID;
class CPubKey;
class COutput;
class COutPoint;
class uint256;
class CCoinControl;
QT_BEGIN_NAMESPACE
class QTimer;
QT_END_NAMESPACE
class SendCoinsRecipient
{
public:
QString address;
QString label;
qint64 amount;
};
/** Interface to Bitcoin wallet from Qt view code. */
class WalletModel : public QObject
{
Q_OBJECT
public:
explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
~WalletModel();
enum StatusCode // Returned by sendCoins
{
OK,
InvalidAmount,
InvalidAddress,
AmountExceedsBalance,
AmountWithFeeExceedsBalance,
DuplicateAddress,
TransactionCreationFailed, // Error returned when wallet is still locked
TransactionCommitFailed,
Aborted
};
enum EncryptionStatus
{
Unencrypted, // !wallet->IsCrypted()
Locked, // wallet->IsCrypted() && wallet->IsLocked()
Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
};
OptionsModel *getOptionsModel();
AddressTableModel *getAddressTableModel();
TransactionTableModel *getTransactionTableModel();
qint64 getBalance(const CCoinControl *coinControl=NULL) const;
qint64 getUnconfirmed() const;
qint64 getImmature() const;
int getNumTransactions() const;
EncryptionStatus getEncryptionStatus() const;
// Check address for validity
bool validateAddress(const QString &address);
// Return status record for SendCoins, contains error id + information
struct SendCoinsReturn
{
SendCoinsReturn(StatusCode status=Aborted) : status(status) {}
StatusCode status;
};
// Prepare a transaction to get a fee estimate
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl *coinControl=NULL);
// Send coins to a list of recipients
SendCoinsReturn sendCoins(WalletModelTransaction &transaction);
// Wallet encryption
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
// Passphrase only needed when unlocking
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
// Wallet backup
bool backupWallet(const QString &filename);
// RAI object for unlocking wallet, returned by requestUnlock()
class UnlockContext
{
public:
UnlockContext(WalletModel *wallet, bool valid, bool relock);
~UnlockContext();
bool isValid() const { return valid; }
// Copy operator and constructor transfer the context
UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
private:
WalletModel *wallet;
bool valid;
mutable bool relock; // mutable, as it can be set to false by copying
void CopyFrom(const UnlockContext& rhs);
};
UnlockContext requestUnlock();
bool getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
void getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs);
void listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const;
bool isLockedCoin(uint256 hash, unsigned int n) const;
void lockCoin(COutPoint& output);
void unlockCoin(COutPoint& output);
void listLockedCoins(std::vector<COutPoint>& vOutpts);
private:
CWallet *wallet;
// Wallet has an options model for wallet-specific options
// (transaction fee, for example)
OptionsModel *optionsModel;
AddressTableModel *addressTableModel;
TransactionTableModel *transactionTableModel;
// Cache some values to be able to detect changes
qint64 cachedBalance;
qint64 cachedUnconfirmed;
qint64 cachedImmature;
qint64 cachedNumTransactions;
EncryptionStatus cachedEncryptionStatus;
int cachedNumBlocks;
QTimer *pollTimer;
void subscribeToCoreSignals();
void unsubscribeFromCoreSignals();
void checkBalanceChanged();
signals:
// Signal that balance in wallet changed
void balanceChanged(qint64 balance, qint64 unconfirmed, qint64 immature);
// Number of transactions in wallet changed
void numTransactionsChanged(int count);
// Encryption status of wallet changed
void encryptionStatusChanged(int status);
// Signal emitted when wallet needs to be unlocked
// It is valid behaviour for listeners to keep the wallet locked after this signal;
// this means that the unlocking failed or was cancelled.
void requireUnlock();
// Asynchronous error notification
void error(const QString &title, const QString &message, bool modal);
public slots:
/* Wallet status might have changed */
void updateStatus();
/* New transaction, or transaction changed status */
void updateTransaction(const QString &hash, int status);
/* New, updated or removed address book entry */
void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
/* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
void pollBalanceChanged();
};
#endif // WALLETMODEL_H
| [
"beetlemon.cwts@gmail.com"
] | beetlemon.cwts@gmail.com |
9b73ab19e2d3ac48c080e6160f1a48fce16d6884 | 4719f083718b2ed75ceb7bf43a9323e1aee55dfa | /csinskf.h | a93a3768aa08deb6ee329055ebabe3a750fc1ba5 | [] | no_license | mfkiwl/GNSS_INS | b4b2df1965fa5d66b34ecf26a3db5e28948b6808 | 38fd7fe84625c2a20ae5f1908d5663d2802fe574 | refs/heads/main | 2023-04-09T20:15:43.741733 | 2021-04-12T14:43:38 | 2021-04-12T14:43:38 | 359,821,901 | 3 | 0 | null | 2021-04-20T13:15:55 | 2021-04-20T13:15:55 | null | UTF-8 | C++ | false | false | 726 | h | #ifndef CSINSKF_H
#define CSINSKF_H
#include <ckalman.h>
#include <csins.h>
class CSINSKF:public CKalman
{
public:
CSINS sins;
CSINSKF(int nq0, int nr0);
virtual void Init(void) {}
virtual void Init(const CSINS &sins0, int grade=-1);
virtual void SetFt(int nnq=15);
virtual void SetHk(int nnq=15);
virtual void Feedback(double fbts);
int Update(const CVect3 *pwm, const CVect3 *pvm, int nSamples, double ts); // KF Time&Meas Update
void QtMarkovGA(const CVect3 &tauG, const CVect3 &sRG, const CVect3 &tauA, const CVect3 &sRA);
virtual void Miscellanous(void) {}
virtual void SecretAttitude(void);
void SetYaw(double yaw);
};
#endif // CSINSKF_H
| [
"noreply@github.com"
] | noreply@github.com |
ed6d16e8de9debf8d2ffa73bfd8350c832453aa4 | 09991cb5cc1deee033abbe3cbd764ea4089d5944 | /07-Recursion/test10.cpp | f631e9ade1295ea1e8e4cea7f6c0a9226d7264b9 | [] | no_license | jcuasnt/Data-Structure | 2aa5cd2005715a992e35621b74cc28df7bd7c569 | 6a25cbad963fd552cb4d68711e7aa40f0803190a | refs/heads/master | 2023-04-25T03:23:05.069614 | 2019-08-27T08:25:39 | 2019-08-27T08:25:39 | null | 0 | 0 | null | null | null | null | UHC | C++ | false | false | 2,197 | cpp | //--------------------------------------------------------------------
//
// Laboratory 10 test10.cpp
//
// Test program for a set of recursive linked list functions
//
//--------------------------------------------------------------------
// Reads a list of characters and calls the specified recursive routine.
#include <iostream>
#include <Windows.h>
#include "listrec.cpp"
using namespace std;
void SetColor(int color) // 글자색 변경
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
void main()
{
List<char> testList; // Test list
char testElement; // List element
cout << endl << "Enter a list of characters : ";
cin.get(testElement);
while (testElement != '\n')
{
testList.insert(testElement);
cin.get(testElement);
}
testList.showStructure();
// ***** Pre-lab : Call a recursive routine by uncommenting the call you wish to execute.
SetColor(10); cout << endl << "[ PART A ] : insertEnd " << endl; SetColor(7);
testList.write();
testList.insertEnd('!');
cout << "Structure : "; testList.showStructure();
SetColor(10); cout << endl << "[ PART B ] : writeMirror " << endl; SetColor(7);
testList.writeMirror();
cout << "Structure : "; testList.showStructure();
SetColor(10); cout << endl << "[ PART C ] : reverse " << endl; SetColor(7);
testList.reverse();
cout << "Structure : "; testList.showStructure();
SetColor(10); cout << endl << "[ PART D ] : deleteEnd" << endl; SetColor(7);
testList.deleteEnd();
cout << "Structure : "; testList.showStructure();
SetColor(10); cout << endl << "[ PART E ] : length " << endl; SetColor(7);
cout << "length = " << testList.length() << endl;
cout << "Structure : "; testList.showStructure();
// ***** In-lab
SetColor(11); cout << endl << "[ PART A ] : iterReverse " << endl; SetColor(7);
testList.iterReverse();
cout << "Structure : "; testList.showStructure();
SetColor(11); cout << endl << "[ PART B ] : stackWriteMirror " << endl; SetColor(7);
testList.stackWriteMirror();
cout << "Structure : "; testList.showStructure();
system("pause");
} | [
"noreply@github.com"
] | noreply@github.com |
3ddc390a924f743e3101f709b1f0b44fc849bf63 | 6af018471e417cb1502058fa39b4ae015ef018c0 | /include/PathPlanning/BoundingBox.hpp | 1be497d8c7ce4cad632e097abe622d5f3c3d5236 | [] | no_license | SZamboni/LabAppliedRobotics | 97cec0f956f07442a1ecd5c3829b0a281504ae3b | 4d91b923510097ce1d66c993921cdd37e7ad1fc9 | refs/heads/master | 2020-04-25T13:06:06.563515 | 2019-10-21T12:30:38 | 2019-10-21T12:30:38 | 172,798,778 | 0 | 1 | null | 2019-02-27T14:29:40 | 2019-02-26T22:11:34 | C++ | UTF-8 | C++ | false | false | 4,580 | hpp | #ifndef __BOUNDING_BOX__
#define __BOUNDING_BOX__
#include "Segment.hpp"
#include "FilledConvexShape.hpp"
/**
* Class that represent a BoundingBox with 4 numbers
*/
class BoundingBox : public FilledConvexShape, public BoundedShape {
private:
float min_x;
float min_y;
float max_x;
float max_y;
public:
/**
* Public empty constructor
*/
BoundingBox();
/**
* Public full constructor
*
* @argument min_x : the smallest x value of the BoundingBox
* @argument min_y : the smallest y value of the BoundingBox
* @argument max_x : the biggest x value of the BoundingBox
* @argument max_y : the biggest y value of the BoundingBox
*/
BoundingBox(float min_x, float min_y, float max_x, float max_y);
/**
* Method that modifies the box to include another box
*
* @argument other: other bounding box to include in this one
**/
void merge(BoundingBox &other);
/**
* Method that multiply every coordinate of the BoundingBox by the input number
*
* @argument scale : the number that will scale the BoundingBox
*/
void resize(float scale) override;
/**
* Function that returns true if the segment collides with the BoundingBox box
*
* @argument seg : the segment
*
* @returns : true if the segment collides the BoundingBox, false otherwise
*/
bool isSegmentColliding(const Segment &seg) const override;
/**
* Function that returns true if the given arc collides with the BoundingBox
*
* @argument center : the center of the circle arc
* @argument radius : the radius of the circle arc
* @argument start: the initial point of the arc
* @argument finish : the final point of the arc
* @argument clockwise : it is true if the arc is clockwise or counterclockwise respect to the start
*
* @returns : true if the arc touches the BoundingBox, false otherwise
*/
bool isArcColliding(const Point2f &arc_center, float radius, const Point2f &start, const Point2f &finish, bool clockwise) const override;
/**
* Function that returns the area of the BoundingBox
*
* @return : the area of the BoundingBox
*/
float getArea() const override;
/**
* Function that prints the information of the BoundingBox
*/
void print() const override;
/**
* Function that returns true if the dubins arc collides with the BoundingBox
*
* @argument da : the dubins arc to chek
*
* @returns : true if the dubins arc collides the BoundingBox, false otherwise
*/
bool isDubinsArcColliding(const DubinsArc &da) const override;
/**
* Function that returns true if a dubins curve is colliding with the BoundingBox
*
* @argument dc : the dubins curve to check if it collides
*
* @return : true is the dubins curve collide with the BoundingBox, false otherwise
*/
bool isDubinsCurveColliding(const DubinsCurve &dc) const override;
/**
* Function that returns true if the point is inside the BoundingBox
*
* @argument p : the point to check
*
* @returns : true if the point is inside the BoundingBox, false otherwise
*/
bool isPointInside(const Point2f &p) const override;
/**
* Method to get the minimum x
*
* @return : the minimum x
*/
float getMinX() const;
/**
* Method to get the minimum y
*
* @return : the minimum y
*/
float getMinY() const;
/**
* Method to get the maximum x
*
* @return : the maximum x
*/
float getMaxX() const;
/**
* Method to get the maximum y
*
* @return : the maximum y
*/
float getMaxY() const;
/**
* Method that returns true if the dubins arc is touching one of the boundaries of the bounding box
* is different from isDubinsArcColliding() because it does not check is the dubins arc is inside
* the bounding box
*
* @argument da : dubins arc to check
*
* @return true if the dubins arc is touching the boundaries of the bounding box, false otherwise
*/
bool isDubinsArcTouching(const DubinsArc &da) const;
/**
* Method that returns the four segments that compose the bounding box
*
* @return : the segments of the bounding box
*/
vector<Segment> getSegments();
// TO comment Sergio
BoundingBox& getBoundingBox() override;
bool bbIntersectsDubinsCurve(DubinsCurve &dc) override;
};
#endif
| [
"simone.zamboni996@gmail.com"
] | simone.zamboni996@gmail.com |
bdf874f7274ae691f287f92105dd1018860e2c38 | 40051990fd81ff4da9072d1c3be918d1e8e8d866 | /be/src/runtime/lib-cache.h | 4a564eec224fc1578970d1ddbc5263c47ef32fa2 | [
"Apache-2.0",
"OpenSSL",
"LicenseRef-scancode-openssl",
"LicenseRef-scancode-ssleay-windows",
"BSL-1.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"dtoa",
"BSD-3-Clause",
"bzip2-1.0.6",
"MIT",
"PSF-2.0",
"LicenseRef-scancode-mit-modification-obligations",
"LicenseRef-scancode-un... | permissive | P79N6A/impala | 64eb4dbab6b5b513ac37dc8aea351b01777bdda2 | d36ad070e6cb6ff720111e01f723e05a8cdf6957 | refs/heads/master | 2020-04-05T10:13:00.038610 | 2018-11-09T01:21:42 | 2018-11-09T01:21:42 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 7,372 | h | // Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#ifndef IMPALA_RUNTIME_LIB_CACHE_H
#define IMPALA_RUNTIME_LIB_CACHE_H
#include <string>
#include <boost/scoped_ptr.hpp>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include <boost/thread/mutex.hpp>
#include "common/atomic.h"
#include "common/object-pool.h"
#include "common/status.h"
namespace impala {
class RuntimeState;
/// Process-wide cache of dynamically-linked libraries loaded from HDFS.
/// These libraries can either be shared objects, llvm modules or jars. For
/// shared objects, when we load the shared object, we dlopen() it and keep
/// it in our process. For modules, we store the symbols in the module to
/// service symbol lookups. We can't cache the module since it (i.e. the external
/// module) is consumed when it is linked with the query codegen module.
//
/// Locking strategy: We don't want to grab a big lock across all operations since
/// one of the operations is copying a file from HDFS. With one lock that would
/// prevent any UDFs from running on the system. Instead, we have a global lock
/// that is taken when doing the cache lookup, but is not taken during any blocking calls.
/// During the block calls, we take the per-lib lock.
//
/// Entry lifetime management: We cannot delete the entry while a query is
/// using the library. When the caller requests a ptr into the library, they
/// are given the entry handle and must decrement the ref count when they
/// are done.
//
/// TODO:
/// - refresh libraries
/// - better cached module management.
struct LibCacheEntry;
class LibCache {
public:
enum LibType {
TYPE_SO, // Shared object
TYPE_IR, // IR intermediate
TYPE_JAR, // Java jar file. We don't care about the contents in the BE.
};
static LibCache* instance() { return LibCache::instance_.get(); }
/// Calls dlclose on all cached handles.
~LibCache();
/// Initializes the libcache. Must be called before any other APIs.
static Status Init();
/// Gets the local file system path for the library at 'hdfs_lib_file'. If
/// this file is not already on the local fs, it copies it and caches the
/// result. Returns an error if 'hdfs_lib_file' cannot be copied to the local fs.
Status GetLocalLibPath(const std::string& hdfs_lib_file, LibType type,
std::string* local_path);
/// Returns status.ok() if the symbol exists in 'hdfs_lib_file', non-ok otherwise.
/// If 'quiet' is true, the error status for non-Java unfound symbols will not be logged.
Status CheckSymbolExists(const std::string& hdfs_lib_file, LibType type,
const std::string& symbol, bool quiet = false);
/// Returns a pointer to the function for the given library and symbol.
/// If 'hdfs_lib_file' is empty, the symbol is looked up in the impalad process.
/// Otherwise, 'hdfs_lib_file' should be the HDFS path to a shared library (.so) file.
/// dlopen handles and symbols are cached.
/// Only usable if 'hdfs_lib_file' refers to a shared object.
//
/// If entry is non-null and *entry is null, *entry will be set to the cached entry. If
/// entry is non-null and *entry is non-null, *entry will be reused (i.e., the use count
/// is not increased). The caller must call DecrementUseCount(*entry) when it is done
/// using fn_ptr and it is no longer valid to use fn_ptr.
//
/// If 'quiet' is true, returned error statuses will not be logged.
Status GetSoFunctionPtr(const std::string& hdfs_lib_file, const std::string& symbol,
void** fn_ptr, LibCacheEntry** entry, bool quiet = false);
/// Marks the entry for 'hdfs_lib_file' as needing to be refreshed if the file in HDFS is
/// newer than the local cached copied. The refresh will occur the next time the entry is
/// accessed.
void SetNeedsRefresh(const std::string& hdfs_lib_file);
/// See comment in GetSoFunctionPtr().
void DecrementUseCount(LibCacheEntry* entry);
/// Removes the cache entry for 'hdfs_lib_file'
void RemoveEntry(const std::string& hdfs_lib_file);
/// Removes all cached entries.
void DropCache();
private:
/// Singleton instance. Instantiated in Init().
static boost::scoped_ptr<LibCache> instance_;
/// dlopen() handle for the current process (i.e. impalad).
void* current_process_handle_;
/// The number of libs that have been copied from HDFS to the local FS.
/// This is appended to the local fs path to remove collisions.
AtomicInt64 num_libs_copied_;
/// Protects lib_cache_. For lock ordering, this lock must always be taken before
/// the per entry lock.
boost::mutex lock_;
/// Maps HDFS library path => cache entry.
/// Entries in the cache need to be explicitly deleted.
typedef boost::unordered_map<std::string, LibCacheEntry*> LibMap;
LibMap lib_cache_;
LibCache();
LibCache(LibCache const& l); // disable copy ctor
LibCache& operator=(LibCache const& l); // disable assignment
Status InitInternal();
/// Returns the cache entry for 'hdfs_lib_file'. If this library has not been
/// copied locally, it will copy it and add a new LibCacheEntry to 'lib_cache_'.
/// Result is returned in *entry.
/// No locks should be taken before calling this. On return the entry's lock is
/// taken and returned in *entry_lock.
/// If an error is returned, there will be no entry in lib_cache_ and *entry is NULL.
Status GetCacheEntry(const std::string& hdfs_lib_file, LibType type,
boost::unique_lock<boost::mutex>* entry_lock, LibCacheEntry** entry);
/// Implementation to get the cache entry for 'hdfs_lib_file'. Errors are returned
/// without evicting the cache entry if the status is not OK and *entry is not NULL.
Status GetCacheEntryInternal(const std::string& hdfs_lib_file, LibType type,
boost::unique_lock<boost::mutex>* entry_lock, LibCacheEntry** entry);
/// Utility function for generating a filename unique to this process and
/// 'hdfs_path'. This is to prevent multiple impalad processes or different library files
/// with the same name from clobbering each other. 'hdfs_path' should be the full path
/// (including the filename) of the file we're going to copy to the local FS, and
/// 'local_dir' is the local directory prefix of the returned path.
std::string MakeLocalPath(const std::string& hdfs_path, const std::string& local_dir);
/// Implementation to remove an entry from the cache.
/// lock_ must be held. The entry's lock should not be held.
void RemoveEntryInternal(const std::string& hdfs_lib_file,
const LibMap::iterator& entry_iterator);
};
}
#endif
| [
"zhangjunemail@126.com"
] | zhangjunemail@126.com |
86e5195ae232d52945ca8c7c1e54d7cdf4ea99bb | 1d928c3f90d4a0a9a3919a804597aa0a4aab19a3 | /c++/Halide/2016/4/blas_l3_generators.cpp | a908ffa0ff7bfcc0b680bfddfa7d4e859f80887e | [] | no_license | rosoareslv/SED99 | d8b2ff5811e7f0ffc59be066a5a0349a92cbb845 | a062c118f12b93172e31e8ca115ce3f871b64461 | refs/heads/main | 2023-02-22T21:59:02.703005 | 2021-01-28T19:40:51 | 2021-01-28T19:40:51 | 306,497,459 | 1 | 1 | null | 2020-11-24T20:56:18 | 2020-10-23T01:18:07 | null | UTF-8 | C++ | false | false | 5,080 | cpp | #include <vector>
#include "Halide.h"
using namespace Halide;
namespace {
// Generator class for BLAS gemm operations.
template<class T>
class GEMMGenerator :
public Generator<GEMMGenerator<T>> {
public:
typedef Generator<GEMMGenerator<T>> Base;
using Base::target;
using Base::get_target;
using Base::natural_vector_size;
GeneratorParam<bool> transpose_A_ = {"transpose_A", false};
GeneratorParam<bool> transpose_B_ = {"transpose_B", false};
// Standard ordering of parameters in GEMM functions.
Param<T> a_ = {"a", 1.0};
ImageParam A_ = {type_of<T>(), 2, "A"};
ImageParam B_ = {type_of<T>(), 2, "B"};
Param<T> b_ = {"b", 1.0};
ImageParam C_ = {type_of<T>(), 2, "C"};
Func build() {
// Matrices are interpreted as column-major by default. The
// transpose GeneratorParams are used to handle cases where
// one or both is actually row major.
const Expr num_rows = A_.width();
const Expr num_cols = B_.height();
const Expr sum_size = A_.height();
const int vec = natural_vector_size(a_.type());
const int s = vec * 2;
// If they're both transposed, then reverse the order and transpose the result instead.
bool transpose_AB = false;
if ((bool)transpose_A_ && (bool)transpose_B_) {
std::swap(A_, B_);
transpose_A_.set(false);
transpose_B_.set(false);
transpose_AB = true;
}
Var i, j, ii, ji, jii, iii, io, jo, t;
Var ti[3], tj[3];
Func result("result");
// Swizzle A for better memory order in the inner loop.
Func A("A"), B("B"), Btmp("Btmp"), As("As"), Atmp("Atmp");
Atmp(i, j) = BoundaryConditions::constant_exterior(A_, cast<T>(0))(i, j);
if (transpose_A_) {
As(i, j, io) = Atmp(j, io*s + i);
} else {
As(i, j, io) = Atmp(io*s + i, j);
}
A(i, j) = As(i % s, j, i / s);
Btmp(i, j) = B_(i, j);
if (transpose_B_) {
B(i, j) = Btmp(j, i);
} else {
B(i, j) = Btmp(i, j);
}
Var k("k");
Func prod;
// Express all the products we need to do a matrix multiply as a 3D Func.
prod(k, i, j) = A(i, k) * B(k, j);
// Reduce the products along k.
Func AB("AB");
RDom rv(0, sum_size);
AB(i, j) += prod(rv, i, j);
Func ABt("ABt");
if (transpose_AB) {
// Transpose A*B if necessary.
ABt(i, j) = AB(j, i);
} else {
ABt(i, j) = AB(i, j);
}
// Do the part that makes it a 'general' matrix multiply.
result(i, j) = (a_ * ABt(i, j) + b_ * C_(i, j));
result.tile(i, j, ti[1], tj[1], i, j, 2*s, 2*s, TailStrategy::GuardWithIf);
if (transpose_AB) {
result
.tile(i, j, ii, ji, 4, s)
.tile(i, j, ti[0], tj[0], i, j, s/4, 1);
} else {
result
.tile(i, j, ii, ji, s, 4)
.tile(i, j, ti[0], tj[0], i, j, 1, s/4);
}
// If we have enough work per task, parallelize over these tiles.
result.specialize(num_rows >= 512 && num_cols >= 512)
.fuse(tj[1], ti[1], t).parallel(t);
// Otherwise tile one more time before parallelizing, or don't
// parallelize at all.
result.specialize(num_rows >= 128 && num_cols >= 128)
.tile(ti[1], tj[1], ti[2], tj[2], ti[1], tj[1], 2, 2)
.fuse(tj[2], ti[2], t).parallel(t);
result.rename(tj[0], t);
result.bound(i, 0, num_rows).bound(j, 0, num_cols);
As.compute_root()
.split(j, jo, ji, s).reorder(i, ji, io, jo)
.unroll(i).vectorize(ji)
.specialize(A_.width() >= 256 && A_.height() >= 256).parallel(jo, 4);
Atmp.compute_at(As, io)
.vectorize(i).unroll(j);
if (transpose_B_) {
B.compute_at(result, t)
.tile(i, j, ii, ji, 8, 8)
.vectorize(ii).unroll(ji);
Btmp.reorder_storage(j, i)
.compute_at(B, i)
.vectorize(i)
.unroll(j);
}
AB.compute_at(result, i)
.bound_extent(j, 4).unroll(j)
.bound_extent(i, s).vectorize(i)
.update()
.reorder(i, j, rv).unroll(j).unroll(rv, 2).vectorize(i);
if (transpose_AB) {
ABt.compute_at(result, i)
.bound_extent(i, 4).unroll(i)
.bound_extent(j, s).vectorize(j);
}
A_.set_min(0, 0).set_min(1, 0);
B_.set_bounds(0, 0, sum_size).set_min(1, 0);
C_.set_bounds(0, 0, num_rows).set_bounds(1, 0, num_cols);
result.output_buffer().set_bounds(0, 0, num_rows).set_bounds(1, 0, num_cols);
return result;
}
};
RegisterGenerator<GEMMGenerator<float>> register_sgemm("sgemm");
RegisterGenerator<GEMMGenerator<double>> register_dgemm("dgemm");
} // namespace
| [
"rodrigosoaresilva@gmail.com"
] | rodrigosoaresilva@gmail.com |
b34d0ade5d9dda2929aee63c1edab27aeb9eb787 | 887947567c0b0095cae2c533fa06f59d9e97b7f0 | /11507 - Bender B. Rodríguez Problem.cpp | 7d1d41772269b96ebb78bfe32768ea59c1f05d01 | [] | no_license | rwitam-b/UVa-Solutions | 78f619cc6bc06452d7b11054496bb6c7546e95ea | 4ddcd83c5a5e54734ed783c78964be9f409888eb | refs/heads/master | 2021-09-07T22:29:35.056395 | 2018-03-02T07:15:26 | 2018-03-02T07:15:26 | 114,964,623 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 966 | cpp | #define axis(str) str[str.size()-1]
#define sign(str) str[0]
#include<iostream>
#include<string>
using namespace std;
int main()
{
int length;
string bend;
while (cin >> length && length > 1) {
string pos = "+x";
for (int a = 0; a < length - 1; a++) {
cin >> bend;
if (!bend.compare("No")) {
continue;
}
if (axis(pos) == 'x') {
if (sign(pos) == '+') {
pos = bend;
}
else {
pos[0] = (sign(bend) == '+' ? '-' : '+');
pos[1] = axis(bend);
}
}
else if (axis(pos) == 'y' && axis(bend) == 'y') {
if (sign(pos) == '+') {
pos = (sign(bend) == '+' ? "-x" : "+x");
}
else {
pos = (sign(bend) == '+' ? "+x" : "-x");
}
}
else if (axis(pos) == 'z' && axis(bend) == 'z') {
if (sign(pos) == '+') {
pos = (sign(bend) == '+' ? "-x" : "+x");
}
else if (sign(pos) == '-') {
pos = (sign(bend) == '+' ? "+x" : "-x");
}
}
}
cout << pos << endl;
}
return 0;
}
| [
"noreply@github.com"
] | noreply@github.com |
69331a32ce1ee70409a8fadc4ddfb6d9f690bb7f | fb7efe44f4d9f30d623f880d0eb620f3a81f0fbd | /chrome/browser/safe_browsing/incident_reporting/binary_integrity_analyzer.cc | c78d52f92937299f535116a2afcb442f97769584 | [
"BSD-3-Clause"
] | permissive | wzyy2/chromium-browser | 2644b0daf58f8b3caee8a6c09a2b448b2dfe059c | eb905f00a0f7e141e8d6c89be8fb26192a88c4b7 | refs/heads/master | 2022-11-23T20:25:08.120045 | 2018-01-16T06:41:26 | 2018-01-16T06:41:26 | 117,618,467 | 3 | 2 | BSD-3-Clause | 2022-11-20T22:03:57 | 2018-01-16T02:09:10 | null | UTF-8 | C++ | false | false | 2,353 | cc | // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_analyzer.h"
#include <string>
#include <utility>
#include "base/bind.h"
#include "base/callback.h"
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incident.h"
#include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "components/safe_browsing/proto/csd.pb.h"
namespace safe_browsing {
void RecordSignatureVerificationTime(size_t file_index,
const base::TimeDelta& verification_time) {
static const char kHistogramName[] = "SBIRS.VerifyBinaryIntegrity.";
base::HistogramBase* signature_verification_time_histogram =
base::Histogram::FactoryTimeGet(
std::string(kHistogramName) + base::SizeTToString(file_index),
base::TimeDelta::FromMilliseconds(1),
base::TimeDelta::FromSeconds(20), 50,
base::Histogram::kUmaTargetedHistogramFlag);
signature_verification_time_histogram->AddTime(verification_time);
}
void ClearBinaryIntegrityForFile(IncidentReceiver* incident_receiver,
const std::string& basename) {
std::unique_ptr<ClientIncidentReport_IncidentData_BinaryIntegrityIncident>
incident(new ClientIncidentReport_IncidentData_BinaryIntegrityIncident());
incident->set_file_basename(basename);
incident_receiver->ClearIncidentForProcess(
base::MakeUnique<BinaryIntegrityIncident>(std::move(incident)));
}
void RegisterBinaryIntegrityAnalysis() {
#if defined(OS_WIN) || defined(OS_MACOSX)
scoped_refptr<SafeBrowsingService> safe_browsing_service(
g_browser_process->safe_browsing_service());
safe_browsing_service->RegisterDelayedAnalysisCallback(
base::Bind(&VerifyBinaryIntegrity));
#endif
}
} // namespace safe_browsing
| [
"jacob-chen@iotwrt.com"
] | jacob-chen@iotwrt.com |
b72517d2809bae47295c3a97baa83947eed70524 | f08d689a166c17a11f0191cda5e7893c37b12f9f | /Problem Solving/Warmup/CompareTheTriplets.cpp | 21a7d2c5ed21218737111def5c6511ec64e26004 | [
"MIT"
] | permissive | iamnambiar/HackerRank-Solutions | f1bb3d870a04be3e4009d93c7a48c8954d3ead16 | 6fdcab79b18e66a6d7278b979a8be087f8f6c696 | refs/heads/master | 2021-05-23T18:42:10.827591 | 2021-04-23T04:49:21 | 2021-04-23T04:49:21 | 253,420,715 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,127 | cpp | // https://www.hackerrank.com/challenges/compare-the-triplets/problem
#include <bits/stdc++.h>
using namespace std;
string ltrim(const string &);
string rtrim(const string &);
vector<string> split(const string &);
// Complete the compareTriplets function below.
vector<int> compareTriplets(vector<int> a, vector<int> b) {
vector<int> result (2, 0);
if (a.size() == b.size()){
for (int index = 0; index < a.size(); ++index) {
if (a[index] > b[index])
++result[0];
else if (a[index] < b[index])
++result[1];
}
}
return result;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string a_temp_temp;
getline(cin, a_temp_temp);
vector<string> a_temp = split(rtrim(a_temp_temp));
vector<int> a(3);
for (int i = 0; i < 3; i++) {
int a_item = stoi(a_temp[i]);
a[i] = a_item;
}
string b_temp_temp;
getline(cin, b_temp_temp);
vector<string> b_temp = split(rtrim(b_temp_temp));
vector<int> b(3);
for (int i = 0; i < 3; i++) {
int b_item = stoi(b_temp[i]);
b[i] = b_item;
}
vector<int> result = compareTriplets(a, b);
for (int i = 0; i < result.size(); i++) {
fout << result[i];
if (i != result.size() - 1) {
fout << " ";
}
}
fout << "\n";
fout.close();
return 0;
}
string ltrim(const string &str) {
string s(str);
s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
);
return s;
}
string rtrim(const string &str) {
string s(str);
s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
s.end()
);
return s;
}
vector<string> split(const string &str) {
vector<string> tokens;
string::size_type start = 0;
string::size_type end = 0;
while ((end = str.find(" ", start)) != string::npos) {
tokens.push_back(str.substr(start, end - start));
start = end + 1;
}
tokens.push_back(str.substr(start));
return tokens;
}
| [
"neeraj.cnambiar@gmail.com"
] | neeraj.cnambiar@gmail.com |
3a95f61c4a9028c08b3cd71ac871cb0444b7628a | 3d845db6ed8e87cf4eb8087e83d41ca037f578f6 | /double_hashing.h | 34b648308cbd875d5c40d4c27bcc2d05eb460440 | [] | no_license | arnoldosolis/CSCI335-hw4 | 00c28abc3047973b9ff0ffd50af0caa843019b99 | 5d2c856148496a63a5bf64f526e4e51b7523f0c7 | refs/heads/main | 2023-04-05T12:21:07.076351 | 2021-04-16T18:19:36 | 2021-04-16T18:19:36 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,188 | h | #ifndef DOUBLE_PROBING_H
#define DOUBLE_PROBING_H
#include <vector>
#include <algorithm>
#include <functional>
// Double probing implementation.
template <typename HashedObj>
class HashTableDouble
{
public:
enum EntryType
{
ACTIVE,
EMPTY,
DELETED
};
explicit HashTableDouble(size_t size = 101) : array_(NextPrime(size))
{
MakeEmpty();
}
bool Contains(const HashedObj &x) const
{
return IsActive(FindPos(x));
}
void MakeEmpty()
{
current_size_ = 0;
for (auto &entry : array_)
entry.info_ = EMPTY;
}
bool Insert(const HashedObj &x)
{
// Insert x as active
size_t current_pos = FindPos(x);
if (IsActive(current_pos))
{
return false;
}
array_[current_pos].element_ = x;
array_[current_pos].info_ = ACTIVE;
// Rehash; see Section 5.5
if (++current_size_ > array_.size() / 2)
{
Rehash();
}
return true;
}
bool Insert(HashedObj &&x)
{
// Insert x as active
size_t current_pos = FindPos(x);
if (IsActive(current_pos))
{
return false;
}
array_[current_pos] = std::move(x);
array_[current_pos].info_ = ACTIVE;
// Rehash; see Section 5.5
if (++current_size_ > array_.size() / 2)
{
Rehash();
}
return true;
}
bool Remove(const HashedObj &x)
{
size_t current_pos = FindPos(x);
if (!IsActive(current_pos))
return false;
array_[current_pos].info_ = DELETED;
return true;
}
/*
* Returns # of elements in hashmap (N)
*/
int getElementCount()
{
return current_size_;
}
/*
* Returns the size of table (T)
*/
int getCurrentSize()
{
return array_.size();
}
/*
* Returns # of collisions (C)
*/
int collisionCount()
{
return collisionCount_;
}
float theLoadFactor()
{
float ele = current_size_;
float size = array_.size();
return ele / size;
}
/*
* Returns average number of collisions (M=C/N)
*/
float averageCollisions()
{
float col = collisionCount_;
float ele = current_size_;
return col / ele;
}
/*
* Set collision count to 0
*/
int resetCollisionCount()
{
return collisionCount_ = 0;
}
/*
* Sets R
*/
void setR(int x)
{
R = x;
}
private:
struct HashEntry
{
HashedObj element_;
EntryType info_;
HashEntry(const HashedObj &e = HashedObj{}, EntryType i = EMPTY)
: element_{e}, info_{i} {}
HashEntry(HashedObj &&e, EntryType i = EMPTY)
: element_{std::move(e)}, info_{i} {}
};
std::vector<HashEntry> array_;
size_t current_size_;
/*
* Added Variables for counting
*/
mutable int collisionCount_ = 0;
int R = 0;
bool IsActive(size_t current_pos) const
{
return array_[current_pos].info_ == ACTIVE;
}
size_t FindPos(const HashedObj &x) const
{
size_t offset = InternalSecondHash(x);
size_t current_pos = InternalHash(x);
while (array_[current_pos].info_ != EMPTY && array_[current_pos].element_ != x)
{
collisionCount_++;
current_pos += offset; // Compute ith probe.
if (current_pos >= array_.size())
current_pos -= array_.size();
}
return current_pos;
}
/*
* Rehashing for quadratic probing hash table
*/
void Rehash()
{
std::vector<HashEntry> old_array = array_;
// Create new double-sized, empty table.
array_.resize(NextPrime(2 * old_array.size()));
for (auto &entry : array_)
entry.info_ = EMPTY;
// Copy table over.
current_size_ = 0;
for (auto &entry : old_array)
if (entry.info_ == ACTIVE)
Insert(std::move(entry.element_));
}
size_t InternalHash(const HashedObj &x) const
{
static std::hash<HashedObj> hf;
return hf(x) % array_.size();
}
size_t InternalSecondHash(const HashedObj &x) const
{
static std::hash<HashedObj> hf;
return (R - ((hf(x) % R)) % array_.size());
}
};
#endif // DOUBLE_PROBING_H
| [
"arnoldosolis817@gmail.com"
] | arnoldosolis817@gmail.com |
b0e6c9c4ab8ca481623cfe18666beab46020aca0 | d9dbdf6517e5e02f81de25b02c823eaae9406866 | /src/Player.h | 63580f03e1c5079b235bd248240ce063be90997b | [] | no_license | fdarling/ludum47 | 9696e4b80ec280fd98accd82d7ed33d076661a70 | e355d55fd0060307106079fe59d3c46faf9abe9a | refs/heads/master | 2023-07-21T18:21:06.338319 | 2021-02-15T01:54:50 | 2021-02-15T01:54:50 | 301,842,828 | 0 | 1 | null | 2023-07-18T00:36:43 | 2020-10-06T20:10:32 | C++ | UTF-8 | C++ | false | false | 679 | h | #pragma once
#include <Box2D/Box2D.h>
#include "Rect.h"
// #include <BulletCollision/CollisionShapes/btCollisionShape.h>
// #include <BulletDynamics/Dynamics/btRigidBody.h>
class Player
{
public:
Player();
~Player();
bool init();
void walkLeft();
void walkRight();
void jump();
void advance();
void draw(const Point &offset) const;
Rect rect;
// SDL_Texture *_standingTexture;
SDL_Texture *_walkingTexture;
int _frameIndex;
bool _walkingLeft;
Point _lastPos;
// btCollisionShape *shape;
// btRigidBody *body;
b2Body *body;
b2Fixture *fixture;
bool touchingGround;
};
| [
"fdarling@gmail.com"
] | fdarling@gmail.com |
f70a2279857a8abeb56c7b1c7a2461e192fbb23e | 58fc1e297276e83c1bf4db5b17fc40e09bb3bceb | /src/CCA/Components/Wasatch/Expressions/PBE/Precipitation/PrecipitationClassicNucleationCoefficient.h | 2c6b84d5d2f6abc7de329f82eb289a39ffb246c2 | [
"MIT"
] | permissive | jholmen/Uintah-kokkos_dev_old | 219679a92e5ed17594040ec602e1fd946e823cde | da1e965f8f065ae5980e69a590b52d85b2df1a60 | refs/heads/master | 2023-04-13T17:03:13.552152 | 2021-04-20T13:16:22 | 2021-04-20T13:16:22 | 359,657,090 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,874 | h | /*
* The MIT License
*
* Copyright (c) 2012-2016 The University of Utah
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef PrecipitationClassicNucleationCoefficient_Expr_h
#define PrecipitationClassicNucleationCoefficient_Expr_h
#include <expression/Expression.h>
/**
* \ingroup WasatchExpressions
* \class PrecipitationClassicNucleationCoefficient
* \author Alex Abboud
* \date January, 2012
*
* \tparam FieldT the type of field.
*
* \brief Nucleation Coeffcient Source term for use in QMOM
* classic nucleation refers to this value as
* \f$ B_0 = \exp ( 16 \pi /3 ( \gamma /K_B T)^3( \nu /N_A/ \ln(S)^2 \f$
*/
template< typename FieldT >
class PrecipitationClassicNucleationCoefficient
: public Expr::Expression<FieldT>
{
const double expConst_;
DECLARE_FIELD(FieldT, superSat_)
PrecipitationClassicNucleationCoefficient( const Expr::Tag& superSatTag,
const double expConst);
public:
class Builder : public Expr::ExpressionBuilder
{
public:
Builder( const Expr::Tag& result,
const Expr::Tag& superSatTag,
const double expConst )
: ExpressionBuilder(result),
supersatt_(superSatTag),
expconst_(expConst)
{}
~Builder(){}
Expr::ExpressionBase* build() const
{
return new PrecipitationClassicNucleationCoefficient<FieldT>( supersatt_, expconst_);
}
private:
const Expr::Tag supersatt_;
const double expconst_;
};
~PrecipitationClassicNucleationCoefficient();
void evaluate();
};
// ###################################################################
//
// Implementation
//
// ###################################################################
template< typename FieldT >
PrecipitationClassicNucleationCoefficient<FieldT>::
PrecipitationClassicNucleationCoefficient( const Expr::Tag& superSatTag,
const double expConst)
: Expr::Expression<FieldT>(),
expConst_(expConst)
{
this->set_gpu_runnable( true );
superSat_ = this->template create_field_request<FieldT>(superSatTag);
}
//--------------------------------------------------------------------
template< typename FieldT >
PrecipitationClassicNucleationCoefficient<FieldT>::
~PrecipitationClassicNucleationCoefficient()
{}
//--------------------------------------------------------------------
template< typename FieldT >
void
PrecipitationClassicNucleationCoefficient<FieldT>::
evaluate()
{
using namespace SpatialOps;
FieldT& result = this->value();
const FieldT& S = superSat_->field_ref();
result <<= cond( S > 1.0, exp(expConst_ / log(S) / log(S) ) )
( 0.0 );
}
//--------------------------------------------------------------------
#endif // PrecipitationClassicNucleationCoefficient_Expr_h
| [
"ahumphrey@sci.utah.edu"
] | ahumphrey@sci.utah.edu |
526b02062a27d19526c11d2815e4985335d05ef5 | 495c5e320ff12694a266605fb1e57f20a9191365 | /src/Vector.h | 3688013b62db46b4caf222ebb10ec7a76a12e196 | [] | no_license | jfellus/pg_algebra | 12ec1e5f317102ff7c66c25b1e28b7d7c8bc83e6 | aff2857394f512982b2c636b630282df5746746b | refs/heads/master | 2016-09-15T15:01:51.224314 | 2016-04-02T17:34:04 | 2016-04-02T17:34:04 | 34,625,272 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 636 | h | /*
* Vector.h
*
* Created on: 20 avr. 2015
* Author: jfellus
*/
#ifndef VECTOR_H_
#define VECTOR_H_
#include <pg.h>
#include <matrix.h>
class RowVector {
public:
Matrix out;
OUTPUT(Matrix, out)
public:
RowVector() {}
void init() {
out.h = 1;
}
void process(Matrix& in) {
out.data = in;
out.n = out.w = in.n;
}
};
class ColVector {
public:
Matrix out;
OUTPUT(Matrix, out)
public:
ColVector() {}
void init() {
out.w = 1;
}
void process(Matrix& in) {
out.data = in;
out.n = out.h = in.n;
}
void process(Image& in) {
out.data = in.data;
out.n = out.h = in.n;
}
};
#endif /* VECTOR_H_ */
| [
"jfellus@gmail.com"
] | jfellus@gmail.com |
086e47282526d5fc8b81457b3b8cc96078f39477 | bc18aa46ee25ab4b14d63f59d8ace6a0cb691abf | /include/armadillo/armadillo_bits/SpMat_meat.hpp | 54d5a507c13ce6736646b362195398b396202c2d | [] | no_license | mirsking/DMPwp | 9a1788e05687f395b03d2c4daf6d9ee16509ad64 | 73a981ac542b70821d5ee0c75b87df73e3ce83eb | refs/heads/master | 2021-01-16T18:40:31.689249 | 2014-03-22T13:33:34 | 2014-03-22T13:33:34 | 18,009,238 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 108,487 | hpp | // Copyright (C) 2011-2013 Ryan Curtin
// Copyright (C) 2012-2013 Conrad Sanderson
// Copyright (C) 2011 Matthew Amidon
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//! \addtogroup SpMat
//! @{
/**
* Initialize a sparse matrix with size 0x0 (empty).
*/
template<typename eT>
inline
SpMat<eT>::SpMat()
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(memory::acquire_chunked<eT>(1))
, row_indices(memory::acquire_chunked<uword>(1))
, col_ptrs(memory::acquire<uword>(2))
{
arma_extra_debug_sigprint_this(this);
access::rw(values[0]) = 0;
access::rw(row_indices[0]) = 0;
access::rw(col_ptrs[0]) = 0; // No elements.
access::rw(col_ptrs[1]) = std::numeric_limits<uword>::max();
}
/**
* Clean up the memory of a sparse matrix and destruct it.
*/
template<typename eT>
inline
SpMat<eT>::~SpMat()
{
arma_extra_debug_sigprint_this(this);
// If necessary, release the memory.
if (values)
{
// values being non-NULL implies row_indices is non-NULL.
memory::release(access::rw(values));
memory::release(access::rw(row_indices));
}
// Column pointers always must be deleted.
memory::release(access::rw(col_ptrs));
}
/**
* Constructor with size given.
*/
template<typename eT>
inline
SpMat<eT>::SpMat(const uword in_rows, const uword in_cols)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL)
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
init(in_rows, in_cols);
}
/**
* Assemble from text.
*/
template<typename eT>
inline
SpMat<eT>::SpMat(const char* text)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL)
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
init(std::string(text));
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const char* text)
{
arma_extra_debug_sigprint();
init(std::string(text));
}
template<typename eT>
inline
SpMat<eT>::SpMat(const std::string& text)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL)
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint();
init(text);
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const std::string& text)
{
arma_extra_debug_sigprint();
init(text);
}
template<typename eT>
inline
SpMat<eT>::SpMat(const SpMat<eT>& x)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL)
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
init(x);
}
//! Insert a large number of values at once.
//! locations.row[0] should be row indices, locations.row[1] should be column indices,
//! and values should be the corresponding values.
//! If sort_locations is false, then it is assumed that the locations and values
//! are already sorted in column-major ordering.
template<typename eT>
template<typename T1, typename T2>
inline
SpMat<eT>::SpMat(const Base<uword,T1>& locations_expr, const Base<eT,T2>& vals_expr, const bool sort_locations)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL)
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
const unwrap<T1> locs_tmp( locations_expr.get_ref() );
const Mat<uword>& locs = locs_tmp.M;
const unwrap<T2> vals_tmp( vals_expr.get_ref() );
const Mat<eT>& vals = vals_tmp.M;
arma_debug_check( (vals.is_vec() == false), "SpMat::SpMat(): given 'values' object is not a vector" );
arma_debug_check((locs.n_cols != vals.n_elem), "SpMat::SpMat(): number of locations is different than number of values");
// If there are no elements in the list, max() will fail.
if (locs.n_cols == 0)
{
init(0, 0);
return;
}
arma_debug_check((locs.n_rows != 2), "SpMat::SpMat(): locations matrix must have two rows");
// Automatically determine size (and check if it's sorted).
uvec bounds = arma::max(locs, 1);
init(bounds[0] + 1, bounds[1] + 1);
// Resize to correct number of elements.
mem_resize(vals.n_elem);
// Reset column pointers to zero.
arrayops::inplace_set(access::rwp(col_ptrs), uword(0), n_cols + 1);
bool actually_sorted = true;
if(sort_locations == true)
{
// sort_index() uses std::sort() which may use quicksort... so we better
// make sure it's not already sorted before taking an O(N^2) sort penalty.
for (uword i = 1; i < locs.n_cols; ++i)
{
if ((locs.at(1, i) < locs.at(1, i - 1)) || (locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) <= locs.at(0, i - 1)))
{
actually_sorted = false;
break;
}
}
if(actually_sorted == false)
{
// This may not be the fastest possible implementation but it maximizes code reuse.
Col<uword> abslocs(locs.n_cols);
for (uword i = 0; i < locs.n_cols; ++i)
{
abslocs[i] = locs.at(1, i) * n_rows + locs.at(0, i);
}
// Now we will sort with sort_index().
uvec sorted_indices = sort_index(abslocs); // Ascending sort.
// Now we add the elements in this sorted order.
for (uword i = 0; i < sorted_indices.n_elem; ++i)
{
arma_debug_check((locs.at(0, sorted_indices[i]) >= n_rows), "SpMat::SpMat(): invalid row index");
arma_debug_check((locs.at(1, sorted_indices[i]) >= n_cols), "SpMat::SpMat(): invalid column index");
access::rw(values[i]) = vals[sorted_indices[i]];
access::rw(row_indices[i]) = locs.at(0, sorted_indices[i]);
access::rw(col_ptrs[locs.at(1, sorted_indices[i]) + 1])++;
}
}
}
if( (sort_locations == false) || (actually_sorted == true) )
{
// Now set the values and row indices correctly.
// Increment the column pointers in each column (so they are column "counts").
for (uword i = 0; i < vals.n_elem; ++i)
{
arma_debug_check((locs.at(0, i) >= n_rows), "SpMat::SpMat(): invalid row index");
arma_debug_check((locs.at(1, i) >= n_cols), "SpMat::SpMat(): invalid column index");
// Check ordering in debug mode.
if(i > 0)
{
arma_debug_check
(
( (locs.at(1, i) < locs.at(1, i - 1)) || (locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) < locs.at(0, i - 1)) ),
"SpMat::SpMat(): out of order points; either pass sort_locations = true, or sort points in column-major ordering"
);
arma_debug_check((locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) == locs.at(0, i - 1)), "SpMat::SpMat(): two identical point locations in list");
}
access::rw(values[i]) = vals[i];
access::rw(row_indices[i]) = locs.at(0, i);
access::rw(col_ptrs[locs.at(1, i) + 1])++;
}
}
// Now fix the column pointers.
for (uword i = 0; i <= n_cols; ++i)
{
access::rw(col_ptrs[i + 1]) += col_ptrs[i];
}
}
//! Insert a large number of values at once.
//! locations.row[0] should be row indices, locations.row[1] should be column indices,
//! and values should be the corresponding values.
//! If sort_locations is false, then it is assumed that the locations and values
//! are already sorted in column-major ordering.
//! In this constructor the size is explicitly given.
template<typename eT>
template<typename T1, typename T2>
inline
SpMat<eT>::SpMat(const Base<uword,T1>& locations_expr, const Base<eT,T2>& vals_expr, const uword in_n_rows, const uword in_n_cols, const bool sort_locations)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL)
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
init(in_n_rows, in_n_cols);
const unwrap<T1> locs_tmp( locations_expr.get_ref() );
const Mat<uword>& locs = locs_tmp.M;
const unwrap<T2> vals_tmp( vals_expr.get_ref() );
const Mat<eT>& vals = vals_tmp.M;
arma_debug_check( (vals.is_vec() == false), "SpMat::SpMat(): given 'values' object is not a vector" );
arma_debug_check((locs.n_rows != 2), "SpMat::SpMat(): locations matrix must have two rows");
arma_debug_check((locs.n_cols != vals.n_elem), "SpMat::SpMat(): number of locations is different than number of values");
// Resize to correct number of elements.
mem_resize(vals.n_elem);
// Reset column pointers to zero.
arrayops::inplace_set(access::rwp(col_ptrs), uword(0), n_cols + 1);
bool actually_sorted = true;
if(sort_locations == true)
{
// sort_index() uses std::sort() which may use quicksort... so we better
// make sure it's not already sorted before taking an O(N^2) sort penalty.
for (uword i = 1; i < locs.n_cols; ++i)
{
if ((locs.at(1, i) < locs.at(1, i - 1)) || (locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) <= locs.at(0, i - 1)))
{
actually_sorted = false;
break;
}
}
if(actually_sorted == false)
{
// This may not be the fastest possible implementation but it maximizes code reuse.
Col<uword> abslocs(locs.n_cols);
for (uword i = 0; i < locs.n_cols; ++i)
{
abslocs[i] = locs.at(1, i) * n_rows + locs.at(0, i);
}
// Now we will sort with sort_index().
uvec sorted_indices = sort_index(abslocs); // Ascending sort.
// Now we add the elements in this sorted order.
for (uword i = 0; i < sorted_indices.n_elem; ++i)
{
arma_debug_check((locs.at(0, sorted_indices[i]) >= n_rows), "SpMat::SpMat(): invalid row index");
arma_debug_check((locs.at(1, sorted_indices[i]) >= n_cols), "SpMat::SpMat(): invalid column index");
access::rw(values[i]) = vals[sorted_indices[i]];
access::rw(row_indices[i]) = locs.at(0, sorted_indices[i]);
access::rw(col_ptrs[locs.at(1, sorted_indices[i]) + 1])++;
}
}
}
if( (sort_locations == false) || (actually_sorted == true) )
{
// Now set the values and row indices correctly.
// Increment the column pointers in each column (so they are column "counts").
for (uword i = 0; i < vals.n_elem; ++i)
{
arma_debug_check((locs.at(0, i) >= n_rows), "SpMat::SpMat(): invalid row index");
arma_debug_check((locs.at(1, i) >= n_cols), "SpMat::SpMat(): invalid column index");
// Check ordering in debug mode.
if(i > 0)
{
arma_debug_check
(
( (locs.at(1, i) < locs.at(1, i - 1)) || (locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) < locs.at(0, i - 1)) ),
"SpMat::SpMat(): out of order points; either pass sort_locations = true or sort points in column-major ordering"
);
arma_debug_check((locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) == locs.at(0, i - 1)), "SpMat::SpMat(): two identical point locations in list");
}
access::rw(values[i]) = vals[i];
access::rw(row_indices[i]) = locs.at(0, i);
access::rw(col_ptrs[locs.at(1, i) + 1])++;
}
}
// Now fix the column pointers.
for (uword i = 0; i <= n_cols; ++i)
{
access::rw(col_ptrs[i + 1]) += col_ptrs[i];
}
}
/**
* Simple operators with plain values. These operate on every value in the
* matrix, so a sparse matrix += 1 will turn all those zeroes into ones. Be
* careful and make sure that's what you really want!
*/
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const eT val)
{
arma_extra_debug_sigprint();
// Resize to 1x1 then set that to the right value.
init(1, 1); // Sets col_ptrs to 0.
mem_resize(1); // One element.
// Manually set element.
access::rw(values[0]) = val;
access::rw(row_indices[0]) = 0;
access::rw(col_ptrs[1]) = 1;
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator*=(const eT val)
{
arma_extra_debug_sigprint();
if(val == eT(0))
{
// Everything will be zero.
init(n_rows, n_cols);
return *this;
}
arrayops::inplace_mul( access::rwp(values), val, n_nonzero );
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator/=(const eT val)
{
arma_extra_debug_sigprint();
arma_debug_check( (val == eT(0)), "element-wise division: division by zero" );
arrayops::inplace_div( access::rwp(values), val, n_nonzero );
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const SpMat<eT>& x)
{
arma_extra_debug_sigprint();
init(x);
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator+=(const SpMat<eT>& x)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "addition");
// Iterate over nonzero values of other matrix.
for (const_iterator it = x.begin(); it != x.end(); it++)
{
get_value(it.row(), it.col()) += *it;
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator-=(const SpMat<eT>& x)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "subtraction");
// Iterate over nonzero values of other matrix.
for (const_iterator it = x.begin(); it != x.end(); it++)
{
get_value(it.row(), it.col()) -= *it;
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator*=(const SpMat<eT>& y)
{
arma_extra_debug_sigprint();
arma_debug_assert_mul_size(n_rows, n_cols, y.n_rows, y.n_cols, "matrix multiplication");
SpMat<eT> z;
z = (*this) * y;
steal_mem(z);
return *this;
}
// This is in-place element-wise matrix multiplication.
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator%=(const SpMat<eT>& x)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise multiplication");
// We can do this with two iterators rather simply.
iterator it = begin();
const_iterator x_it = x.begin();
while (it != end() && x_it != x.end())
{
// One of these will be further advanced than the other (or they will be at the same place).
if ((it.row() == x_it.row()) && (it.col() == x_it.col()))
{
// There is an element at this place in both matrices. Multiply.
(*it) *= (*x_it);
// Now move on to the next position.
it++;
x_it++;
}
else if ((it.col() < x_it.col()) || ((it.col() == x_it.col()) && (it.row() < x_it.row())))
{
// This case is when our matrix has an element which the other matrix does not.
// So we must delete this element.
(*it) = 0;
// Because we have deleted the element, we now have to manually set the position...
it.internal_pos--;
// Now we can increment our iterator.
it++;
}
else /* if our iterator is ahead of the other matrix */
{
// In this case we don't need to set anything to 0; our element is already 0.
// We can just increment the iterator of the other matrix.
x_it++;
}
}
// If we are not at the end of our matrix, then we must terminate the remaining elements.
while (it != end())
{
(*it) = 0;
// Hack to manually set the position right...
it.internal_pos--;
it++; // ...and then an increment.
}
return *this;
}
// Construct a complex matrix out of two non-complex matrices
template<typename eT>
template<typename T1, typename T2>
inline
SpMat<eT>::SpMat
(
const SpBase<typename SpMat<eT>::pod_type, T1>& A,
const SpBase<typename SpMat<eT>::pod_type, T2>& B
)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL) // extra element is set when mem_resize is called
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type T;
// Make sure eT is complex and T is not (compile-time check).
arma_type_check(( is_complex<eT>::value == false ));
arma_type_check(( is_complex< T>::value == true ));
// Compile-time abort if types are not compatible.
arma_type_check(( is_same_type< std::complex<T>, eT >::value == false ));
// Hack until Proxy supports sparse matrices: assume get_ref() is SpMat<> (at
// the moment it must be).
const SpMat<T>& X = A.get_ref();
const SpMat<T>& Y = B.get_ref();
arma_assert_same_size(X.n_rows, X.n_cols, Y.n_rows, Y.n_cols, "SpMat()");
const uword l_n_rows = X.n_rows;
const uword l_n_cols = X.n_cols;
// Set size of matrix correctly.
init(l_n_rows, l_n_cols);
mem_resize(n_unique(X, Y, op_n_unique_count()));
// Now on a second iteration, fill it.
typename SpMat<T>::const_iterator x_it = X.begin();
typename SpMat<T>::const_iterator y_it = Y.begin();
uword cur_pos = 0;
while ((x_it != X.end()) || (y_it != Y.end()))
{
if(x_it == y_it) // if we are at the same place
{
access::rw(values[cur_pos]) = std::complex<T>((T) *x_it, (T) *y_it);
access::rw(row_indices[cur_pos]) = x_it.row();
++access::rw(col_ptrs[x_it.col() + 1]);
++x_it;
++y_it;
}
else
{
if((x_it.col() < y_it.col()) || ((x_it.col() == y_it.col()) && (x_it.row() < y_it.row()))) // if y is closer to the end
{
access::rw(values[cur_pos]) = std::complex<T>((T) *x_it, T(0));
access::rw(row_indices[cur_pos]) = x_it.row();
++access::rw(col_ptrs[x_it.col() + 1]);
++x_it;
}
else // x is closer to the end
{
access::rw(values[cur_pos]) = std::complex<T>(T(0), (T) *y_it);
access::rw(row_indices[cur_pos]) = y_it.row();
++access::rw(col_ptrs[y_it.col() + 1]);
++y_it;
}
}
++cur_pos;
}
// Now fix the column pointers; they are supposed to be a sum.
for (uword c = 1; c <= n_cols; ++c)
{
access::rw(col_ptrs[c]) += col_ptrs[c - 1];
}
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator/=(const SpMat<eT>& x)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise division");
// If you use this method, you are probably stupid or misguided, but for compatibility with Mat, we have implemented it anyway.
// We have to loop over every element, which is not good. In fact, it makes me physically sad to write this.
for(uword c = 0; c < n_cols; ++c)
{
for(uword r = 0; r < n_rows; ++r)
{
at(r, c) /= x.at(r, c);
}
}
return *this;
}
template<typename eT>
template<typename T1>
inline
SpMat<eT>::SpMat(const Base<eT, T1>& x)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL) // extra element is set when mem_resize is called in operator=()
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
(*this).operator=(x);
}
template<typename eT>
template<typename T1>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const Base<eT, T1>& x)
{
arma_extra_debug_sigprint();
const Proxy<T1> p(x.get_ref());
const uword x_n_rows = p.get_n_rows();
const uword x_n_cols = p.get_n_cols();
const uword x_n_elem = p.get_n_elem();
init(x_n_rows, x_n_cols);
// Count number of nonzero elements in base object.
uword n = 0;
if(Proxy<T1>::prefer_at_accessor == true)
{
for(uword j = 0; j < x_n_cols; ++j)
for(uword i = 0; i < x_n_rows; ++i)
{
if(p.at(i, j) != eT(0)) { ++n; }
}
}
else
{
for(uword i = 0; i < x_n_elem; ++i)
{
if(p[i] != eT(0)) { ++n; }
}
}
mem_resize(n);
// Now the memory is resized correctly; add nonzero elements.
n = 0;
for(uword j = 0; j < x_n_cols; ++j)
for(uword i = 0; i < x_n_rows; ++i)
{
const eT val = p.at(i, j);
if(val != eT(0))
{
access::rw(values[n]) = val;
access::rw(row_indices[n]) = i;
access::rw(col_ptrs[j + 1])++;
++n;
}
}
// Sum column counts to be column pointers.
for(uword c = 1; c <= n_cols; ++c)
{
access::rw(col_ptrs[c]) += col_ptrs[c - 1];
}
return *this;
}
template<typename eT>
template<typename T1>
inline
const SpMat<eT>&
SpMat<eT>::operator*=(const Base<eT, T1>& y)
{
arma_extra_debug_sigprint();
const Proxy<T1> p(y.get_ref());
arma_debug_assert_mul_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "matrix multiplication");
// We assume the matrix structure is such that we will end up with a sparse
// matrix. Assuming that every entry in the dense matrix is nonzero (which is
// a fairly valid assumption), each row with any nonzero elements in it (in this
// matrix) implies an entire nonzero column. Therefore, we iterate over all
// the row_indices and count the number of rows with any elements in them
// (using the quasi-linked-list idea from SYMBMM -- see operator_times.hpp).
podarray<uword> index(n_rows);
index.fill(n_rows); // Fill with invalid links.
uword last_index = n_rows + 1;
for(uword i = 0; i < n_nonzero; ++i)
{
if(index[row_indices[i]] == n_rows)
{
index[row_indices[i]] = last_index;
last_index = row_indices[i];
}
}
// Now count the number of rows which have nonzero elements.
uword nonzero_rows = 0;
while(last_index != n_rows + 1)
{
++nonzero_rows;
last_index = index[last_index];
}
SpMat<eT> z(n_rows, p.get_n_cols());
z.mem_resize(nonzero_rows * p.get_n_cols()); // upper bound on size
// Now we have to fill all the elements using a modification of the NUMBMM algorithm.
uword cur_pos = 0;
podarray<eT> partial_sums(n_rows);
partial_sums.zeros();
for(uword lcol = 0; lcol < n_cols; ++lcol)
{
const_iterator it = begin();
while(it != end())
{
const eT value = (*it);
partial_sums[it.row()] += (value * p.at(it.col(), lcol));
++it;
}
// Now add all partial sums to the matrix.
for(uword i = 0; i < n_rows; ++i)
{
if(partial_sums[i] != eT(0))
{
access::rw(z.values[cur_pos]) = partial_sums[i];
access::rw(z.row_indices[cur_pos]) = i;
++access::rw(z.col_ptrs[lcol + 1]);
//printf("colptr %d now %d\n", lcol + 1, z.col_ptrs[lcol + 1]);
++cur_pos;
partial_sums[i] = 0; // Would it be faster to do this in batch later?
}
}
}
// Now fix the column pointers.
for(uword c = 1; c <= z.n_cols; ++c)
{
access::rw(z.col_ptrs[c]) += z.col_ptrs[c - 1];
}
// Resize to final correct size.
z.mem_resize(z.col_ptrs[z.n_cols]);
// Now take the memory of the temporary matrix.
steal_mem(z);
return *this;
}
/**
* Don't use this function. It's not mathematically well-defined and wastes
* cycles to trash all your data. This is dumb.
*/
template<typename eT>
template<typename T1>
inline
const SpMat<eT>&
SpMat<eT>::operator/=(const Base<eT, T1>& x)
{
arma_extra_debug_sigprint();
SpMat<eT> tmp = (*this) / x.get_ref();
steal_mem(tmp);
return *this;
}
template<typename eT>
template<typename T1>
inline
const SpMat<eT>&
SpMat<eT>::operator%=(const Base<eT, T1>& x)
{
arma_extra_debug_sigprint();
const Proxy<T1> p(x.get_ref());
arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise multiplication");
// Count the number of elements we will need.
SpMat<eT> tmp(n_rows, n_cols);
const_iterator it = begin();
uword new_n_nonzero = 0;
while(it != end())
{
// prefer_at_accessor == false can't save us any work here
if(((*it) * p.at(it.row(), it.col())) != eT(0))
{
++new_n_nonzero;
}
++it;
}
// Resize.
tmp.mem_resize(new_n_nonzero);
const_iterator c_it = begin();
uword cur_pos = 0;
while(c_it != end())
{
// prefer_at_accessor == false can't save us any work here
const eT val = (*c_it) * p.at(c_it.row(), c_it.col());
if(val != eT(0))
{
access::rw(tmp.values[cur_pos]) = val;
access::rw(tmp.row_indices[cur_pos]) = c_it.row();
++access::rw(tmp.col_ptrs[c_it.col() + 1]);
++cur_pos;
}
++c_it;
}
// Fix column pointers.
for(uword c = 1; c <= n_cols; ++c)
{
access::rw(tmp.col_ptrs[c]) += tmp.col_ptrs[c - 1];
}
steal_mem(tmp);
return *this;
}
/**
* Functions on subviews.
*/
template<typename eT>
inline
SpMat<eT>::SpMat(const SpSubview<eT>& X)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL) // extra element added when mem_resize is called
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
(*this).operator=(X);
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const SpSubview<eT>& X)
{
arma_extra_debug_sigprint();
const uword in_n_cols = X.n_cols;
const uword in_n_rows = X.n_rows;
const bool alias = (this == &(X.m));
if(alias == false)
{
init(in_n_rows, in_n_cols);
const uword x_n_nonzero = X.n_nonzero;
mem_resize(x_n_nonzero);
typename SpSubview<eT>::const_iterator it = X.begin();
while(it != X.end())
{
access::rw(row_indices[it.pos()]) = it.row();
access::rw(values[it.pos()]) = (*it);
++access::rw(col_ptrs[it.col() + 1]);
++it;
}
// Now sum column pointers.
for(uword c = 1; c <= n_cols; ++c)
{
access::rw(col_ptrs[c]) += col_ptrs[c - 1];
}
}
else
{
// Create it in a temporary.
SpMat<eT> tmp(X);
steal_mem(tmp);
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator+=(const SpSubview<eT>& X)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, X.n_rows, X.n_cols, "addition");
typename SpSubview<eT>::const_iterator it = X.begin();
while(it != X.end())
{
at(it.row(), it.col()) += (*it);
++it;
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator-=(const SpSubview<eT>& X)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, X.n_rows, X.n_cols, "subtraction");
typename SpSubview<eT>::const_iterator it = X.begin();
while(it != X.end())
{
at(it.row(), it.col()) -= (*it);
++it;
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator*=(const SpSubview<eT>& y)
{
arma_extra_debug_sigprint();
arma_debug_assert_mul_size(n_rows, n_cols, y.n_rows, y.n_cols, "matrix multiplication");
// Cannot be done in-place (easily).
SpMat<eT> z = (*this) * y;
steal_mem(z);
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator%=(const SpSubview<eT>& x)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise multiplication");
iterator it = begin();
typename SpSubview<eT>::const_iterator xit = x.begin();
while((it != end()) || (xit != x.end()))
{
if((xit.row() == it.row()) && (xit.col() == it.col()))
{
(*it) *= (*xit);
++it;
++xit;
}
else
{
if((xit.col() > it.col()) || ((xit.col() == it.col()) && (xit.row() > it.row())))
{
// xit is "ahead"
(*it) = eT(0); // erase element; x has a zero here
it.internal_pos--; // update iterator so it still works
++it;
}
else
{
// it is "ahead"
++xit;
}
}
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator/=(const SpSubview<eT>& x)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise division");
// There is no pretty way to do this.
for(uword elem = 0; elem < n_elem; elem++)
{
at(elem) /= x(elem);
}
return *this;
}
/**
* Operators on regular subviews.
*/
template<typename eT>
inline
SpMat<eT>::SpMat(const subview<eT>& x)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL) // extra value set in operator=()
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
(*this).operator=(x);
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const subview<eT>& x)
{
arma_extra_debug_sigprint();
const uword x_n_rows = x.n_rows;
const uword x_n_cols = x.n_cols;
// Set the size correctly.
init(x_n_rows, x_n_cols);
// Count number of nonzero elements.
uword n = 0;
for(uword c = 0; c < x_n_cols; ++c)
{
for(uword r = 0; r < x_n_rows; ++r)
{
if(x.at(r, c) != eT(0))
{
++n;
}
}
}
// Resize memory appropriately.
mem_resize(n);
n = 0;
for(uword c = 0; c < x_n_cols; ++c)
{
for(uword r = 0; r < x_n_rows; ++r)
{
const eT val = x.at(r, c);
if(val != eT(0))
{
access::rw(values[n]) = val;
access::rw(row_indices[n]) = r;
++access::rw(col_ptrs[c + 1]);
++n;
}
}
}
// Fix column counts into column pointers.
for(uword c = 1; c <= n_cols; ++c)
{
access::rw(col_ptrs[c]) += col_ptrs[c - 1];
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator+=(const subview<eT>& x)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "addition");
// Loop over every element. This could probably be written in a more
// efficient way, by calculating the number of nonzero elements the output
// matrix will have, allocating the memory correctly, and then filling the
// matrix correctly. However... for now, this works okay.
for(uword lcol = 0; lcol < n_cols; ++lcol)
for(uword lrow = 0; lrow < n_rows; ++lrow)
{
at(lrow, lcol) += x.at(lrow, lcol);
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator-=(const subview<eT>& x)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "subtraction");
// Loop over every element.
for(uword lcol = 0; lcol < n_cols; ++lcol)
for(uword lrow = 0; lrow < n_rows; ++lrow)
{
at(lrow, lcol) -= x.at(lrow, lcol);
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator*=(const subview<eT>& y)
{
arma_extra_debug_sigprint();
arma_debug_assert_mul_size(n_rows, n_cols, y.n_rows, y.n_cols, "matrix multiplication");
SpMat<eT> z(n_rows, y.n_cols);
// Performed in the same fashion as operator*=(SpMat).
for (const_row_iterator x_row_it = begin_row(); x_row_it.pos() < n_nonzero; ++x_row_it)
{
for (uword lcol = 0; lcol < y.n_cols; ++lcol)
{
// At this moment in the loop, we are calculating anything that is contributed to by *x_row_it and *y_col_it.
// Given that our position is x_ab and y_bc, there will only be a contribution if x.col == y.row, and that
// contribution will be in location z_ac.
z.at(x_row_it.row, lcol) += (*x_row_it) * y.at(x_row_it.col, lcol);
}
}
steal_mem(z);
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator%=(const subview<eT>& x)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise multiplication");
// Loop over every element.
for(uword lcol = 0; lcol < n_cols; ++lcol)
for(uword lrow = 0; lrow < n_rows; ++lrow)
{
at(lrow, lcol) *= x.at(lrow, lcol);
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::operator/=(const subview<eT>& x)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise division");
// Loop over every element.
for(uword lcol = 0; lcol < n_cols; ++lcol)
for(uword lrow = 0; lrow < n_rows; ++lrow)
{
at(lrow, lcol) /= x.at(lrow, lcol);
}
return *this;
}
template<typename eT>
template<typename T1, typename spop_type>
inline
SpMat<eT>::SpMat(const SpOp<T1, spop_type>& X)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL) // set in application of sparse operation
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
spop_type::apply(*this, X);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const SpOp<T1, spop_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
spop_type::apply(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator+=(const SpOp<T1, spop_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
const SpMat<eT> m(X);
return (*this).operator+=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator-=(const SpOp<T1, spop_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
const SpMat<eT> m(X);
return (*this).operator-=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator*=(const SpOp<T1, spop_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
const SpMat<eT> m(X);
return (*this).operator*=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator%=(const SpOp<T1, spop_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
const SpMat<eT> m(X);
return (*this).operator%=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator/=(const SpOp<T1, spop_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
const SpMat<eT> m(X);
return (*this).operator/=(m);
}
template<typename eT>
template<typename T1, typename T2, typename spglue_type>
inline
SpMat<eT>::SpMat(const SpGlue<T1, T2, spglue_type>& X)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL) // extra element set in application of sparse glue
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
spglue_type::apply(*this, X);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
SpMat<eT>::SpMat(const mtSpOp<eT, T1, spop_type>& X)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL) // extra element set in application of sparse glue
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
spop_type::apply(*this, X);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
spop_type::apply(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator+=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
const SpMat<eT> m(X);
return (*this).operator+=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator-=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
const SpMat<eT> m(X);
return (*this).operator-=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator*=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
const SpMat<eT> m(X);
return (*this).operator*=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator%=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
const SpMat<eT> m(X);
return (*this).operator%=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator/=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
const SpMat<eT> m(X);
return (*this).operator/=(m);
}
template<typename eT>
template<typename T1, typename T2, typename spglue_type>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const SpGlue<T1, T2, spglue_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
spglue_type::apply(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename T2, typename spglue_type>
inline
const SpMat<eT>&
SpMat<eT>::operator+=(const SpGlue<T1, T2, spglue_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
const SpMat<eT> m(X);
return (*this).operator+=(m);
}
template<typename eT>
template<typename T1, typename T2, typename spglue_type>
inline
const SpMat<eT>&
SpMat<eT>::operator-=(const SpGlue<T1, T2, spglue_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
const SpMat<eT> m(X);
return (*this).operator-=(m);
}
template<typename eT>
template<typename T1, typename T2, typename spglue_type>
inline
const SpMat<eT>&
SpMat<eT>::operator*=(const SpGlue<T1, T2, spglue_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
const SpMat<eT> m(X);
return (*this).operator*=(m);
}
template<typename eT>
template<typename T1, typename T2, typename spglue_type>
inline
const SpMat<eT>&
SpMat<eT>::operator%=(const SpGlue<T1, T2, spglue_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
const SpMat<eT> m(X);
return (*this).operator%=(m);
}
template<typename eT>
template<typename T1, typename T2, typename spglue_type>
inline
const SpMat<eT>&
SpMat<eT>::operator/=(const SpGlue<T1, T2, spglue_type>& X)
{
arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false ));
const SpMat<eT> m(X);
return (*this).operator/=(m);
}
template<typename eT>
arma_inline
SpSubview<eT>
SpMat<eT>::row(const uword row_num)
{
arma_extra_debug_sigprint();
arma_debug_check(row_num >= n_rows, "SpMat::row(): out of bounds");
return SpSubview<eT>(*this, row_num, 0, 1, n_cols);
}
template<typename eT>
arma_inline
const SpSubview<eT>
SpMat<eT>::row(const uword row_num) const
{
arma_extra_debug_sigprint();
arma_debug_check(row_num >= n_rows, "SpMat::row(): out of bounds");
return SpSubview<eT>(*this, row_num, 0, 1, n_cols);
}
template<typename eT>
inline
SpSubview<eT>
SpMat<eT>::operator()(const uword row_num, const span& col_span)
{
arma_extra_debug_sigprint();
const bool col_all = col_span.whole;
const uword local_n_cols = n_cols;
const uword in_col1 = col_all ? 0 : col_span.a;
const uword in_col2 = col_span.b;
const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
arma_debug_check
(
(row_num >= n_rows)
||
( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
,
"SpMat::operator(): indices out of bounds or incorrectly used"
);
return SpSubview<eT>(*this, row_num, in_col1, 1, submat_n_cols);
}
template<typename eT>
inline
const SpSubview<eT>
SpMat<eT>::operator()(const uword row_num, const span& col_span) const
{
arma_extra_debug_sigprint();
const bool col_all = col_span.whole;
const uword local_n_cols = n_cols;
const uword in_col1 = col_all ? 0 : col_span.a;
const uword in_col2 = col_span.b;
const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
arma_debug_check
(
(row_num >= n_rows)
||
( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
,
"SpMat::operator(): indices out of bounds or incorrectly used"
);
return SpSubview<eT>(*this, row_num, in_col1, 1, submat_n_cols);
}
template<typename eT>
arma_inline
SpSubview<eT>
SpMat<eT>::col(const uword col_num)
{
arma_extra_debug_sigprint();
arma_debug_check(col_num >= n_cols, "SpMat::col(): out of bounds");
return SpSubview<eT>(*this, 0, col_num, n_rows, 1);
}
template<typename eT>
arma_inline
const SpSubview<eT>
SpMat<eT>::col(const uword col_num) const
{
arma_extra_debug_sigprint();
arma_debug_check(col_num >= n_cols, "SpMat::col(): out of bounds");
return SpSubview<eT>(*this, 0, col_num, n_rows, 1);
}
template<typename eT>
inline
SpSubview<eT>
SpMat<eT>::operator()(const span& row_span, const uword col_num)
{
arma_extra_debug_sigprint();
const bool row_all = row_span.whole;
const uword local_n_rows = n_rows;
const uword in_row1 = row_all ? 0 : row_span.a;
const uword in_row2 = row_span.b;
const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
arma_debug_check
(
(col_num >= n_cols)
||
( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
,
"SpMat::operator(): indices out of bounds or incorrectly used"
);
return SpSubview<eT>(*this, in_row1, col_num, submat_n_rows, 1);
}
template<typename eT>
inline
const SpSubview<eT>
SpMat<eT>::operator()(const span& row_span, const uword col_num) const
{
arma_extra_debug_sigprint();
const bool row_all = row_span.whole;
const uword local_n_rows = n_rows;
const uword in_row1 = row_all ? 0 : row_span.a;
const uword in_row2 = row_span.b;
const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
arma_debug_check
(
(col_num >= n_cols)
||
( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
,
"SpMat::operator(): indices out of bounds or incorrectly used"
);
return SpSubview<eT>(*this, in_row1, col_num, submat_n_rows, 1);
}
/**
* Swap in_row1 with in_row2.
*/
template<typename eT>
inline
void
SpMat<eT>::swap_rows(const uword in_row1, const uword in_row2)
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_row1 >= n_rows) || (in_row2 >= n_rows),
"SpMat::swap_rows(): out of bounds"
);
// Sanity check.
if (in_row1 == in_row2)
{
return;
}
// The easier way to do this, instead of collecting all the elements in one row and then swapping with the other, will be
// to iterate over each column of the matrix (since we store in column-major format) and then swap the two elements in the two rows at that time.
// We will try to avoid using the at() call since it is expensive, instead preferring to use an iterator to track our position.
uword col1 = (in_row1 < in_row2) ? in_row1 : in_row2;
uword col2 = (in_row1 < in_row2) ? in_row2 : in_row1;
for (uword lcol = 0; lcol < n_cols; lcol++)
{
// If there is nothing in this column we can ignore it.
if (col_ptrs[lcol] == col_ptrs[lcol + 1])
{
continue;
}
// These will represent the positions of the items themselves.
uword loc1 = n_nonzero + 1;
uword loc2 = n_nonzero + 1;
for (uword search_pos = col_ptrs[lcol]; search_pos < col_ptrs[lcol + 1]; search_pos++)
{
if (row_indices[search_pos] == col1)
{
loc1 = search_pos;
}
if (row_indices[search_pos] == col2)
{
loc2 = search_pos;
break; // No need to look any further.
}
}
// There are four cases: we found both elements; we found one element (loc1); we found one element (loc2); we found zero elements.
// If we found zero elements no work needs to be done and we can continue to the next column.
if ((loc1 != (n_nonzero + 1)) && (loc2 != (n_nonzero + 1)))
{
// This is an easy case: just swap the values. No index modifying necessary.
eT tmp = values[loc1];
access::rw(values[loc1]) = values[loc2];
access::rw(values[loc2]) = tmp;
}
else if (loc1 != (n_nonzero + 1)) // We only found loc1 and not loc2.
{
// We need to find the correct place to move our value to. It will be forward (not backwards) because in_row2 > in_row1.
// Each iteration of the loop swaps the current value (loc1) with (loc1 + 1); in this manner we move our value down to where it should be.
while (((loc1 + 1) < col_ptrs[lcol + 1]) && (row_indices[loc1 + 1] < in_row2))
{
// Swap both the values and the indices. The column should not change.
eT tmp = values[loc1];
access::rw(values[loc1]) = values[loc1 + 1];
access::rw(values[loc1 + 1]) = tmp;
uword tmp_index = row_indices[loc1];
access::rw(row_indices[loc1]) = row_indices[loc1 + 1];
access::rw(row_indices[loc1 + 1]) = tmp_index;
loc1++; // And increment the counter.
}
// Now set the row index correctly.
access::rw(row_indices[loc1]) = in_row2;
}
else if (loc2 != (n_nonzero + 1))
{
// We need to find the correct place to move our value to. It will be backwards (not forwards) because in_row1 < in_row2.
// Each iteration of the loop swaps the current value (loc2) with (loc2 - 1); in this manner we move our value up to where it should be.
while (((loc2 - 1) >= col_ptrs[lcol]) && (row_indices[loc2 - 1] > in_row1))
{
// Swap both the values and the indices. The column should not change.
eT tmp = values[loc2];
access::rw(values[loc2]) = values[loc2 - 1];
access::rw(values[loc2 - 1]) = tmp;
uword tmp_index = row_indices[loc2];
access::rw(row_indices[loc2]) = row_indices[loc2 - 1];
access::rw(row_indices[loc2 - 1]) = tmp_index;
loc2--; // And decrement the counter.
}
// Now set the row index correctly.
access::rw(row_indices[loc2]) = in_row1;
}
/* else: no need to swap anything; both values are zero */
}
}
/**
* Swap in_col1 with in_col2.
*/
template<typename eT>
inline
void
SpMat<eT>::swap_cols(const uword in_col1, const uword in_col2)
{
arma_extra_debug_sigprint();
// slow but works
for(uword lrow = 0; lrow < n_rows; ++lrow)
{
eT tmp = at(lrow, in_col1);
at(lrow, in_col1) = at(lrow, in_col2);
at(lrow, in_col2) = tmp;
}
}
/**
* Remove the row row_num.
*/
template<typename eT>
inline
void
SpMat<eT>::shed_row(const uword row_num)
{
arma_extra_debug_sigprint();
arma_debug_check (row_num >= n_rows, "SpMat::shed_row(): out of bounds");
shed_rows (row_num, row_num);
}
/**
* Remove the column col_num.
*/
template<typename eT>
inline
void
SpMat<eT>::shed_col(const uword col_num)
{
arma_extra_debug_sigprint();
arma_debug_check (col_num >= n_cols, "SpMat::shed_col(): out of bounds");
shed_cols(col_num, col_num);
}
/**
* Remove all rows between (and including) in_row1 and in_row2.
*/
template<typename eT>
inline
void
SpMat<eT>::shed_rows(const uword in_row1, const uword in_row2)
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_row1 > in_row2) || (in_row2 >= n_rows),
"SpMat::shed_rows(): indices out of bounds or incorectly used"
);
uword i, j;
// Store the length of values
uword vlength = n_nonzero;
// Store the length of col_ptrs
uword clength = n_cols + 1;
// This is O(n * n_cols) and inplace, there may be a faster way, though.
for (i = 0, j = 0; i < vlength; ++i)
{
// Store the row of the ith element.
const uword lrow = row_indices[i];
// Is the ith element in the range of rows we want to remove?
if (lrow >= in_row1 && lrow <= in_row2)
{
// Increment our "removed elements" counter.
++j;
// Adjust the values of col_ptrs each time we remove an element.
// Basically, the length of one column reduces by one, and everything to
// its right gets reduced by one to represent all the elements being
// shifted to the left by one.
for(uword k = 0; k < clength; ++k)
{
if (col_ptrs[k] > (i - j + 1))
{
--access::rw(col_ptrs[k]);
}
}
}
else
{
// We shift the element we checked to the left by how many elements
// we have removed.
// j = 0 until we remove the first element.
if (j != 0)
{
access::rw(row_indices[i - j]) = (lrow > in_row2) ? (lrow - (in_row2 - in_row1 + 1)) : lrow;
access::rw(values[i - j]) = values[i];
}
}
}
// j is the number of elements removed.
// Shrink the vectors. This will copy the memory.
mem_resize(n_nonzero - j);
// Adjust row and element counts.
access::rw(n_rows) = n_rows - (in_row2 - in_row1) - 1;
access::rw(n_elem) = n_rows * n_cols;
}
/**
* Remove all columns between (and including) in_col1 and in_col2.
*/
template<typename eT>
inline
void
SpMat<eT>::shed_cols(const uword in_col1, const uword in_col2)
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_col1 > in_col2) || (in_col2 >= n_cols),
"SpMat::shed_cols(): indices out of bounds or incorrectly used"
);
// First we find the locations in values and row_indices for the column entries.
uword col_beg = col_ptrs[in_col1];
uword col_end = col_ptrs[in_col2 + 1];
// Then we find the number of entries in the column.
uword diff = col_end - col_beg;
if (diff > 0)
{
eT* new_values = memory::acquire_chunked<eT> (n_nonzero - diff);
uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero - diff);
// Copy first part.
if (col_beg != 0)
{
arrayops::copy(new_values, values, col_beg);
arrayops::copy(new_row_indices, row_indices, col_beg);
}
// Copy second part.
if (col_end != n_nonzero)
{
arrayops::copy(new_values + col_beg, values + col_end, n_nonzero - col_end);
arrayops::copy(new_row_indices + col_beg, row_indices + col_end, n_nonzero - col_end);
}
memory::release(values);
memory::release(row_indices);
access::rw(values) = new_values;
access::rw(row_indices) = new_row_indices;
// Update counts and such.
access::rw(n_nonzero) -= diff;
}
// Update column pointers.
const uword new_n_cols = n_cols - ((in_col2 - in_col1) + 1);
uword* new_col_ptrs = memory::acquire<uword>(new_n_cols + 2);
new_col_ptrs[new_n_cols + 1] = std::numeric_limits<uword>::max();
// Copy first set of columns (no manipulation required).
if (in_col1 != 0)
{
arrayops::copy(new_col_ptrs, col_ptrs, in_col1);
}
// Copy second set of columns (manipulation required).
uword cur_col = in_col1;
for (uword i = in_col2 + 1; i <= n_cols; ++i, ++cur_col)
{
new_col_ptrs[cur_col] = col_ptrs[i] - diff;
}
memory::release(col_ptrs);
access::rw(col_ptrs) = new_col_ptrs;
// We update the element and column counts, and we're done.
access::rw(n_cols) = new_n_cols;
access::rw(n_elem) = n_cols * n_rows;
}
template<typename eT>
arma_inline
SpSubview<eT>
SpMat<eT>::rows(const uword in_row1, const uword in_row2)
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_row1 > in_row2) || (in_row2 >= n_rows),
"SpMat::rows(): indices out of bounds or incorrectly used"
);
const uword subview_n_rows = in_row2 - in_row1 + 1;
return SpSubview<eT>(*this, in_row1, 0, subview_n_rows, n_cols);
}
template<typename eT>
arma_inline
const SpSubview<eT>
SpMat<eT>::rows(const uword in_row1, const uword in_row2) const
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_row1 > in_row2) || (in_row2 >= n_rows),
"SpMat::rows(): indices out of bounds or incorrectly used"
);
const uword subview_n_rows = in_row2 - in_row1 + 1;
return SpSubview<eT>(*this, in_row1, 0, subview_n_rows, n_cols);
}
template<typename eT>
arma_inline
SpSubview<eT>
SpMat<eT>::cols(const uword in_col1, const uword in_col2)
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_col1 > in_col2) || (in_col2 >= n_cols),
"SpMat::cols(): indices out of bounds or incorrectly used"
);
const uword subview_n_cols = in_col2 - in_col1 + 1;
return SpSubview<eT>(*this, 0, in_col1, n_rows, subview_n_cols);
}
template<typename eT>
arma_inline
const SpSubview<eT>
SpMat<eT>::cols(const uword in_col1, const uword in_col2) const
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_col1 > in_col2) || (in_col2 >= n_cols),
"SpMat::cols(): indices out of bounds or incorrectly used"
);
const uword subview_n_cols = in_col2 - in_col1 + 1;
return SpSubview<eT>(*this, 0, in_col1, n_rows, subview_n_cols);
}
template<typename eT>
arma_inline
SpSubview<eT>
SpMat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2)
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
"SpMat::submat(): indices out of bounds or incorrectly used"
);
const uword subview_n_rows = in_row2 - in_row1 + 1;
const uword subview_n_cols = in_col2 - in_col1 + 1;
return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_cols);
}
template<typename eT>
arma_inline
const SpSubview<eT>
SpMat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
"SpMat::submat(): indices out of bounds or incorrectly used"
);
const uword subview_n_rows = in_row2 - in_row1 + 1;
const uword subview_n_cols = in_col2 - in_col1 + 1;
return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_cols);
}
template<typename eT>
inline
SpSubview<eT>
SpMat<eT>::submat (const span& row_span, const span& col_span)
{
arma_extra_debug_sigprint();
const bool row_all = row_span.whole;
const bool col_all = col_span.whole;
const uword local_n_rows = n_rows;
const uword local_n_cols = n_cols;
const uword in_row1 = row_all ? 0 : row_span.a;
const uword in_row2 = row_span.b;
const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
const uword in_col1 = col_all ? 0 : col_span.a;
const uword in_col2 = col_span.b;
const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
arma_debug_check
(
( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
||
( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
,
"SpMat::submat(): indices out of bounds or incorrectly used"
);
return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_cols);
}
template<typename eT>
inline
const SpSubview<eT>
SpMat<eT>::submat (const span& row_span, const span& col_span) const
{
arma_extra_debug_sigprint();
const bool row_all = row_span.whole;
const bool col_all = col_span.whole;
const uword local_n_rows = n_rows;
const uword local_n_cols = n_cols;
const uword in_row1 = row_all ? 0 : row_span.a;
const uword in_row2 = row_span.b;
const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
const uword in_col1 = col_all ? 0 : col_span.a;
const uword in_col2 = col_span.b;
const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
arma_debug_check
(
( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
||
( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
,
"SpMat::submat(): indices out of bounds or incorrectly used"
);
return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_cols);
}
template<typename eT>
inline
SpSubview<eT>
SpMat<eT>::operator()(const span& row_span, const span& col_span)
{
arma_extra_debug_sigprint();
return submat(row_span, col_span);
}
template<typename eT>
inline
const SpSubview<eT>
SpMat<eT>::operator()(const span& row_span, const span& col_span) const
{
arma_extra_debug_sigprint();
return submat(row_span, col_span);
}
/**
* Element access; acces the i'th element (works identically to the Mat accessors).
* If there is nothing at element i, 0 is returned.
*
* @param i Element to access.
*/
template<typename eT>
arma_inline
arma_warn_unused
SpValProxy<SpMat<eT> >
SpMat<eT>::operator[](const uword i)
{
return get_value(i);
}
template<typename eT>
arma_inline
arma_warn_unused
eT
SpMat<eT>::operator[](const uword i) const
{
return get_value(i);
}
template<typename eT>
arma_inline
arma_warn_unused
SpValProxy<SpMat<eT> >
SpMat<eT>::at(const uword i)
{
return get_value(i);
}
template<typename eT>
arma_inline
arma_warn_unused
eT
SpMat<eT>::at(const uword i) const
{
return get_value(i);
}
template<typename eT>
arma_inline
arma_warn_unused
SpValProxy<SpMat<eT> >
SpMat<eT>::operator()(const uword i)
{
arma_debug_check( (i >= n_elem), "SpMat::operator(): out of bounds");
return get_value(i);
}
template<typename eT>
arma_inline
arma_warn_unused
eT
SpMat<eT>::operator()(const uword i) const
{
arma_debug_check( (i >= n_elem), "SpMat::operator(): out of bounds");
return get_value(i);
}
/**
* Element access; access the element at row in_rows and column in_col.
* If there is nothing at that position, 0 is returned.
*/
template<typename eT>
arma_inline
arma_warn_unused
SpValProxy<SpMat<eT> >
SpMat<eT>::at(const uword in_row, const uword in_col)
{
return get_value(in_row, in_col);
}
template<typename eT>
arma_inline
arma_warn_unused
eT
SpMat<eT>::at(const uword in_row, const uword in_col) const
{
return get_value(in_row, in_col);
}
template<typename eT>
arma_inline
arma_warn_unused
SpValProxy<SpMat<eT> >
SpMat<eT>::operator()(const uword in_row, const uword in_col)
{
arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "SpMat::operator(): out of bounds");
return get_value(in_row, in_col);
}
template<typename eT>
arma_inline
arma_warn_unused
eT
SpMat<eT>::operator()(const uword in_row, const uword in_col) const
{
arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "SpMat::operator(): out of bounds");
return get_value(in_row, in_col);
}
/**
* Check if matrix is empty (no size, no values).
*/
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::is_empty() const
{
return(n_elem == 0);
}
//! returns true if the object can be interpreted as a column or row vector
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::is_vec() const
{
return ( (n_rows == 1) || (n_cols == 1) );
}
//! returns true if the object can be interpreted as a row vector
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::is_rowvec() const
{
return (n_rows == 1);
}
//! returns true if the object can be interpreted as a column vector
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::is_colvec() const
{
return (n_cols == 1);
}
//! returns true if the object has the same number of non-zero rows and columnns
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::is_square() const
{
return (n_rows == n_cols);
}
//! returns true if all of the elements are finite
template<typename eT>
inline
arma_warn_unused
bool
SpMat<eT>::is_finite() const
{
for(uword i = 0; i < n_nonzero; i++)
{
if(arma_isfinite(values[i]) == false)
{
return false;
}
}
return true; // No infinite values.
}
//! returns true if the given index is currently in range
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::in_range(const uword i) const
{
return (i < n_elem);
}
//! returns true if the given start and end indices are currently in range
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::in_range(const span& x) const
{
arma_extra_debug_sigprint();
if(x.whole == true)
{
return true;
}
else
{
const uword a = x.a;
const uword b = x.b;
return ( (a <= b) && (b < n_elem) );
}
}
//! returns true if the given location is currently in range
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::in_range(const uword in_row, const uword in_col) const
{
return ( (in_row < n_rows) && (in_col < n_cols) );
}
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::in_range(const span& row_span, const uword in_col) const
{
arma_extra_debug_sigprint();
if(row_span.whole == true)
{
return (in_col < n_cols);
}
else
{
const uword in_row1 = row_span.a;
const uword in_row2 = row_span.b;
return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) );
}
}
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::in_range(const uword in_row, const span& col_span) const
{
arma_extra_debug_sigprint();
if(col_span.whole == true)
{
return (in_row < n_rows);
}
else
{
const uword in_col1 = col_span.a;
const uword in_col2 = col_span.b;
return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) );
}
}
template<typename eT>
arma_inline
arma_warn_unused
bool
SpMat<eT>::in_range(const span& row_span, const span& col_span) const
{
arma_extra_debug_sigprint();
const uword in_row1 = row_span.a;
const uword in_row2 = row_span.b;
const uword in_col1 = col_span.a;
const uword in_col2 = col_span.b;
const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) );
const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) );
return ( (rows_ok == true) && (cols_ok == true) );
}
template<typename eT>
inline
void
SpMat<eT>::impl_print(const std::string& extra_text) const
{
arma_extra_debug_sigprint();
if(extra_text.length() != 0)
{
const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width();
ARMA_DEFAULT_OSTREAM << extra_text << '\n';
ARMA_DEFAULT_OSTREAM.width(orig_width);
}
arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, true);
}
template<typename eT>
inline
void
SpMat<eT>::impl_print(std::ostream& user_stream, const std::string& extra_text) const
{
arma_extra_debug_sigprint();
if(extra_text.length() != 0)
{
const std::streamsize orig_width = user_stream.width();
user_stream << extra_text << '\n';
user_stream.width(orig_width);
}
arma_ostream::print(user_stream, *this, true);
}
template<typename eT>
inline
void
SpMat<eT>::impl_raw_print(const std::string& extra_text) const
{
arma_extra_debug_sigprint();
if(extra_text.length() != 0)
{
const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width();
ARMA_DEFAULT_OSTREAM << extra_text << '\n';
ARMA_DEFAULT_OSTREAM.width(orig_width);
}
arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, false);
}
template<typename eT>
inline
void
SpMat<eT>::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const
{
arma_extra_debug_sigprint();
if(extra_text.length() != 0)
{
const std::streamsize orig_width = user_stream.width();
user_stream << extra_text << '\n';
user_stream.width(orig_width);
}
arma_ostream::print(user_stream, *this, false);
}
/**
* Matrix printing, prepends supplied text.
* Prints 0 wherever no element exists.
*/
template<typename eT>
inline
void
SpMat<eT>::impl_print_dense(const std::string& extra_text) const
{
arma_extra_debug_sigprint();
if(extra_text.length() != 0)
{
const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width();
ARMA_DEFAULT_OSTREAM << extra_text << '\n';
ARMA_DEFAULT_OSTREAM.width(orig_width);
}
arma_ostream::print_dense(ARMA_DEFAULT_OSTREAM, *this, true);
}
template<typename eT>
inline
void
SpMat<eT>::impl_print_dense(std::ostream& user_stream, const std::string& extra_text) const
{
arma_extra_debug_sigprint();
if(extra_text.length() != 0)
{
const std::streamsize orig_width = user_stream.width();
user_stream << extra_text << '\n';
user_stream.width(orig_width);
}
arma_ostream::print_dense(user_stream, *this, true);
}
template<typename eT>
inline
void
SpMat<eT>::impl_raw_print_dense(const std::string& extra_text) const
{
arma_extra_debug_sigprint();
if(extra_text.length() != 0)
{
const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width();
ARMA_DEFAULT_OSTREAM << extra_text << '\n';
ARMA_DEFAULT_OSTREAM.width(orig_width);
}
arma_ostream::print_dense(ARMA_DEFAULT_OSTREAM, *this, false);
}
template<typename eT>
inline
void
SpMat<eT>::impl_raw_print_dense(std::ostream& user_stream, const std::string& extra_text) const
{
arma_extra_debug_sigprint();
if(extra_text.length() != 0)
{
const std::streamsize orig_width = user_stream.width();
user_stream << extra_text << '\n';
user_stream.width(orig_width);
}
arma_ostream::print_dense(user_stream, *this, false);
}
//! Set the size to the size of another matrix.
template<typename eT>
template<typename eT2>
inline
void
SpMat<eT>::copy_size(const SpMat<eT2>& m)
{
arma_extra_debug_sigprint();
init(m.n_rows, m.n_cols);
}
template<typename eT>
template<typename eT2>
inline
void
SpMat<eT>::copy_size(const Mat<eT2>& m)
{
arma_extra_debug_sigprint();
init(m.n_rows, m.n_cols);
}
/**
* Resize the matrix to a given size. The matrix will be resized to be a column vector (i.e. in_elem columns, 1 row).
*
* @param in_elem Number of elements to allow.
*/
template<typename eT>
inline
void
SpMat<eT>::set_size(const uword in_elem)
{
arma_extra_debug_sigprint();
// If this is a row vector, we resize to a row vector.
if(vec_state == 2)
{
init(1, in_elem);
}
else
{
init(in_elem, 1);
}
}
/**
* Resize the matrix to a given size.
*
* @param in_rows Number of rows to allow.
* @param in_cols Number of columns to allow.
*/
template<typename eT>
inline
void
SpMat<eT>::set_size(const uword in_rows, const uword in_cols)
{
arma_extra_debug_sigprint();
init(in_rows, in_cols);
}
template<typename eT>
inline
void
SpMat<eT>::reshape(const uword in_rows, const uword in_cols, const uword dim)
{
arma_extra_debug_sigprint();
if (dim == 0)
{
// We have to modify all of the relevant row indices and the relevant column pointers.
// Iterate over all the points to do this. We won't be deleting any points, but we will be modifying
// columns and rows. We'll have to store a new set of column vectors.
uword* new_col_ptrs = memory::acquire<uword>(in_cols + 2);
new_col_ptrs[in_cols + 1] = std::numeric_limits<uword>::max();
uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero + 1);
access::rw(new_row_indices[n_nonzero]) = 0;
arrayops::inplace_set(new_col_ptrs, uword(0), in_cols + 1);
for(const_iterator it = begin(); it != end(); it++)
{
uword vector_position = (it.col() * n_rows) + it.row();
new_row_indices[it.pos()] = vector_position % in_rows;
++new_col_ptrs[vector_position / in_rows + 1];
}
// Now sum the column counts to get the new column pointers.
for(uword i = 1; i <= in_cols; i++)
{
access::rw(new_col_ptrs[i]) += new_col_ptrs[i - 1];
}
// Copy the new row indices.
memory::release(row_indices);
access::rw(row_indices) = new_row_indices;
memory::release(col_ptrs);
access::rw(col_ptrs) = new_col_ptrs;
// Now set the size.
access::rw(n_rows) = in_rows;
access::rw(n_cols) = in_cols;
}
else
{
// Row-wise reshaping. This is more tedious and we will use a separate sparse matrix to do it.
SpMat<eT> tmp(in_rows, in_cols);
for(const_row_iterator it = begin_row(); it.pos() < n_nonzero; it++)
{
uword vector_position = (it.row() * n_cols) + it.col();
tmp((vector_position / in_cols), (vector_position % in_cols)) = (*it);
}
(*this).operator=(tmp);
}
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::zeros()
{
arma_extra_debug_sigprint();
if (n_nonzero > 0)
{
memory::release(values);
memory::release(row_indices);
access::rw(values) = memory::acquire_chunked<eT>(1);
access::rw(row_indices) = memory::acquire_chunked<uword>(1);
access::rw(values[0]) = 0;
access::rw(row_indices[0]) = 0;
}
access::rw(n_nonzero) = 0;
arrayops::inplace_set(access::rwp(col_ptrs), uword(0), n_cols + 1);
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::zeros(const uword in_elem)
{
arma_extra_debug_sigprint();
if(vec_state == 2)
{
init(1, in_elem); // Row vector
}
else
{
init(in_elem, 1);
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::zeros(const uword in_rows, const uword in_cols)
{
arma_extra_debug_sigprint();
init(in_rows, in_cols);
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::eye()
{
arma_extra_debug_sigprint();
return (*this).eye(n_rows, n_cols);
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::eye(const uword in_rows, const uword in_cols)
{
arma_extra_debug_sigprint();
const uword N = (std::min)(in_rows, in_cols);
init(in_rows, in_cols);
mem_resize(N);
arrayops::inplace_set(access::rwp(values), eT(1), N);
for(uword i = 0; i < N; ++i) { access::rw(row_indices[i]) = i; }
for(uword i = 0; i <= N; ++i) { access::rw(col_ptrs[i]) = i; }
access::rw(n_nonzero) = N;
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::speye()
{
arma_extra_debug_sigprint();
return (*this).eye(n_rows, n_cols);
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::speye(const uword in_n_rows, const uword in_n_cols)
{
arma_extra_debug_sigprint();
return (*this).eye(in_n_rows, in_n_cols);
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::sprandu(const uword in_rows, const uword in_cols, const double density)
{
arma_extra_debug_sigprint();
arma_debug_check( ( (density < double(0)) || (density > double(1)) ), "sprandu(): density must be in the [0,1] interval" );
zeros(in_rows, in_cols);
mem_resize( uword(density * double(in_rows) * double(in_cols) + 0.5) );
if(n_nonzero == 0)
{
return *this;
}
eop_aux_randu<eT>::fill( access::rwp(values), n_nonzero );
uvec indices = linspace<uvec>( 0, in_rows*in_cols-1, n_nonzero );
// perturb the indices
for(uword i=1; i < n_nonzero-1; ++i)
{
const uword index_left = indices[i-1];
const uword index_right = indices[i+1];
const uword center = (index_left + index_right) / 2;
const uword delta1 = center - index_left - 1;
const uword delta2 = index_right - center - 1;
const uword min_delta = (std::min)(delta1, delta2);
uword index_new = uword( double(center) + double(min_delta) * (2.0*randu()-1.0) );
// paranoia, but better be safe than sorry
if( (index_left < index_new) && (index_new < index_right) )
{
indices[i] = index_new;
}
}
uword cur_index = 0;
uword count = 0;
for(uword lcol = 0; lcol < in_cols; ++lcol)
for(uword lrow = 0; lrow < in_rows; ++lrow)
{
if(count == indices[cur_index])
{
access::rw(row_indices[cur_index]) = lrow;
access::rw(col_ptrs[lcol + 1])++;
++cur_index;
}
++count;
}
if(cur_index != n_nonzero)
{
// Fix size to correct size.
mem_resize(cur_index);
}
// Sum column pointers.
for(uword lcol = 1; lcol <= in_cols; ++lcol)
{
access::rw(col_ptrs[lcol]) += col_ptrs[lcol - 1];
}
return *this;
}
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::sprandn(const uword in_rows, const uword in_cols, const double density)
{
arma_extra_debug_sigprint();
arma_debug_check( ( (density < double(0)) || (density > double(1)) ), "sprandn(): density must be in the [0,1] interval" );
zeros(in_rows, in_cols);
mem_resize( uword(density * double(in_rows) * double(in_cols) + 0.5) );
if(n_nonzero == 0)
{
return *this;
}
eop_aux_randn<eT>::fill( access::rwp(values), n_nonzero );
uvec indices = linspace<uvec>( 0, in_rows*in_cols-1, n_nonzero );
// perturb the indices
for(uword i=1; i < n_nonzero-1; ++i)
{
const uword index_left = indices[i-1];
const uword index_right = indices[i+1];
const uword center = (index_left + index_right) / 2;
const uword delta1 = center - index_left - 1;
const uword delta2 = index_right - center - 1;
const uword min_delta = (std::min)(delta1, delta2);
uword index_new = uword( double(center) + double(min_delta) * (2.0*randu()-1.0) );
// paranoia, but better be safe than sorry
if( (index_left < index_new) && (index_new < index_right) )
{
indices[i] = index_new;
}
}
uword cur_index = 0;
uword count = 0;
for(uword lcol = 0; lcol < in_cols; ++lcol)
for(uword lrow = 0; lrow < in_rows; ++lrow)
{
if(count == indices[cur_index])
{
access::rw(row_indices[cur_index]) = lrow;
access::rw(col_ptrs[lcol + 1])++;
++cur_index;
}
++count;
}
if(cur_index != n_nonzero)
{
// Fix size to correct size.
mem_resize(cur_index);
}
// Sum column pointers.
for(uword lcol = 1; lcol <= in_cols; ++lcol)
{
access::rw(col_ptrs[lcol]) += col_ptrs[lcol - 1];
}
return *this;
}
template<typename eT>
inline
void
SpMat<eT>::reset()
{
arma_extra_debug_sigprint();
set_size(0, 0);
}
/**
* Get the minimum or the maximum of the matrix.
*/
template<typename eT>
inline
arma_warn_unused
eT
SpMat<eT>::min() const
{
arma_extra_debug_sigprint();
arma_debug_check((n_elem == 0), "min(): object has no elements");
if (n_nonzero == 0)
{
return 0;
}
eT val = op_min::direct_min(values, n_nonzero);
if ((val > 0) && (n_nonzero < n_elem)) // A sparse 0 is less.
{
val = 0;
}
return val;
}
template<typename eT>
inline
eT
SpMat<eT>::min(uword& index_of_min_val) const
{
arma_extra_debug_sigprint();
arma_debug_check((n_elem == 0), "min(): object has no elements");
eT val = 0;
if (n_nonzero == 0) // There are no other elements. It must be 0.
{
index_of_min_val = 0;
}
else
{
uword location;
val = op_min::direct_min(values, n_nonzero, location);
if ((val > 0) && (n_nonzero < n_elem)) // A sparse 0 is less.
{
val = 0;
// Give back the index to the first zero position.
index_of_min_val = 0;
while (get_position(index_of_min_val) == index_of_min_val) // An element exists at that position.
{
index_of_min_val++;
}
}
else
{
index_of_min_val = get_position(location);
}
}
return val;
}
template<typename eT>
inline
eT
SpMat<eT>::min(uword& row_of_min_val, uword& col_of_min_val) const
{
arma_extra_debug_sigprint();
arma_debug_check((n_elem == 0), "min(): object has no elements");
eT val = 0;
if (n_nonzero == 0) // There are no other elements. It must be 0.
{
row_of_min_val = 0;
col_of_min_val = 0;
}
else
{
uword location;
val = op_min::direct_min(values, n_nonzero, location);
if ((val > 0) && (n_nonzero < n_elem)) // A sparse 0 is less.
{
val = 0;
location = 0;
while (get_position(location) == location) // An element exists at that position.
{
location++;
}
row_of_min_val = location % n_rows;
col_of_min_val = location / n_rows;
}
else
{
get_position(location, row_of_min_val, col_of_min_val);
}
}
return val;
}
template<typename eT>
inline
arma_warn_unused
eT
SpMat<eT>::max() const
{
arma_extra_debug_sigprint();
arma_debug_check((n_elem == 0), "max(): object has no elements");
if (n_nonzero == 0)
{
return 0;
}
eT val = op_max::direct_max(values, n_nonzero);
if ((val < 0) && (n_nonzero < n_elem)) // A sparse 0 is more.
{
return 0;
}
return val;
}
template<typename eT>
inline
eT
SpMat<eT>::max(uword& index_of_max_val) const
{
arma_extra_debug_sigprint();
arma_debug_check((n_elem == 0), "max(): object has no elements");
eT val = 0;
if (n_nonzero == 0)
{
index_of_max_val = 0;
}
else
{
uword location;
val = op_max::direct_max(values, n_nonzero, location);
if ((val < 0) && (n_nonzero < n_elem)) // A sparse 0 is more.
{
val = 0;
location = 0;
while (get_position(location) == location) // An element exists at that position.
{
location++;
}
}
else
{
index_of_max_val = get_position(location);
}
}
return val;
}
template<typename eT>
inline
eT
SpMat<eT>::max(uword& row_of_max_val, uword& col_of_max_val) const
{
arma_extra_debug_sigprint();
arma_debug_check((n_elem == 0), "max(): object has no elements");
eT val = 0;
if (n_nonzero == 0)
{
row_of_max_val = 0;
col_of_max_val = 0;
}
else
{
uword location;
val = op_max::direct_max(values, n_nonzero, location);
if ((val < 0) && (n_nonzero < n_elem)) // A sparse 0 is more.
{
val = 0;
location = 0;
while (get_position(location) == location) // An element exists at that position.
{
location++;
}
row_of_max_val = location % n_rows;
col_of_max_val = location / n_rows;
}
else
{
get_position(location, row_of_max_val, col_of_max_val);
}
}
return val;
}
//! save the matrix to a file
template<typename eT>
inline
bool
SpMat<eT>::save(const std::string name, const file_type type, const bool print_status) const
{
arma_extra_debug_sigprint();
bool save_okay;
switch(type)
{
// case raw_ascii:
// save_okay = diskio::save_raw_ascii(*this, name);
// break;
// case csv_ascii:
// save_okay = diskio::save_csv_ascii(*this, name);
// break;
case arma_binary:
save_okay = diskio::save_arma_binary(*this, name);
break;
case coord_ascii:
save_okay = diskio::save_coord_ascii(*this, name);
break;
default:
arma_warn(true, "SpMat::save(): unsupported file type");
save_okay = false;
}
arma_warn( (save_okay == false), "SpMat::save(): couldn't write to ", name);
return save_okay;
}
//! save the matrix to a stream
template<typename eT>
inline
bool
SpMat<eT>::save(std::ostream& os, const file_type type, const bool print_status) const
{
arma_extra_debug_sigprint();
bool save_okay;
switch(type)
{
// case raw_ascii:
// save_okay = diskio::save_raw_ascii(*this, os);
// break;
// case csv_ascii:
// save_okay = diskio::save_csv_ascii(*this, os);
// break;
case arma_binary:
save_okay = diskio::save_arma_binary(*this, os);
break;
case coord_ascii:
save_okay = diskio::save_coord_ascii(*this, os);
break;
default:
arma_warn(true, "SpMat::save(): unsupported file type");
save_okay = false;
}
arma_warn( (save_okay == false), "SpMat::save(): couldn't write to the given stream");
return save_okay;
}
//! load a matrix from a file
template<typename eT>
inline
bool
SpMat<eT>::load(const std::string name, const file_type type, const bool print_status)
{
arma_extra_debug_sigprint();
bool load_okay;
std::string err_msg;
switch(type)
{
// case auto_detect:
// load_okay = diskio::load_auto_detect(*this, name, err_msg);
// break;
// case raw_ascii:
// load_okay = diskio::load_raw_ascii(*this, name, err_msg);
// break;
// case csv_ascii:
// load_okay = diskio::load_csv_ascii(*this, name, err_msg);
// break;
case arma_binary:
load_okay = diskio::load_arma_binary(*this, name, err_msg);
break;
case coord_ascii:
load_okay = diskio::load_coord_ascii(*this, name, err_msg);
break;
default:
arma_warn(true, "SpMat::load(): unsupported file type");
load_okay = false;
}
if(load_okay == false)
{
if(err_msg.length() > 0)
{
arma_warn(true, "SpMat::load(): ", err_msg, name);
}
else
{
arma_warn(true, "SpMat::load(): couldn't read ", name);
}
}
if(load_okay == false)
{
(*this).reset();
}
return load_okay;
}
//! load a matrix from a stream
template<typename eT>
inline
bool
SpMat<eT>::load(std::istream& is, const file_type type, const bool print_status)
{
arma_extra_debug_sigprint();
bool load_okay;
std::string err_msg;
switch(type)
{
// case auto_detect:
// load_okay = diskio::load_auto_detect(*this, is, err_msg);
// break;
// case raw_ascii:
// load_okay = diskio::load_raw_ascii(*this, is, err_msg);
// break;
// case csv_ascii:
// load_okay = diskio::load_csv_ascii(*this, is, err_msg);
// break;
case arma_binary:
load_okay = diskio::load_arma_binary(*this, is, err_msg);
break;
case coord_ascii:
load_okay = diskio::load_coord_ascii(*this, is, err_msg);
break;
default:
arma_warn(true, "SpMat::load(): unsupported file type");
load_okay = false;
}
if(load_okay == false)
{
if(err_msg.length() > 0)
{
arma_warn(true, "SpMat::load(): ", err_msg, "the given stream");
}
else
{
arma_warn(true, "SpMat::load(): couldn't load from the given stream");
}
}
if(load_okay == false)
{
(*this).reset();
}
return load_okay;
}
//! save the matrix to a file, without printing any error messages
template<typename eT>
inline
bool
SpMat<eT>::quiet_save(const std::string name, const file_type type) const
{
arma_extra_debug_sigprint();
return (*this).save(name, type, false);
}
//! save the matrix to a stream, without printing any error messages
template<typename eT>
inline
bool
SpMat<eT>::quiet_save(std::ostream& os, const file_type type) const
{
arma_extra_debug_sigprint();
return (*this).save(os, type, false);
}
//! load a matrix from a file, without printing any error messages
template<typename eT>
inline
bool
SpMat<eT>::quiet_load(const std::string name, const file_type type)
{
arma_extra_debug_sigprint();
return (*this).load(name, type, false);
}
//! load a matrix from a stream, without printing any error messages
template<typename eT>
inline
bool
SpMat<eT>::quiet_load(std::istream& is, const file_type type)
{
arma_extra_debug_sigprint();
return (*this).load(is, type, false);
}
/**
* Initialize the matrix to the specified size. Data is not preserved, so the matrix is assumed to be entirely sparse (empty).
*/
template<typename eT>
inline
void
SpMat<eT>::init(uword in_rows, uword in_cols)
{
arma_extra_debug_sigprint();
// Verify that we are allowed to do this.
if(vec_state > 0)
{
if((in_rows == 0) && (in_cols == 0))
{
if(vec_state == 1)
{
in_cols = 1;
}
else
if(vec_state == 2)
{
in_rows = 1;
}
}
else
{
arma_debug_check
(
( ((vec_state == 1) && (in_cols != 1)) || ((vec_state == 2) && (in_rows != 1)) ),
"SpMat::init(): object is a row or column vector; requested size is not compatible"
);
}
}
// Ensure that n_elem can hold the result of (n_rows * n_cols)
arma_debug_check
(
(
( (in_rows > ARMA_MAX_UHWORD) || (in_cols > ARMA_MAX_UHWORD) )
? ( (float(in_rows) * float(in_cols)) > float(ARMA_MAX_UHWORD) )
: false
),
"SpMat::init(): requested size is too large"
);
// Clean out the existing memory.
if (values)
{
memory::release(values);
memory::release(row_indices);
}
access::rw(values) = memory::acquire_chunked<eT> (1);
access::rw(row_indices) = memory::acquire_chunked<uword>(1);
access::rw(values[0]) = 0;
access::rw(row_indices[0]) = 0;
memory::release(col_ptrs);
// Set the new size accordingly.
access::rw(n_rows) = in_rows;
access::rw(n_cols) = in_cols;
access::rw(n_elem) = (in_rows * in_cols);
access::rw(n_nonzero) = 0;
// Try to allocate the column pointers, filling them with 0, except for the
// last element which contains the maximum possible element (so iterators
// terminate correctly).
access::rw(col_ptrs) = memory::acquire<uword>(in_cols + 2);
access::rw(col_ptrs[in_cols + 1]) = std::numeric_limits<uword>::max();
arrayops::inplace_set(access::rwp(col_ptrs), uword(0), in_cols + 1);
}
/**
* Initialize the matrix from a string.
*/
template<typename eT>
inline
void
SpMat<eT>::init(const std::string& text)
{
arma_extra_debug_sigprint();
// Figure out the size first.
uword t_n_rows = 0;
uword t_n_cols = 0;
bool t_n_cols_found = false;
std::string token;
std::string::size_type line_start = 0;
std::string::size_type line_end = 0;
while (line_start < text.length())
{
line_end = text.find(';', line_start);
if (line_end == std::string::npos)
line_end = text.length() - 1;
std::string::size_type line_len = line_end - line_start + 1;
std::stringstream line_stream(text.substr(line_start, line_len));
// Step through each column.
uword line_n_cols = 0;
while (line_stream >> token)
{
++line_n_cols;
}
if (line_n_cols > 0)
{
if (t_n_cols_found == false)
{
t_n_cols = line_n_cols;
t_n_cols_found = true;
}
else // Check it each time through, just to make sure.
arma_check((line_n_cols != t_n_cols), "SpMat::init(): inconsistent number of columns in given string");
++t_n_rows;
}
line_start = line_end + 1;
}
set_size(t_n_rows, t_n_cols);
// Second time through will pick up all the values.
line_start = 0;
line_end = 0;
uword lrow = 0;
while (line_start < text.length())
{
line_end = text.find(';', line_start);
if (line_end == std::string::npos)
line_end = text.length() - 1;
std::string::size_type line_len = line_end - line_start + 1;
std::stringstream line_stream(text.substr(line_start, line_len));
uword lcol = 0;
eT val;
while (line_stream >> val)
{
// Only add nonzero elements.
if (val != eT(0))
{
get_value(lrow, lcol) = val;
}
++lcol;
}
++lrow;
line_start = line_end + 1;
}
}
/**
* Copy from another matrix.
*/
template<typename eT>
inline
void
SpMat<eT>::init(const SpMat<eT>& x)
{
arma_extra_debug_sigprint();
// Ensure we are not initializing to ourselves.
if (this != &x)
{
init(x.n_rows, x.n_cols);
// values and row_indices may not be null.
if (values != NULL)
{
memory::release(values);
memory::release(row_indices);
}
access::rw(values) = memory::acquire_chunked<eT> (x.n_nonzero + 1);
access::rw(row_indices) = memory::acquire_chunked<uword>(x.n_nonzero + 1);
// Now copy over the elements.
arrayops::copy(access::rwp(values), x.values, x.n_nonzero + 1);
arrayops::copy(access::rwp(row_indices), x.row_indices, x.n_nonzero + 1);
arrayops::copy(access::rwp(col_ptrs), x.col_ptrs, x.n_cols + 1);
access::rw(n_nonzero) = x.n_nonzero;
}
}
template<typename eT>
inline
void
SpMat<eT>::mem_resize(const uword new_n_nonzero)
{
arma_extra_debug_sigprint();
if(n_nonzero != new_n_nonzero)
{
if(new_n_nonzero == 0)
{
memory::release(values);
memory::release(row_indices);
access::rw(values) = memory::acquire_chunked<eT> (1);
access::rw(row_indices) = memory::acquire_chunked<uword>(1);
access::rw(values[0]) = 0;
access::rw(row_indices[0]) = 0;
}
else
{
// Figure out the actual amount of memory currently allocated
// NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays
const uword n_alloc = memory::enlarge_to_mult_of_chunksize(n_nonzero);
if(n_alloc < new_n_nonzero)
{
eT* new_values = memory::acquire_chunked<eT> (new_n_nonzero + 1);
uword* new_row_indices = memory::acquire_chunked<uword>(new_n_nonzero + 1);
if(n_nonzero > 0)
{
// Copy old elements.
uword copy_len = std::min(n_nonzero, new_n_nonzero);
arrayops::copy(new_values, values, copy_len);
arrayops::copy(new_row_indices, row_indices, copy_len);
}
memory::release(values);
memory::release(row_indices);
access::rw(values) = new_values;
access::rw(row_indices) = new_row_indices;
}
// Set the "fake end" of the matrix by setting the last value and row
// index to 0. This helps the iterators work correctly.
access::rw(values[new_n_nonzero]) = 0;
access::rw(row_indices[new_n_nonzero]) = 0;
}
access::rw(n_nonzero) = new_n_nonzero;
}
}
// Steal memory from another matrix.
template<typename eT>
inline
void
SpMat<eT>::steal_mem(SpMat<eT>& x)
{
arma_extra_debug_sigprint();
if(this != &x)
{
// Release all the memory.
memory::release(values);
memory::release(row_indices);
memory::release(col_ptrs);
// We'll have to copy everything about the other matrix.
const uword x_n_rows = x.n_rows;
const uword x_n_cols = x.n_cols;
const uword x_n_elem = x.n_elem;
const uword x_n_nonzero = x.n_nonzero;
access::rw(n_rows) = x_n_rows;
access::rw(n_cols) = x_n_cols;
access::rw(n_elem) = x_n_elem;
access::rw(n_nonzero) = x_n_nonzero;
access::rw(values) = x.values;
access::rw(row_indices) = x.row_indices;
access::rw(col_ptrs) = x.col_ptrs;
// Set other matrix to empty.
access::rw(x.n_rows) = 0;
access::rw(x.n_cols) = 0;
access::rw(x.n_elem) = 0;
access::rw(x.n_nonzero) = 0;
access::rw(x.values) = NULL;
access::rw(x.row_indices) = NULL;
access::rw(x.col_ptrs) = NULL;
}
}
template<typename eT>
template<typename T1, typename Functor>
arma_hot
inline
void
SpMat<eT>::init_xform(const SpBase<eT,T1>& A, const Functor& func)
{
arma_extra_debug_sigprint();
// if possible, avoid doing a copy and instead apply func to the generated elements
if(SpProxy<T1>::Q_created_by_proxy == true)
{
(*this) = A.get_ref();
const uword nnz = n_nonzero;
eT* t_values = access::rwp(values);
for(uword i=0; i < nnz; ++i)
{
t_values[i] = func(t_values[i]);
}
}
else
{
init_xform_mt(A.get_ref(), func);
}
}
template<typename eT>
template<typename eT2, typename T1, typename Functor>
arma_hot
inline
void
SpMat<eT>::init_xform_mt(const SpBase<eT2,T1>& A, const Functor& func)
{
arma_extra_debug_sigprint();
const SpProxy<T1> P(A.get_ref());
if( (P.is_alias(*this) == true) || (is_SpMat<typename SpProxy<T1>::stored_type>::value == true) )
{
// NOTE: unwrap_spmat will convert a submatrix to a matrix, which in effect takes care of aliasing with submatrices;
// NOTE: however, when more delayed ops are implemented, more elaborate handling of aliasing will be necessary
const unwrap_spmat<typename SpProxy<T1>::stored_type> tmp(P.Q);
const SpMat<eT2>& x = tmp.M;
if(void_ptr(this) != void_ptr(&x))
{
init(x.n_rows, x.n_cols);
// values and row_indices may not be null.
if(values != NULL)
{
memory::release(values);
memory::release(row_indices);
}
access::rw(values) = memory::acquire_chunked<eT> (x.n_nonzero + 1);
access::rw(row_indices) = memory::acquire_chunked<uword>(x.n_nonzero + 1);
arrayops::copy(access::rwp(row_indices), x.row_indices, x.n_nonzero + 1);
arrayops::copy(access::rwp(col_ptrs), x.col_ptrs, x.n_cols + 1);
access::rw(n_nonzero) = x.n_nonzero;
}
// initialise the elements array with a transformed version of the elements from x
const uword nnz = n_nonzero;
const eT2* x_values = x.values;
eT* t_values = access::rwp(values);
for(uword i=0; i < nnz; ++i)
{
t_values[i] = func(x_values[i]); // NOTE: func() must produce a value of type eT (ie. act as a convertor between eT2 and eT)
}
}
else
{
init(P.get_n_rows(), P.get_n_cols());
mem_resize(P.get_n_nonzero());
typename SpProxy<T1>::const_iterator_type it = P.begin();
while(it != P.end())
{
access::rw(row_indices[it.pos()]) = it.row();
access::rw(values[it.pos()]) = func(*it); // NOTE: func() must produce a value of type eT (ie. act as a convertor between eT2 and eT)
++access::rw(col_ptrs[it.col() + 1]);
++it;
}
// Now sum column pointers.
for(uword c = 1; c <= n_cols; ++c)
{
access::rw(col_ptrs[c]) += col_ptrs[c - 1];
}
}
}
template<typename eT>
inline
typename SpMat<eT>::iterator
SpMat<eT>::begin()
{
return iterator(*this);
}
template<typename eT>
inline
typename SpMat<eT>::const_iterator
SpMat<eT>::begin() const
{
return const_iterator(*this);
}
template<typename eT>
inline
typename SpMat<eT>::iterator
SpMat<eT>::end()
{
return iterator(*this, 0, n_cols, n_nonzero);
}
template<typename eT>
inline
typename SpMat<eT>::const_iterator
SpMat<eT>::end() const
{
return const_iterator(*this, 0, n_cols, n_nonzero);
}
template<typename eT>
inline
typename SpMat<eT>::iterator
SpMat<eT>::begin_col(const uword col_num)
{
return iterator(*this, 0, col_num);
}
template<typename eT>
inline
typename SpMat<eT>::const_iterator
SpMat<eT>::begin_col(const uword col_num) const
{
return const_iterator(*this, 0, col_num);
}
template<typename eT>
inline
typename SpMat<eT>::iterator
SpMat<eT>::end_col(const uword col_num)
{
return iterator(*this, 0, col_num + 1);
}
template<typename eT>
inline
typename SpMat<eT>::const_iterator
SpMat<eT>::end_col(const uword col_num) const
{
return const_iterator(*this, 0, col_num + 1);
}
template<typename eT>
inline
typename SpMat<eT>::row_iterator
SpMat<eT>::begin_row(const uword row_num)
{
return row_iterator(*this, row_num, 0);
}
template<typename eT>
inline
typename SpMat<eT>::const_row_iterator
SpMat<eT>::begin_row(const uword row_num) const
{
return const_row_iterator(*this, row_num, 0);
}
template<typename eT>
inline
typename SpMat<eT>::row_iterator
SpMat<eT>::end_row()
{
return row_iterator(*this, n_nonzero);
}
template<typename eT>
inline
typename SpMat<eT>::const_row_iterator
SpMat<eT>::end_row() const
{
return const_row_iterator(*this, n_nonzero);
}
template<typename eT>
inline
typename SpMat<eT>::row_iterator
SpMat<eT>::end_row(const uword row_num)
{
return row_iterator(*this, row_num + 1, 0);
}
template<typename eT>
inline
typename SpMat<eT>::const_row_iterator
SpMat<eT>::end_row(const uword row_num) const
{
return const_row_iterator(*this, row_num + 1, 0);
}
template<typename eT>
inline
void
SpMat<eT>::clear()
{
if (values)
{
memory::release(values);
memory::release(row_indices);
access::rw(values) = memory::acquire_chunked<eT> (1);
access::rw(row_indices) = memory::acquire_chunked<uword>(1);
access::rw(values[0]) = 0;
access::rw(row_indices[0]) = 0;
}
memory::release(col_ptrs);
access::rw(col_ptrs) = memory::acquire<uword>(n_cols + 2);
access::rw(col_ptrs[n_cols + 1]) = std::numeric_limits<uword>::max();
arrayops::inplace_set(col_ptrs, eT(0), n_cols + 1);
access::rw(n_nonzero) = 0;
}
template<typename eT>
inline
bool
SpMat<eT>::empty() const
{
return (n_elem == 0);
}
template<typename eT>
inline
uword
SpMat<eT>::size() const
{
return n_elem;
}
template<typename eT>
inline
arma_hot
arma_warn_unused
SpValProxy<SpMat<eT> >
SpMat<eT>::get_value(const uword i)
{
// First convert to the actual location.
uword lcol = i / n_rows; // Integer division.
uword lrow = i % n_rows;
return get_value(lrow, lcol);
}
template<typename eT>
inline
arma_hot
arma_warn_unused
eT
SpMat<eT>::get_value(const uword i) const
{
// First convert to the actual location.
uword lcol = i / n_rows; // Integer division.
uword lrow = i % n_rows;
return get_value(lrow, lcol);
}
template<typename eT>
inline
arma_hot
arma_warn_unused
SpValProxy<SpMat<eT> >
SpMat<eT>::get_value(const uword in_row, const uword in_col)
{
const uword colptr = col_ptrs[in_col];
const uword next_colptr = col_ptrs[in_col + 1];
// Step through the row indices to see if our element exists.
for (uword i = colptr; i < next_colptr; ++i)
{
const uword row_index = row_indices[i];
// First check that we have not stepped past it.
if (in_row < row_index) // If we have, then it doesn't exist: return 0.
{
return SpValProxy<SpMat<eT> >(in_row, in_col, *this); // Proxy for a zero value.
}
// Now check if we are at the correct place.
if (in_row == row_index) // If we are, return a reference to the value.
{
return SpValProxy<SpMat<eT> >(in_row, in_col, *this, &access::rw(values[i]));
}
}
// We did not find it, so it does not exist: return 0.
return SpValProxy<SpMat<eT> >(in_row, in_col, *this);
}
template<typename eT>
inline
arma_hot
arma_warn_unused
eT
SpMat<eT>::get_value(const uword in_row, const uword in_col) const
{
const uword colptr = col_ptrs[in_col];
const uword next_colptr = col_ptrs[in_col + 1];
// Step through the row indices to see if our element exists.
for (uword i = colptr; i < next_colptr; ++i)
{
const uword row_index = row_indices[i];
// First check that we have not stepped past it.
if (in_row < row_index) // If we have, then it doesn't exist: return 0.
{
return eT(0);
}
// Now check if we are at the correct place.
if (in_row == row_index) // If we are, return the value.
{
return values[i];
}
}
// We did not find it, so it does not exist: return 0.
return eT(0);
}
/**
* Given the index representing which of the nonzero values this is, return its
* actual location, either in row/col or just the index.
*/
template<typename eT>
arma_hot
arma_inline
arma_warn_unused
uword
SpMat<eT>::get_position(const uword i) const
{
uword lrow, lcol;
get_position(i, lrow, lcol);
// Assemble the row/col into the element's location in the matrix.
return (lrow + n_rows * lcol);
}
template<typename eT>
arma_hot
arma_inline
void
SpMat<eT>::get_position(const uword i, uword& row_of_i, uword& col_of_i) const
{
arma_debug_check((i >= n_nonzero), "SpMat::get_position(): index out of bounds");
col_of_i = 0;
while (col_ptrs[col_of_i + 1] <= i)
{
col_of_i++;
}
row_of_i = row_indices[i];
return;
}
/**
* Add an element at the given position, and return a reference to it. The
* element will be set to 0 (unless otherwise specified). If the element
* already exists, its value will be overwritten.
*
* @param in_row Row of new element.
* @param in_col Column of new element.
* @param in_val Value to set new element to (default 0.0).
*/
template<typename eT>
inline
arma_hot
arma_warn_unused
eT&
SpMat<eT>::add_element(const uword in_row, const uword in_col, const eT val)
{
arma_extra_debug_sigprint();
// We will assume the new element does not exist and begin the search for
// where to insert it. If we find that it already exists, we will then
// overwrite it.
uword colptr = col_ptrs[in_col ];
uword next_colptr = col_ptrs[in_col + 1];
uword pos = colptr; // The position in the matrix of this value.
if (colptr != next_colptr)
{
// There are other elements in this column, so we must find where this
// element will fit as compared to those.
while (pos < next_colptr && in_row > row_indices[pos])
{
pos++;
}
// We aren't inserting into the last position, so it is still possible
// that the element may exist.
if (pos != next_colptr && row_indices[pos] == in_row)
{
// It already exists. Then, just overwrite it.
access::rw(values[pos]) = val;
return access::rw(values[pos]);
}
}
//
// Element doesn't exist, so we have to insert it
//
// We have to update the rest of the column pointers.
for (uword i = in_col + 1; i < n_cols + 1; i++)
{
access::rw(col_ptrs[i])++; // We are only inserting one new element.
}
// Figure out the actual amount of memory currently allocated
// NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays
const uword n_alloc = memory::enlarge_to_mult_of_chunksize(n_nonzero + 1);
// If possible, avoid time-consuming memory allocation
if(n_alloc > (n_nonzero + 1))
{
arrayops::copy_backwards(access::rwp(values) + pos + 1, values + pos, (n_nonzero - pos) + 1);
arrayops::copy_backwards(access::rwp(row_indices) + pos + 1, row_indices + pos, (n_nonzero - pos) + 1);
// Insert the new element.
access::rw(values[pos]) = val;
access::rw(row_indices[pos]) = in_row;
access::rw(n_nonzero)++;
}
else
{
const uword old_n_nonzero = n_nonzero;
access::rw(n_nonzero)++; // Add to count of nonzero elements.
// Allocate larger memory.
eT* new_values = memory::acquire_chunked<eT> (n_nonzero + 1);
uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero + 1);
// Copy things over, before the new element.
if (pos > 0)
{
arrayops::copy(new_values, values, pos);
arrayops::copy(new_row_indices, row_indices, pos);
}
// Insert the new element.
new_values[pos] = val;
new_row_indices[pos] = in_row;
// Copy the rest of things over (including the extra element at the end).
arrayops::copy(new_values + pos + 1, values + pos, (old_n_nonzero - pos) + 1);
arrayops::copy(new_row_indices + pos + 1, row_indices + pos, (old_n_nonzero - pos) + 1);
// Assign new pointers.
memory::release(values);
memory::release(row_indices);
access::rw(values) = new_values;
access::rw(row_indices) = new_row_indices;
}
return access::rw(values[pos]);
}
/**
* Delete an element at the given position.
*
* @param in_row Row of element to be deleted.
* @param in_col Column of element to be deleted.
*/
template<typename eT>
inline
arma_hot
void
SpMat<eT>::delete_element(const uword in_row, const uword in_col)
{
arma_extra_debug_sigprint();
// We assume the element exists (although... it may not) and look for its
// exact position. If it doesn't exist... well, we don't need to do anything.
uword colptr = col_ptrs[in_col];
uword next_colptr = col_ptrs[in_col + 1];
if (colptr != next_colptr)
{
// There's at least one element in this column.
// Let's see if we are one of them.
for (uword pos = colptr; pos < next_colptr; pos++)
{
if (in_row == row_indices[pos])
{
const uword old_n_nonzero = n_nonzero;
--access::rw(n_nonzero); // Remove one from the count of nonzero elements.
// Found it. Now remove it.
// Figure out the actual amount of memory currently allocated and the actual amount that will be required
// NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays
const uword n_alloc = memory::enlarge_to_mult_of_chunksize(old_n_nonzero + 1);
const uword n_alloc_mod = memory::enlarge_to_mult_of_chunksize(n_nonzero + 1);
// If possible, avoid time-consuming memory allocation
if(n_alloc_mod == n_alloc)
{
if (pos < n_nonzero) // remember, we decremented n_nonzero
{
arrayops::copy_forwards(access::rwp(values) + pos, values + pos + 1, (n_nonzero - pos) + 1);
arrayops::copy_forwards(access::rwp(row_indices) + pos, row_indices + pos + 1, (n_nonzero - pos) + 1);
}
}
else
{
// Make new arrays.
eT* new_values = memory::acquire_chunked<eT> (n_nonzero + 1);
uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero + 1);
if (pos > 0)
{
arrayops::copy(new_values, values, pos);
arrayops::copy(new_row_indices, row_indices, pos);
}
arrayops::copy(new_values + pos, values + pos + 1, (n_nonzero - pos) + 1);
arrayops::copy(new_row_indices + pos, row_indices + pos + 1, (n_nonzero - pos) + 1);
memory::release(values);
memory::release(row_indices);
access::rw(values) = new_values;
access::rw(row_indices) = new_row_indices;
}
// And lastly, update all the column pointers (decrement by one).
for (uword i = in_col + 1; i < n_cols + 1; i++)
{
--access::rw(col_ptrs[i]); // We only removed one element.
}
return; // There is nothing left to do.
}
}
}
return; // The element does not exist, so there's nothing for us to do.
}
#ifdef ARMA_EXTRA_SPMAT_MEAT
#include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPMAT_MEAT)
#endif
//! @}
| [
"mirsking@163.com"
] | mirsking@163.com |
36757cf17b7434ecaca78a074facc20ef61ef964 | 1d757454ff3655b90949ec7478e8e741d154c8cf | /codeforces/1345c.cpp | e21a123a13fbf6554ea405621c32644ffdcdf967 | [] | no_license | manoj9april/cp-solutions | 193b588e0f4690719fe292ac404a8c1f592b8c78 | 41141298600c1e7b9ccb6e26174f797744ed6ac1 | refs/heads/master | 2021-07-12T17:52:21.578577 | 2021-06-20T16:23:05 | 2021-06-20T16:23:05 | 249,103,555 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,954 | cpp | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n) for(ll i=0; i<n; i++)
#define loop1(i,n) for(ll i=1; i<=n; i++)
#define all(a) (a).begin(),(a).end()
#define exist(s,e) (s.find(e)!=s.end())
#define dbg(x) cout << #x << " = " << x << endl
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define inf (int)1e9
#define infll 1e18
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test int t; cin>>t; while(t--)
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
//===========================DEBUG======================//
#define XOX 1
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while(!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
stringstream ss; ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//================================================================//
//////////////////////////////////////////////////////////////////////////////////////////
// main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=3e5+5;
ll a[lmt],b[lmt];
int main(){
#ifndef ONLINE_JUDGE
freopen("../input.txt", "r", stdin);
freopen("../output.txt", "w", stdout);
#endif
fast
test{
ll n; cin>>n;
loop(i,n) cin>>a[i];
mii pos;
ll mn = infll, mx = -infll;
loop(i,n){
ll npos = i + a[i%n];
npos = ((npos%n)+n)%n;
mn = min(mn,npos);
mx = max(mx,npos);
// pts(npos);
pos[npos]=1;
}
// pt("");
ll ok=1;
if(mx-mn+1 != n){pt("NO"); continue;}
for(ll i=mn; i<=mx; i++){
if(!exist(pos,i)){
ok=0; break;
}
}
pt((ok?"YES":"NO"));
}
}
/*
*/
| [
"qwertyrani3@gmail.com"
] | qwertyrani3@gmail.com |
920cbe0da3683db5b2021fcc138c6832cf016226 | 028c70cba227ca1c15a646502ff9fc6e3103539b | /seal-c/ciphertext.hpp | 2ea6299713079b9e117334935b77fd6639b33ff2 | [
"MIT"
] | permissive | lambdageek/sealsharp | 3adfa4597284f08837ea54bacc563c1dce6e7a4b | 63863f1542ada35d299453cf382f42c7c5544404 | refs/heads/master | 2020-04-13T13:09:22.605011 | 2019-02-04T19:35:39 | 2019-02-04T19:35:39 | 163,222,065 | 4 | 0 | MIT | 2019-01-10T15:42:41 | 2018-12-26T22:21:04 | C++ | UTF-8 | C++ | false | false | 445 | hpp |
#ifndef _SEAL_C_CIPHERTEXT_HPP
#define _SEAL_C_CIPHERTEXT_HPP
#include <seal/ciphertext.h>
#include <seal-c/types.h>
#include "wrap.hpp"
namespace seal_c {
namespace wrap {
template<>
struct Wrap<seal::Ciphertext*> : public WrapPair<seal::Ciphertext*, SEALCiphertextRef> {};
template<>
struct Unwrap<SEALCiphertextRef> : public WrapPair<seal::Ciphertext*, SEALCiphertextRef> {};
} // namespace wrap
} // namespace seal_c
#endif
| [
"alklig@microsoft.com"
] | alklig@microsoft.com |
3eeda37b9abb7202e4e70335826bdd473599ba04 | eaa64753cb11194ab175ec8c386924cd7edd502b | /WinBridge/DirectShow/Stdafx.cpp | 20064f731ee278a996cac327e10ee1b866073b9a | [] | no_license | venkatvishnu/win-bridge | e0a51e56eeb730df1b30cc453ac7e73744927ee8 | ea4542160f1bcea442a28e7051a75743970d5eaa | refs/heads/master | 2021-01-25T06:01:03.215370 | 2011-07-29T04:21:36 | 2011-07-29T04:21:36 | 41,912,274 | 0 | 0 | null | null | null | null | SHIFT_JIS | C++ | false | false | 265 | cpp | // stdafx.cpp : 標準インクルード DirectShow.pch のみを
// 含むソース ファイルは、プリコンパイル済みヘッダーになります。
// stdafx.obj にはプリコンパイル済み型情報が含まれます。
#include "stdafx.h"
| [
"hiro5791@gmail.com"
] | hiro5791@gmail.com |
3b371df187f01582e92b206559b2a9febbbe81c7 | 9b633c6e1c8b658c2a7eeadef906de24fbd8ff6b | /Library/ColorFilteringMaterial.h | ae6faf4d8667f85c1fda198733d291d207f6253e | [] | no_license | swordlegend/EveryRay-Rendering-Engine | 4e10516de701d21b0b5eeb248a0476cbb1552b93 | 906d0c7e9a718129d48c91cc8aaec5e576f60985 | refs/heads/master | 2020-08-01T16:03:49.722169 | 2019-07-08T20:29:26 | 2019-07-08T20:29:26 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 386 | h | #pragma once
#include "Common.h"
#include "PostProcessingMaterial.h"
using namespace Library;
namespace Rendering
{
class ColorFilterMaterial : public PostProcessingMaterial
{
RTTI_DECLARATIONS(PostProcessingMaterial, ColorFilterMaterial)
MATERIAL_VARIABLE_DECLARATION(ColorFilter)
public:
ColorFilterMaterial();
virtual void Initialize(Effect* effect) override;
};
} | [
"steaklive@gmail.com"
] | steaklive@gmail.com |
f1be0025e0bff9dfeb64d1d82a9637dc47a34fdd | 0f30b234b3cd6e38c9975bbea88e1ab2eb61e910 | /grid-gui/SymbolMapFile.h | 533fac65f4ed150445e1b81d6ea7c6a21742f607 | [
"MIT"
] | permissive | fmidev/smartmet-plugin-grid-gui | c4f5ba059d54eb69436828c8376c250aba3a30ac | ec88e2c1d8389c19218220e626481b1533e7794d | refs/heads/master | 2023-08-09T12:19:02.960887 | 2023-07-28T06:54:41 | 2023-07-28T06:54:41 | 100,470,071 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,345 | h | #pragma once
#include <grid-files/common/ThreadLock.h>
#include <grid-files/common/Typedefs.h>
#include <grid-files/common/ImageFunctions.h>
#include <map>
#include <vector>
namespace SmartMet
{
namespace T
{
typedef std::map<double,std::string> SymbolMap;
typedef std::map<std::string,CImage> SymbolCache;
class SymbolMapFile
{
public:
SymbolMapFile();
SymbolMapFile(const std::string& filename);
SymbolMapFile(const SymbolMapFile& symbolMapFile);
virtual ~SymbolMapFile();
void init();
void init(const std::string& filename);
bool checkUpdates();
time_t getLastModificationTime();
std::string getFilename();
bool getSymbol(double value,CImage& symbol);
string_vec getNames();
bool hasName(const char *name);
void print(std::ostream& stream,uint level,uint optionFlags);
protected:
void loadFile();
string_vec mNames;
std::string mFilename;
std::string mDir;
SymbolMap mSymbolMap;
SymbolCache mSymbolCache;
time_t mLastModified;
ThreadLock mThreadLock;
};
typedef std::vector<SymbolMapFile> SymbolMapFile_vec;
} // namespace T
} // namespace SmartMet
| [
"markku.koskela@fmi.fi"
] | markku.koskela@fmi.fi |
7b0c1dfe2f482ea038281f2574dc2f491d8b484e | 944438a953b5a125aae48eeb578b80cc37e3577e | /ash/system/message_center/ash_notification_view.cc | 433e3881bf4dffa5ab2b2205459334cee330574e | [
"BSD-3-Clause"
] | permissive | guhuaijian/chromium | 0dc346626cc2084bb9a786bb59911441a83d10e0 | 2b617d4be11c76220496be187d321325babb7cda | refs/heads/master | 2023-08-16T14:49:25.462662 | 2021-10-29T01:20:06 | 2021-10-29T01:20:06 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 34,833 | cc | // Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/message_center/ash_notification_view.h"
#include <memory>
#include <utility>
#include "ash/public/cpp/rounded_image_view.h"
#include "ash/public/cpp/style/color_provider.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/style/button_style.h"
#include "ash/system/message_center/ash_notification_input_container.h"
#include "ash/system/message_center/message_center_constants.h"
#include "ash/system/message_center/message_center_style.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_popup_utils.h"
#include "base/bind.h"
#include "base/check.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/text_elider.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/message_center_constants.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/vector_icons.h"
#include "ui/message_center/views/notification_background_painter.h"
#include "ui/message_center/views/notification_control_buttons_view.h"
#include "ui/message_center/views/notification_header_view.h"
#include "ui/message_center/views/notification_view_base.h"
#include "ui/message_center/views/relative_time_formatter.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/focus_ring.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/layout/flex_layout_view.h"
#include "ui/views/layout/layout_types.h"
#include "ui/views/metadata/view_factory_internal.h"
#include "ui/views/style/typography.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
namespace {
constexpr gfx::Insets kNotificationViewPadding(0, 16, 18, 6);
constexpr gfx::Insets kMainRightViewPadding(0, 0, 0, 10);
constexpr int kMainRightViewVerticalSpacing = 4;
// This padding is applied to all the children of `main_right_view_` except the
// action buttons.
constexpr gfx::Insets kMainRightViewChildPadding(0, 14, 0, 0);
constexpr gfx::Insets kActionButtonsRowPadding(0, 22, 0, 0);
constexpr int kContentRowHorizontalSpacing = 16;
constexpr int kLeftContentVerticalSpacing = 4;
constexpr int kTitleRowSpacing = 6;
constexpr int kHeaderRowSpacing = 4;
// Bullet character. The divider symbol between the title and the timestamp.
constexpr char16_t kTitleRowDivider[] = u"\u2022";
constexpr char kGoogleSansFont[] = "Google Sans";
constexpr int kAppIconViewSize = 24;
constexpr int kTitleCharacterLimit =
message_center::kNotificationWidth * message_center::kMaxTitleLines /
message_center::kMinPixelsPerTitleCharacter;
constexpr int kTitleLabelSize = 14;
constexpr int kTimestampInCollapsedViewSize = 12;
constexpr int kMessageLabelSize = 13;
// The size for `icon_view_`, which is the icon within right content (between
// title/message view and expand button).
constexpr int kIconViewSize = 48;
// Helpers ---------------------------------------------------------------------
// Configure the style for labels in notification view. `is_color_primary`
// indicates if the color of the text is primary or secondary text color.
void ConfigureLabelStyle(views::Label* label, int size, bool is_color_primary) {
label->SetAutoColorReadabilityEnabled(false);
label->SetFontList(gfx::FontList({kGoogleSansFont}, gfx::Font::NORMAL, size,
gfx::Font::Weight::MEDIUM));
auto layer_type =
is_color_primary
? ash::AshColorProvider::ContentLayerType::kTextColorPrimary
: ash::AshColorProvider::ContentLayerType::kTextColorSecondary;
label->SetEnabledColor(
ash::AshColorProvider::Get()->GetContentLayerColor(layer_type));
}
// Create a view that will contain the `content_row`,
// `message_view_in_expanded_state_`, inline settings and the large image.
views::Builder<views::View> CreateMainRightViewBuilder() {
auto layout_manager = std::make_unique<views::FlexLayout>();
layout_manager
->SetDefault(views::kMarginsKey,
gfx::Insets(0, 0, kMainRightViewVerticalSpacing, 0))
.SetOrientation(views::LayoutOrientation::kVertical)
.SetInteriorMargin(kMainRightViewPadding);
return views::Builder<views::View>()
.SetID(message_center::NotificationViewBase::ViewId::kMainRightView)
.SetLayoutManager(std::move(layout_manager))
.SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToZero,
views::MaximumFlexSizeRule::kUnbounded));
}
// Create a view containing the title and message for the notification in a
// single line. This is used when a grouped child notification is in a
// collapsed parent notification.
views::Builder<views::BoxLayoutView> CreateCollapsedSummaryBuilder(
const message_center::Notification& notification) {
return views::Builder<views::BoxLayoutView>()
.SetID(
message_center::NotificationViewBase::ViewId::kCollapsedSummaryView)
.SetInsideBorderInsets(ash::kGroupedCollapsedSummaryInsets)
.SetBetweenChildSpacing(ash::kGroupedCollapsedSummaryLabelSpacing)
.SetOrientation(views::BoxLayout::Orientation::kHorizontal)
.SetVisible(false)
.AddChild(views::Builder<views::Label>()
.SetText(notification.title())
.SetTextContext(views::style::CONTEXT_DIALOG_BODY_TEXT))
.AddChild(views::Builder<views::Label>()
.SetText(notification.message())
.SetTextContext(views::style::CONTEXT_DIALOG_BODY_TEXT)
.SetTextStyle(views::style::STYLE_SECONDARY));
}
} // namespace
namespace ash {
using CrossAxisAlignment = views::BoxLayout::CrossAxisAlignment;
using MainAxisAlignment = views::BoxLayout::MainAxisAlignment;
using Orientation = views::BoxLayout::Orientation;
BEGIN_METADATA(AshNotificationView, NotificationTitleRow, views::View)
END_METADATA
BEGIN_METADATA(AshNotificationView, ExpandButton, views::Button)
END_METADATA
AshNotificationView::NotificationTitleRow::NotificationTitleRow(
const std::u16string& title)
: title_view_(AddChildView(GenerateTitleView(title))),
title_row_divider_(AddChildView(std::make_unique<views::Label>(
kTitleRowDivider,
views::style::CONTEXT_DIALOG_BODY_TEXT))),
timestamp_in_collapsed_view_(
AddChildView(std::make_unique<views::Label>())) {
SetLayoutManager(std::make_unique<views::FlexLayout>())
->SetDefault(views::kMarginsKey, gfx::Insets(0, 0, 0, kTitleRowSpacing));
title_view_->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum,
views::MaximumFlexSizeRule::kPreferred));
ConfigureLabelStyle(title_row_divider_, kTimestampInCollapsedViewSize,
/*is_color_primary=*/false);
ConfigureLabelStyle(timestamp_in_collapsed_view_,
kTimestampInCollapsedViewSize,
/*is_color_primary=*/false);
ConfigureLabelStyle(title_view_, kTitleLabelSize,
/*is_color_primary=*/true);
}
AshNotificationView::NotificationTitleRow::~NotificationTitleRow() {
timestamp_update_timer_.Stop();
}
void AshNotificationView::NotificationTitleRow::UpdateTitle(
const std::u16string& title) {
title_view_->SetText(title);
}
void AshNotificationView::NotificationTitleRow::UpdateTimestamp(
base::Time timestamp) {
std::u16string relative_time;
base::TimeDelta next_update;
message_center::GetRelativeTimeStringAndNextUpdateTime(
timestamp - base::Time::Now(), &relative_time, &next_update);
timestamp_ = timestamp;
timestamp_in_collapsed_view_->SetText(relative_time);
// Unretained is safe as the timer cancels the task on destruction.
timestamp_update_timer_.Start(
FROM_HERE, next_update,
base::BindOnce(&NotificationTitleRow::UpdateTimestamp,
base::Unretained(this), timestamp));
}
void AshNotificationView::NotificationTitleRow::UpdateVisibility(
bool in_collapsed_mode) {
timestamp_in_collapsed_view_->SetVisible(in_collapsed_mode);
title_row_divider_->SetVisible(in_collapsed_mode);
}
AshNotificationView::ExpandButton::ExpandButton(PressedCallback callback)
: Button(std::move(callback)) {
auto* layout_manager = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal,
kNotificationExpandButtonInsets, kNotificationExpandButtonChildSpacing));
layout_manager->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kEnd);
TrayPopupUtils::ConfigureTrayPopupButton(this);
auto label = std::make_unique<views::Label>();
label->SetFontList(gfx::FontList({kGoogleSansFont}, gfx::Font::NORMAL,
kNotificationExpandButtonLabelFontSize,
gfx::Font::Weight::MEDIUM));
label->SetPreferredSize(kNotificationExpandButtonLabelSize);
label->SetText(base::NumberToString16(total_grouped_notifications_));
label->SetVisible(ShouldShowLabel());
label_ = AddChildView(std::move(label));
UpdateIcons();
auto image = std::make_unique<views::ImageView>();
image->SetImage(expanded_ ? expanded_image_ : collapsed_image_);
image_ = AddChildView(std::move(image));
views::InstallRoundRectHighlightPathGenerator(
this, gfx::Insets(), kNotificationExpandButtonCornerRadius);
}
AshNotificationView::ExpandButton::~ExpandButton() = default;
void AshNotificationView::ExpandButton::SetExpanded(bool expanded) {
if (expanded_ == expanded)
return;
expanded_ = expanded;
label_->SetText(base::NumberToString16(total_grouped_notifications_));
label_->SetVisible(ShouldShowLabel());
image_->SetImage(expanded_ ? expanded_image_ : collapsed_image_);
SetTooltipText(l10n_util::GetStringUTF16(
expanded_ ? IDS_ASH_NOTIFICATION_COLLAPSE_TOOLTIP
: IDS_ASH_NOTIFICATION_EXPAND_TOOLTIP));
SchedulePaint();
}
bool AshNotificationView::ExpandButton::ShouldShowLabel() const {
return !expanded_ && total_grouped_notifications_;
}
void AshNotificationView::ExpandButton::UpdateGroupedNotificationsCount(
int count) {
total_grouped_notifications_ = count;
label_->SetText(base::NumberToString16(total_grouped_notifications_));
label_->SetVisible(ShouldShowLabel());
}
void AshNotificationView::ExpandButton::UpdateIcons() {
expanded_image_ = gfx::CreateVectorIcon(
kUnifiedMenuExpandIcon, kNotificationExpandButtonChevronIconSize,
AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorPrimary));
collapsed_image_ = gfx::ImageSkiaOperations::CreateRotatedImage(
gfx::CreateVectorIcon(
kUnifiedMenuExpandIcon, kNotificationExpandButtonChevronIconSize,
AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorPrimary)),
SkBitmapOperations::ROTATION_180_CW);
}
gfx::Size AshNotificationView::ExpandButton::CalculatePreferredSize() const {
if (ShouldShowLabel())
return kNotificationExpandButtonWithLabelSize;
return kNotificationExpandButtonSize;
}
void AshNotificationView::ExpandButton::OnThemeChanged() {
views::Button::OnThemeChanged();
UpdateIcons();
image_->SetImage(expanded_ ? expanded_image_ : collapsed_image_);
views::FocusRing::Get(this)->SetColor(
AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kFocusRingColor));
SkColor background_color = AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kControlBackgroundColorInactive);
SetBackground(views::CreateRoundedRectBackground(background_color,
kTrayItemCornerRadius));
}
AshNotificationView::AshNotificationView(
const message_center::Notification& notification,
bool shown_in_popup)
: NotificationViewBase(notification), shown_in_popup_(shown_in_popup) {
// TODO(crbug/1232197): fix views and layout to match spec.
// Instantiate view instances and define layout and view hierarchy.
SetLayoutManager(std::make_unique<views::FlexLayout>())
->SetOrientation(views::LayoutOrientation::kVertical)
.SetInteriorMargin(notification.group_child() ? gfx::Insets()
: kNotificationViewPadding);
auto content_row_layout = std::make_unique<views::FlexLayout>();
content_row_layout->SetInteriorMargin(kMainRightViewChildPadding);
auto content_row_builder =
CreateContentRowBuilder()
.SetLayoutManager(std::move(content_row_layout))
.AddChild(
views::Builder<views::BoxLayoutView>()
.SetID(kHeaderLeftContent)
.SetOrientation(Orientation::kVertical)
.SetBetweenChildSpacing(kLeftContentVerticalSpacing)
.SetProperty(views::kFlexBehaviorKey,
views::FlexSpecification(
views::MinimumFlexSizeRule::kScaleToZero,
views::MaximumFlexSizeRule::kScaleToMaximum))
.AddChild(
CreateHeaderRowBuilder()
.SetIsInAshNotificationView(true)
.SetColor(
AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::
kTextColorSecondary)))
.AddChild(
CreateLeftContentBuilder()
.CopyAddressTo(&left_content_)
.SetBetweenChildSpacing(kLeftContentVerticalSpacing)))
.AddChild(
views::Builder<views::BoxLayoutView>()
.SetMainAxisAlignment(MainAxisAlignment::kEnd)
.SetInsideBorderInsets(
gfx::Insets(0, kContentRowHorizontalSpacing, 0, 0))
.SetBetweenChildSpacing(kContentRowHorizontalSpacing)
.SetProperty(views::kFlexBehaviorKey,
views::FlexSpecification(
views::MinimumFlexSizeRule::kPreferred,
views::MaximumFlexSizeRule::kUnbounded))
.AddChild(CreateRightContentBuilder())
.AddChild(
views::Builder<views::FlexLayoutView>()
.SetOrientation(views::LayoutOrientation::kHorizontal)
.AddChild(views::Builder<ExpandButton>()
.CopyAddressTo(&expand_button_)
.SetCallback(base::BindRepeating(
&AshNotificationView::ToggleExpand,
base::Unretained(this)))
.SetProperty(
views::kCrossAxisAlignmentKey,
views::LayoutAlignment::kCenter))));
// Main right view contains all the views besides control buttons and
// icon.
auto main_right_view_builder =
CreateMainRightViewBuilder()
.AddChild(content_row_builder)
.AddChild(
views::Builder<views::Label>()
.CopyAddressTo(&message_view_in_expanded_state_)
.SetHorizontalAlignment(gfx::ALIGN_TO_HEAD)
.SetMultiLine(true)
.SetMaxLines(message_center::kMaxLinesForExpandedMessageView)
.SetAllowCharacterBreak(true)
.SetBorder(
views::CreateEmptyBorder(kMainRightViewChildPadding))
// TODO(crbug/682266): This is a workaround to that bug by
// explicitly setting the width. Ideally, we should fix the
// original bug, but it seems there's no obvious solution for
// the bug according to https://crbug.com/678337#c7. We will
// consider making changes to this code when the bug is fixed.
.SetMaximumWidth(GetExpandedMessageViewWidth()))
.AddChild(CreateInlineSettingsBuilder())
.AddChild(CreateImageContainerBuilder());
ConfigureLabelStyle(message_view_in_expanded_state_, kMessageLabelSize,
false);
AddChildView(
views::Builder<views::BoxLayoutView>()
.CopyAddressTo(&control_buttons_container_)
.SetMainAxisAlignment(MainAxisAlignment::kEnd)
.SetVisible(!notification.group_child())
.AddChild(CreateControlButtonsBuilder()
.CopyAddressTo(&control_buttons_view_)
.SetButtonIconColors(
AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::
kIconColorPrimary)))
.Build());
AddChildView(
views::Builder<views::FlexLayoutView>()
.CopyAddressTo(&main_view_)
.SetOrientation(views::LayoutOrientation::kHorizontal)
.AddChild(views::Builder<views::BoxLayoutView>()
.SetID(kAppIconViewContainer)
.SetOrientation(Orientation::kVertical)
.SetMainAxisAlignment(MainAxisAlignment::kStart)
.AddChild(views::Builder<RoundedImageView>()
.CopyAddressTo(&app_icon_view_)
.SetCornerRadius(kAppIconViewSize / 2)))
.AddChild(main_right_view_builder)
.Build());
AddChildView(CreateCollapsedSummaryBuilder(notification)
.CopyAddressTo(&collapsed_summary_view_)
.Build());
AddChildView(views::Builder<views::BoxLayoutView>()
.CopyAddressTo(&grouped_notifications_container_)
.SetOrientation(Orientation::kVertical)
.SetInsideBorderInsets(kGroupedNotificationContainerInsets)
.SetBetweenChildSpacing(
IsExpanded() ? kGroupedNotificationsExpandedSpacing
: kGroupedNotificationsCollapsedSpacing)
.Build());
AddChildView(CreateActionsRow());
// Custom paddings for `AshNotificationView`.
static_cast<views::BoxLayout*>(action_buttons_row()->GetLayoutManager())
->set_inside_border_insets(kActionButtonsRowPadding);
static_cast<views::FlexLayout*>(header_row()->GetLayoutManager())
->SetDefault(views::kMarginsKey, gfx::Insets(0, 0, 0, kHeaderRowSpacing))
.SetInteriorMargin(gfx::Insets());
if (shown_in_popup_ && !notification.group_child()) {
layer()->SetBackgroundBlur(ColorProvider::kBackgroundBlurSigma);
layer()->SetBackdropFilterQuality(ColorProvider::kBackgroundBlurQuality);
layer()->SetRoundedCornerRadius(
gfx::RoundedCornersF{kMessagePopupCornerRadius});
} else if (!notification.group_child()) {
layer()->SetRoundedCornerRadius(
gfx::RoundedCornersF{kMessageCenterNotificationCornerRadius});
}
layer()->SetIsFastRoundedCorner(true);
UpdateWithNotification(notification);
}
AshNotificationView::~AshNotificationView() = default;
void AshNotificationView::ToggleExpand() {
SetExpanded(!IsExpanded());
}
void AshNotificationView::AddGroupNotification(
const message_center::Notification& notification,
bool newest_first) {
auto notification_view =
std::make_unique<AshNotificationView>(notification,
/*shown_in_popup=*/false);
notification_view->SetVisible(
total_grouped_notifications_ <
message_center_style::kMaxGroupedNotificationsInCollapsedState ||
IsExpanded());
notification_view->SetGroupedChildExpanded(IsExpanded());
grouped_notifications_container_->AddChildViewAt(
std::move(notification_view),
newest_first ? 0 : grouped_notifications_container_->children().size());
total_grouped_notifications_++;
left_content_->SetVisible(false);
expand_button_->UpdateGroupedNotificationsCount(total_grouped_notifications_);
PreferredSizeChanged();
}
void AshNotificationView::PopulateGroupNotifications(
const std::vector<const message_center::Notification*>& notifications) {
DCHECK(total_grouped_notifications_ == 0);
for (auto* notification : notifications) {
auto notification_view =
std::make_unique<AshNotificationView>(*notification,
/*shown_in_popup=*/false);
notification_view->SetVisible(
total_grouped_notifications_ <
message_center_style::kMaxGroupedNotificationsInCollapsedState ||
IsExpanded());
notification_view->SetGroupedChildExpanded(IsExpanded());
grouped_notifications_container_->AddChildViewAt(
std::move(notification_view), 0);
}
total_grouped_notifications_ = notifications.size();
left_content_->SetVisible(total_grouped_notifications_ == 0);
expand_button_->UpdateGroupedNotificationsCount(total_grouped_notifications_);
}
void AshNotificationView::RemoveGroupNotification(
const std::string& notification_id) {
AshNotificationView* to_be_deleted = nullptr;
for (auto* child : grouped_notifications_container_->children()) {
AshNotificationView* group_notification =
static_cast<AshNotificationView*>(child);
if (group_notification->notification_id() == notification_id) {
to_be_deleted = group_notification;
break;
}
}
if (to_be_deleted)
delete to_be_deleted;
total_grouped_notifications_--;
left_content_->SetVisible(total_grouped_notifications_ == 0);
expand_button_->UpdateGroupedNotificationsCount(total_grouped_notifications_);
PreferredSizeChanged();
}
void AshNotificationView::SetGroupedChildExpanded(bool expanded) {
collapsed_summary_view_->SetVisible(!expanded);
main_view_->SetVisible(expanded);
control_buttons_view_->SetVisible(expanded);
}
void AshNotificationView::UpdateViewForExpandedState(bool expanded) {
app_icon_view_->SetBorder(views::CreateEmptyBorder(
expanded ? kAppIconViewExpandedPadding : kAppIconViewCollapsedPadding));
bool is_single_expanded_notification =
!is_grouped_child_view_ && !is_grouped_parent_view_ && expanded;
header_row()->SetVisible(is_grouped_parent_view_ ||
(is_single_expanded_notification));
if (title_row_) {
title_row_->UpdateVisibility(is_grouped_child_view_ ||
(IsExpandable() && !expanded));
}
if (message_view()) {
// `message_view()` is shown only in collapsed mode.
if (!expanded) {
ConfigureLabelStyle(message_view(), kMessageLabelSize, false);
}
message_view()->SetVisible(!expanded);
message_view_in_expanded_state_->SetVisible(expanded &&
!is_grouped_parent_view_);
}
expand_button_->SetExpanded(expanded);
static_cast<views::BoxLayout*>(
grouped_notifications_container_->GetLayoutManager())
->set_between_child_spacing(expanded
? kGroupedNotificationsExpandedSpacing
: kGroupedNotificationsCollapsedSpacing);
int notification_count = 0;
for (auto* child : grouped_notifications_container_->children()) {
auto* notification_view = static_cast<AshNotificationView*>(child);
notification_view->SetGroupedChildExpanded(expanded);
notification_count++;
if (notification_count >
message_center_style::kMaxGroupedNotificationsInCollapsedState) {
notification_view->SetVisible(expanded);
}
}
NotificationViewBase::UpdateViewForExpandedState(expanded);
}
void AshNotificationView::UpdateWithNotification(
const message_center::Notification& notification) {
is_grouped_child_view_ = notification.group_child();
is_grouped_parent_view_ = notification.group_parent();
grouped_notifications_container_->SetVisible(is_grouped_parent_view_);
header_row()->SetVisible(!is_grouped_child_view_);
UpdateMessageViewInExpandedState(notification);
NotificationViewBase::UpdateWithNotification(notification);
}
void AshNotificationView::CreateOrUpdateHeaderView(
const message_center::Notification& notification) {
switch (notification.system_notification_warning_level()) {
case message_center::SystemNotificationWarningLevel::WARNING:
header_row()->SetSummaryText(
l10n_util::GetStringUTF16(IDS_ASH_NOTIFICATION_WARNING_LABEL));
break;
case message_center::SystemNotificationWarningLevel::CRITICAL_WARNING:
header_row()->SetSummaryText(l10n_util::GetStringUTF16(
IDS_ASH_NOTIFICATION_CRITICAL_WARNING_LABEL));
break;
case message_center::SystemNotificationWarningLevel::NORMAL:
header_row()->SetSummaryText(std::u16string());
break;
}
NotificationViewBase::CreateOrUpdateHeaderView(notification);
}
void AshNotificationView::CreateOrUpdateTitleView(
const message_center::Notification& notification) {
if (notification.title().empty()) {
if (title_row_) {
DCHECK(left_content()->Contains(title_row_));
left_content()->RemoveChildViewT(title_row_);
title_row_ = nullptr;
}
return;
}
const std::u16string& title = gfx::TruncateString(
notification.title(), kTitleCharacterLimit, gfx::WORD_BREAK);
if (!title_row_) {
title_row_ =
AddViewToLeftContent(std::make_unique<NotificationTitleRow>(title));
} else {
title_row_->UpdateTitle(title);
ReorderViewInLeftContent(title_row_);
}
title_row_->UpdateTimestamp(notification.timestamp());
}
void AshNotificationView::CreateOrUpdateSmallIconView(
const message_center::Notification& notification) {
if (is_grouped_child_view_ && !notification.icon().IsEmpty()) {
app_icon_view_->SetImage(notification.icon().AsImageSkia(),
gfx::Size(kAppIconViewSize, kAppIconViewSize));
return;
}
// TODO(crbug/1241990): Since we haven't decided which color we will use for
// app icon, we will need to change this part later.
SkColor icon_color = notification.accent_color().value_or(
AshColorProvider::Get()->GetContentLayerColor(
ash::AshColorProvider::ContentLayerType::kTextColorPrimary));
// TODO(crbug.com/768748): figure out if this has a performance impact and
// cache images if so.
gfx::Image masked_small_icon = notification.GenerateMaskedSmallIcon(
kAppIconViewSize, icon_color,
AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kControlBackgroundColorInactive),
AshColorProvider::Get()->GetContentLayerColor(
ash::AshColorProvider::ContentLayerType::kTextColorPrimary));
if (masked_small_icon.IsEmpty()) {
app_icon_view_->SetImage(
gfx::CreateVectorIcon(message_center::kProductIcon, kAppIconViewSize,
SK_ColorWHITE),
gfx::Size(kAppIconViewSize, kAppIconViewSize));
} else {
app_icon_view_->SetImage(masked_small_icon.AsImageSkia(),
gfx::Size(kAppIconViewSize, kAppIconViewSize));
}
}
void AshNotificationView::CreateOrUpdateInlineSettingsViews(
const message_center::Notification& notification) {
if (inline_settings_enabled()) {
DCHECK_EQ(message_center::SettingsButtonHandler::INLINE,
notification.rich_notification_data().settings_button_handler);
return;
}
set_inline_settings_enabled(
notification.rich_notification_data().settings_button_handler ==
message_center::SettingsButtonHandler::INLINE);
if (!inline_settings_enabled()) {
return;
}
// This string can be very long. Do we put this inside a button (any text
// length limit)
// Q2: What is the big settings button on the right side?
inline_settings_row()->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(), 0));
auto turn_off_notifications_button = GenerateNotificationLabelButton(
base::BindRepeating(&AshNotificationView::DisableNotification,
base::Unretained(this)),
l10n_util::GetStringUTF16(
IDS_ASH_NOTIFICATION_INLINE_SETTINGS_TURN_OFF_BUTTON_TEXT));
turn_off_notifications_button_ = inline_settings_row()->AddChildView(
std::move(turn_off_notifications_button));
auto inline_settings_cancel_button = GenerateNotificationLabelButton(
base::BindRepeating(&AshNotificationView::ToggleInlineSettings,
base::Unretained(this)),
l10n_util::GetStringUTF16(
IDS_ASH_NOTIFICATION_INLINE_SETTINGS_CANCEL_BUTTON_TEXT));
inline_settings_cancel_button_ = inline_settings_row()->AddChildView(
std::move(inline_settings_cancel_button));
}
bool AshNotificationView::IsIconViewShown() const {
return NotificationViewBase::IsIconViewShown() && !is_grouped_child_view_;
}
void AshNotificationView::SetExpandButtonEnabled(bool enabled) {
expand_button_->SetVisible(enabled);
}
bool AshNotificationView::IsExpandable() const {
// Inline settings can not be expanded.
if (GetMode() == Mode::SETTING)
return false;
// Notification should always be expandable since we hide `header_row()` in
// collapsed state.
return true;
}
void AshNotificationView::UpdateCornerRadius(int top_radius,
int bottom_radius) {
// Call parent's SetCornerRadius to update radius used for highlight path.
NotificationViewBase::SetCornerRadius(top_radius, bottom_radius);
UpdateBackground(top_radius, bottom_radius);
}
void AshNotificationView::SetDrawBackgroundAsActive(bool active) {}
void AshNotificationView::OnThemeChanged() {
views::View::OnThemeChanged();
UpdateBackground(top_radius_, bottom_radius_);
header_row()->SetColor(AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorSecondary));
views::FocusRing::Get(this)->SetColor(
AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kFocusRingColor));
}
std::unique_ptr<message_center::NotificationInputContainer>
AshNotificationView::GenerateNotificationInputContainer() {
return std::make_unique<AshNotificationInputContainer>(this);
}
std::unique_ptr<views::LabelButton>
AshNotificationView::GenerateNotificationLabelButton(
views::Button::PressedCallback callback,
const std::u16string& label) {
std::unique_ptr<views::LabelButton> actions_button =
std::make_unique<PillButton>(std::move(callback), label,
PillButton::Type::kIconlessAccentFloating,
/*icon=*/nullptr);
// Override the inkdrop configuration to make sure it will show up when hover
// or focus on the button.
PillButton::ConfigureInkDrop(actions_button.get(),
TrayPopupInkDropStyle::FILL_BOUNDS,
/*highlight_on_hover=*/true,
/*highlight_on_focus=*/true);
return actions_button;
}
gfx::Size AshNotificationView::GetIconViewSize() const {
return gfx::Size(kIconViewSize, kIconViewSize);
}
void AshNotificationView::ToggleInlineSettings(const ui::Event& event) {
if (!inline_settings_enabled())
return;
NotificationViewBase::ToggleInlineSettings(event);
bool inline_settings_visible = inline_settings_row()->GetVisible();
// In settings UI, we only show the app icon and header row along with the
// inline settings UI.
header_row()->SetVisible(true);
left_content()->SetVisible(!inline_settings_visible);
right_content()->SetVisible(!inline_settings_visible);
expand_button_->SetVisible(!inline_settings_visible);
}
void AshNotificationView::UpdateMessageViewInExpandedState(
const message_center::Notification& notification) {
if (notification.message().empty()) {
message_view_in_expanded_state_->SetVisible(false);
return;
}
message_view_in_expanded_state_->SetText(gfx::TruncateString(
notification.message(), message_center::kMessageCharacterLimit,
gfx::WORD_BREAK));
message_view_in_expanded_state_->SetVisible(true);
}
void AshNotificationView::UpdateBackground(int top_radius, int bottom_radius) {
SkColor background_color;
if (shown_in_popup_) {
background_color = AshColorProvider::Get()->GetBaseLayerColor(
AshColorProvider::BaseLayerType::kTransparent80);
} else {
background_color = AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kControlBackgroundColorInactive);
}
if (background_color == background_color_ && top_radius_ == top_radius &&
bottom_radius_ == bottom_radius) {
return;
}
if (!is_grouped_child_view_)
background_color_ = background_color;
top_radius_ = top_radius;
bottom_radius_ = bottom_radius;
SetBackground(views::CreateBackgroundFromPainter(
std::make_unique<message_center::NotificationBackgroundPainter>(
top_radius_, bottom_radius_, background_color_)));
}
int AshNotificationView::GetExpandedMessageViewWidth() {
int notification_width = shown_in_popup_ ? message_center::kNotificationWidth
: kNotificationInMessageCenterWidth;
return notification_width - kNotificationViewPadding.width() -
kAppIconViewSize - kMainRightViewPadding.width() -
kMainRightViewChildPadding.width();
}
void AshNotificationView::DisableNotification() {
message_center::MessageCenter::Get()->DisableNotification(notification_id());
}
} // namespace ash
| [
"chromium-scoped@luci-project-accounts.iam.gserviceaccount.com"
] | chromium-scoped@luci-project-accounts.iam.gserviceaccount.com |
b5af2419919acab6c80a65fbaae666881c8e4874 | 6b2a8dd202fdce77c971c412717e305e1caaac51 | /solutions_5708284669460480_0/C++/KraBrR/main.cpp | 7c2ea58efe2080876eda3962ced6cb476c8fa873 | [] | no_license | alexandraback/datacollection | 0bc67a9ace00abbc843f4912562f3a064992e0e9 | 076a7bc7693f3abf07bfdbdac838cb4ef65ccfcf | refs/heads/master | 2021-01-24T18:27:24.417992 | 2017-05-23T09:23:38 | 2017-05-23T09:23:38 | 84,313,442 | 2 | 4 | null | null | null | null | UTF-8 | C++ | false | false | 2,912 | cpp | //
// main.cpp
// CodeJam2015_3_B
//
// Created by Nataphol Baramichai on 5/10/2558 BE.
// Copyright (c) 2558 krabrr. All rights reserved.
//
#include <map>
#include <vector>
#include <stdio.h>
#include <iostream>
using namespace std;
bool debug = false;
bool debug_detail = false;
int main() {
int n;
cin >> n;
int caseIndex = 1;
for (int i = 0; i < n; i++) {
int k, l, s;
cin >> k >> l >> s;
string key, target;
cin >> key >> target;
map<char, int> keyMap;
for (int j = 0; j < key.length(); j++) {
keyMap[key[j]]++;
}
if (debug) {
cout << "k: " << k << " l: " << l << " s: " << s << endl;
cout << "key: " << key << endl;
cout << "target: " << target << endl;
}
bool valid = true;
for (int j = 0; j < target.length(); j++) {
if (keyMap[target[j]] == 0) {
valid = false;
}
}
double ans;
if (valid) {
int stack = 0;
if (target.length() > 1 && target[0] == target[target.length()-1]) {
stack = 1;
}
char first = target[0];
bool all_same = true;
for (int j = 0; j < target.length(); j++) {
if (target[j] != first) {
all_same = false;
break;
}
}
if (all_same) {
stack = l-1;
}
if (debug) {
cout << "stack: " << stack << endl;
}
double avg_pos = 1.0;
double prep_banana = 0;
if (stack > 0) {
int c_count = l;
prep_banana = 1;
for (int j = 0; j < 1000; j++) {
c_count += l-stack;
if (debug_detail) {
cout << "count: " << c_count << endl;
}
if (c_count > s) {
break;
}
prep_banana++;
}
}
else {
prep_banana = (int) s/l;
}
for (int j = 0; j < target.length(); j++) {
avg_pos *= (double) keyMap[target[j]]/k;
}
avg_pos *= prep_banana;
ans = prep_banana-avg_pos;
if (debug) {
cout << "prep: " << prep_banana << ", pos: " << avg_pos << endl;
}
}
else {
ans = 0;
}
printf("Case #%d: %.10f", caseIndex, ans);
if (i != n-1) {
printf("\n");
}
caseIndex++;
}
return 0;
}
| [
"eewestman@gmail.com"
] | eewestman@gmail.com |
9564c0c4fb40c308571a12f1a7ae0c14dc75825e | 3fc047a7c124bfe3f7958b32f4b95f4ac790b7b0 | /Classes/LostLayer.h | 3d690db80cdb1ac6f9b3e1b83eb6e76dd5e8180a | [] | no_license | 1600603/ballon | ab041fa4b11ed499fe0ab4027b54b1c4de6d598b | 8629bc32ed23af5f8b7984105c1ae6a3003d96c1 | refs/heads/master | 2021-01-18T03:57:42.251008 | 2017-04-10T22:45:33 | 2017-04-10T22:45:33 | 85,773,767 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 880 | h | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: LostLayer.h
* Author: guilherme
*
* Created on 4 de Abril de 2017, 22:04
*/
#ifndef LOSTLAYER_H
#define LOSTLAYER_H
#include "cocos2d.h"
#include "ui/UIWidget.h"
#include "ui/UIButton.h"
#include "cocostudio/CocoStudio.h"
#include "GameScene.h"
using namespace cocos2d;
class LostLayer : public cocos2d::LayerColor
{
public:
LostLayer();
~LostLayer();
static cocos2d::LayerColor* createLayer(GameScene* gs, bool isRecord=false);
virtual bool init();
virtual void onEnter();
static void setCallbacks(Node* parent);
static GameScene* gamescene;
bool isrecord = false;
CREATE_FUNC(LostLayer);
private:
};
#endif /* LOSTLAYER_H */
| [
"riosjr@gmail.com"
] | riosjr@gmail.com |
1ed4818b9c687b6e4ff81389e76eb0a056836079 | c776476e9d06b3779d744641e758ac3a2c15cddc | /examples/litmus/c/run-scripts/tmp_1/R+rfi-ctrl-rfi-ctrl+dmb.sy.c.cbmc.cpp | 08911bd90739a3a06e3663d72f014bc125387621 | [] | no_license | ashutosh0gupta/llvm_bmc | aaac7961c723ba6f7ffd77a39559e0e52432eade | 0287c4fb180244e6b3c599a9902507f05c8a7234 | refs/heads/master | 2023-08-02T17:14:06.178723 | 2023-07-31T10:46:53 | 2023-07-31T10:46:53 | 143,100,825 | 3 | 4 | null | 2023-05-25T05:50:55 | 2018-08-01T03:47:00 | C++ | UTF-8 | C++ | false | false | 44,428 | cpp | // 0:vars:3
// 4:atom_0_X5_1:1
// 7:thr1:1
// 3:atom_0_X2_1:1
// 5:atom_1_X2_0:1
// 6:thr0:1
#define ADDRSIZE 8
#define NPROC 3
#define NCONTEXT 1
#define ASSUME(stmt) __CPROVER_assume(stmt)
#define ASSERT(stmt) __CPROVER_assert(stmt, "error")
#define max(a,b) (a>b?a:b)
char __get_rng();
char get_rng( char from, char to ) {
char ret = __get_rng();
ASSUME(ret >= from && ret <= to);
return ret;
}
char get_rng_th( char from, char to ) {
char ret = __get_rng();
ASSUME(ret >= from && ret <= to);
return ret;
}
int main(int argc, char **argv) {
// declare arrays for intial value version in contexts
int meminit_[ADDRSIZE*NCONTEXT];
#define meminit(x,k) meminit_[(x)*NCONTEXT+k]
int coinit_[ADDRSIZE*NCONTEXT];
#define coinit(x,k) coinit_[(x)*NCONTEXT+k]
int deltainit_[ADDRSIZE*NCONTEXT];
#define deltainit(x,k) deltainit_[(x)*NCONTEXT+k]
// declare arrays for running value version in contexts
int mem_[ADDRSIZE*NCONTEXT];
#define mem(x,k) mem_[(x)*NCONTEXT+k]
int co_[ADDRSIZE*NCONTEXT];
#define co(x,k) co_[(x)*NCONTEXT+k]
int delta_[ADDRSIZE*NCONTEXT];
#define delta(x,k) delta_[(x)*NCONTEXT+k]
// declare arrays for local buffer and observed writes
int buff_[NPROC*ADDRSIZE];
#define buff(x,k) buff_[(x)*ADDRSIZE+k]
int pw_[NPROC*ADDRSIZE];
#define pw(x,k) pw_[(x)*ADDRSIZE+k]
// declare arrays for context stamps
char cr_[NPROC*ADDRSIZE];
#define cr(x,k) cr_[(x)*ADDRSIZE+k]
char iw_[NPROC*ADDRSIZE];
#define iw(x,k) iw_[(x)*ADDRSIZE+k]
char cw_[NPROC*ADDRSIZE];
#define cw(x,k) cw_[(x)*ADDRSIZE+k]
char cx_[NPROC*ADDRSIZE];
#define cx(x,k) cx_[(x)*ADDRSIZE+k]
char is_[NPROC*ADDRSIZE];
#define is(x,k) is_[(x)*ADDRSIZE+k]
char cs_[NPROC*ADDRSIZE];
#define cs(x,k) cs_[(x)*ADDRSIZE+k]
char crmax_[NPROC*ADDRSIZE];
#define crmax(x,k) crmax_[(x)*ADDRSIZE+k]
char sforbid_[ADDRSIZE*NCONTEXT];
#define sforbid(x,k) sforbid_[(x)*NCONTEXT+k]
// declare arrays for synchronizations
int cl[NPROC];
int cdy[NPROC];
int cds[NPROC];
int cdl[NPROC];
int cisb[NPROC];
int caddr[NPROC];
int cctrl[NPROC];
int cstart[NPROC];
int creturn[NPROC];
// declare arrays for contexts activity
int active[NCONTEXT];
int ctx_used[NCONTEXT];
__LOCALS__
buff(0,0) = 0;
pw(0,0) = 0;
cr(0,0) = 0;
iw(0,0) = 0;
cw(0,0) = 0;
cx(0,0) = 0;
is(0,0) = 0;
cs(0,0) = 0;
crmax(0,0) = 0;
buff(0,1) = 0;
pw(0,1) = 0;
cr(0,1) = 0;
iw(0,1) = 0;
cw(0,1) = 0;
cx(0,1) = 0;
is(0,1) = 0;
cs(0,1) = 0;
crmax(0,1) = 0;
buff(0,2) = 0;
pw(0,2) = 0;
cr(0,2) = 0;
iw(0,2) = 0;
cw(0,2) = 0;
cx(0,2) = 0;
is(0,2) = 0;
cs(0,2) = 0;
crmax(0,2) = 0;
buff(0,3) = 0;
pw(0,3) = 0;
cr(0,3) = 0;
iw(0,3) = 0;
cw(0,3) = 0;
cx(0,3) = 0;
is(0,3) = 0;
cs(0,3) = 0;
crmax(0,3) = 0;
buff(0,4) = 0;
pw(0,4) = 0;
cr(0,4) = 0;
iw(0,4) = 0;
cw(0,4) = 0;
cx(0,4) = 0;
is(0,4) = 0;
cs(0,4) = 0;
crmax(0,4) = 0;
buff(0,5) = 0;
pw(0,5) = 0;
cr(0,5) = 0;
iw(0,5) = 0;
cw(0,5) = 0;
cx(0,5) = 0;
is(0,5) = 0;
cs(0,5) = 0;
crmax(0,5) = 0;
buff(0,6) = 0;
pw(0,6) = 0;
cr(0,6) = 0;
iw(0,6) = 0;
cw(0,6) = 0;
cx(0,6) = 0;
is(0,6) = 0;
cs(0,6) = 0;
crmax(0,6) = 0;
buff(0,7) = 0;
pw(0,7) = 0;
cr(0,7) = 0;
iw(0,7) = 0;
cw(0,7) = 0;
cx(0,7) = 0;
is(0,7) = 0;
cs(0,7) = 0;
crmax(0,7) = 0;
cl[0] = 0;
cdy[0] = 0;
cds[0] = 0;
cdl[0] = 0;
cisb[0] = 0;
caddr[0] = 0;
cctrl[0] = 0;
cstart[0] = get_rng(0,NCONTEXT-1);
creturn[0] = get_rng(0,NCONTEXT-1);
buff(1,0) = 0;
pw(1,0) = 0;
cr(1,0) = 0;
iw(1,0) = 0;
cw(1,0) = 0;
cx(1,0) = 0;
is(1,0) = 0;
cs(1,0) = 0;
crmax(1,0) = 0;
buff(1,1) = 0;
pw(1,1) = 0;
cr(1,1) = 0;
iw(1,1) = 0;
cw(1,1) = 0;
cx(1,1) = 0;
is(1,1) = 0;
cs(1,1) = 0;
crmax(1,1) = 0;
buff(1,2) = 0;
pw(1,2) = 0;
cr(1,2) = 0;
iw(1,2) = 0;
cw(1,2) = 0;
cx(1,2) = 0;
is(1,2) = 0;
cs(1,2) = 0;
crmax(1,2) = 0;
buff(1,3) = 0;
pw(1,3) = 0;
cr(1,3) = 0;
iw(1,3) = 0;
cw(1,3) = 0;
cx(1,3) = 0;
is(1,3) = 0;
cs(1,3) = 0;
crmax(1,3) = 0;
buff(1,4) = 0;
pw(1,4) = 0;
cr(1,4) = 0;
iw(1,4) = 0;
cw(1,4) = 0;
cx(1,4) = 0;
is(1,4) = 0;
cs(1,4) = 0;
crmax(1,4) = 0;
buff(1,5) = 0;
pw(1,5) = 0;
cr(1,5) = 0;
iw(1,5) = 0;
cw(1,5) = 0;
cx(1,5) = 0;
is(1,5) = 0;
cs(1,5) = 0;
crmax(1,5) = 0;
buff(1,6) = 0;
pw(1,6) = 0;
cr(1,6) = 0;
iw(1,6) = 0;
cw(1,6) = 0;
cx(1,6) = 0;
is(1,6) = 0;
cs(1,6) = 0;
crmax(1,6) = 0;
buff(1,7) = 0;
pw(1,7) = 0;
cr(1,7) = 0;
iw(1,7) = 0;
cw(1,7) = 0;
cx(1,7) = 0;
is(1,7) = 0;
cs(1,7) = 0;
crmax(1,7) = 0;
cl[1] = 0;
cdy[1] = 0;
cds[1] = 0;
cdl[1] = 0;
cisb[1] = 0;
caddr[1] = 0;
cctrl[1] = 0;
cstart[1] = get_rng(0,NCONTEXT-1);
creturn[1] = get_rng(0,NCONTEXT-1);
buff(2,0) = 0;
pw(2,0) = 0;
cr(2,0) = 0;
iw(2,0) = 0;
cw(2,0) = 0;
cx(2,0) = 0;
is(2,0) = 0;
cs(2,0) = 0;
crmax(2,0) = 0;
buff(2,1) = 0;
pw(2,1) = 0;
cr(2,1) = 0;
iw(2,1) = 0;
cw(2,1) = 0;
cx(2,1) = 0;
is(2,1) = 0;
cs(2,1) = 0;
crmax(2,1) = 0;
buff(2,2) = 0;
pw(2,2) = 0;
cr(2,2) = 0;
iw(2,2) = 0;
cw(2,2) = 0;
cx(2,2) = 0;
is(2,2) = 0;
cs(2,2) = 0;
crmax(2,2) = 0;
buff(2,3) = 0;
pw(2,3) = 0;
cr(2,3) = 0;
iw(2,3) = 0;
cw(2,3) = 0;
cx(2,3) = 0;
is(2,3) = 0;
cs(2,3) = 0;
crmax(2,3) = 0;
buff(2,4) = 0;
pw(2,4) = 0;
cr(2,4) = 0;
iw(2,4) = 0;
cw(2,4) = 0;
cx(2,4) = 0;
is(2,4) = 0;
cs(2,4) = 0;
crmax(2,4) = 0;
buff(2,5) = 0;
pw(2,5) = 0;
cr(2,5) = 0;
iw(2,5) = 0;
cw(2,5) = 0;
cx(2,5) = 0;
is(2,5) = 0;
cs(2,5) = 0;
crmax(2,5) = 0;
buff(2,6) = 0;
pw(2,6) = 0;
cr(2,6) = 0;
iw(2,6) = 0;
cw(2,6) = 0;
cx(2,6) = 0;
is(2,6) = 0;
cs(2,6) = 0;
crmax(2,6) = 0;
buff(2,7) = 0;
pw(2,7) = 0;
cr(2,7) = 0;
iw(2,7) = 0;
cw(2,7) = 0;
cx(2,7) = 0;
is(2,7) = 0;
cs(2,7) = 0;
crmax(2,7) = 0;
cl[2] = 0;
cdy[2] = 0;
cds[2] = 0;
cdl[2] = 0;
cisb[2] = 0;
caddr[2] = 0;
cctrl[2] = 0;
cstart[2] = get_rng(0,NCONTEXT-1);
creturn[2] = get_rng(0,NCONTEXT-1);
// Dumping initializations
mem(0+0,0) = 0;
mem(0+1,0) = 0;
mem(0+2,0) = 0;
mem(4+0,0) = 0;
mem(7+0,0) = 0;
mem(3+0,0) = 0;
mem(5+0,0) = 0;
mem(6+0,0) = 0;
// Dumping context matching equalities
co(0,0) = 0;
delta(0,0) = -1;
co(1,0) = 0;
delta(1,0) = -1;
co(2,0) = 0;
delta(2,0) = -1;
co(3,0) = 0;
delta(3,0) = -1;
co(4,0) = 0;
delta(4,0) = -1;
co(5,0) = 0;
delta(5,0) = -1;
co(6,0) = 0;
delta(6,0) = -1;
co(7,0) = 0;
delta(7,0) = -1;
// Dumping thread 1
int ret_thread_1 = 0;
cdy[1] = get_rng(0,NCONTEXT-1);
ASSUME(cdy[1] >= cstart[1]);
T1BLOCK0:
// call void @llvm.dbg.value(metadata i8* %arg, metadata !37, metadata !DIExpression()), !dbg !68
// br label %label_1, !dbg !69
goto T1BLOCK1;
T1BLOCK1:
// call void @llvm.dbg.label(metadata !65), !dbg !70
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 0), metadata !38, metadata !DIExpression()), !dbg !71
// call void @llvm.dbg.value(metadata i64 1, metadata !41, metadata !DIExpression()), !dbg !71
// store atomic i64 1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 0) monotonic, align 8, !dbg !72
// ST: Guess
iw(1,0) = get_rng(0,NCONTEXT-1);// 1 ASSIGN STIW
old_cw = cw(1,0);
cw(1,0) = get_rng(0,NCONTEXT-1);// 1 ASSIGN STCOM
// Check
ASSUME(active[iw(1,0)] == 1);
ASSUME(active[cw(1,0)] == 1);
ASSUME(sforbid(0,cw(1,0))== 0);
ASSUME(iw(1,0) >= 0);
ASSUME(iw(1,0) >= 0);
ASSUME(cw(1,0) >= iw(1,0));
ASSUME(cw(1,0) >= old_cw);
ASSUME(cw(1,0) >= cr(1,0));
ASSUME(cw(1,0) >= cl[1]);
ASSUME(cw(1,0) >= cisb[1]);
ASSUME(cw(1,0) >= cdy[1]);
ASSUME(cw(1,0) >= cdl[1]);
ASSUME(cw(1,0) >= cds[1]);
ASSUME(cw(1,0) >= cctrl[1]);
ASSUME(cw(1,0) >= caddr[1]);
// Update
caddr[1] = max(caddr[1],0);
buff(1,0) = 1;
mem(0,cw(1,0)) = 1;
co(0,cw(1,0))+=1;
delta(0,cw(1,0)) = -1;
ASSUME(creturn[1] >= cw(1,0));
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 0), metadata !44, metadata !DIExpression()), !dbg !73
// %0 = load atomic i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 0) monotonic, align 8, !dbg !74
// LD: Guess
old_cr = cr(1,0);
cr(1,0) = get_rng(0,NCONTEXT-1);// 1 ASSIGN LDCOM
// Check
ASSUME(active[cr(1,0)] == 1);
ASSUME(cr(1,0) >= iw(1,0));
ASSUME(cr(1,0) >= 0);
ASSUME(cr(1,0) >= cdy[1]);
ASSUME(cr(1,0) >= cisb[1]);
ASSUME(cr(1,0) >= cdl[1]);
ASSUME(cr(1,0) >= cl[1]);
// Update
creg_r0 = cr(1,0);
crmax(1,0) = max(crmax(1,0),cr(1,0));
caddr[1] = max(caddr[1],0);
if(cr(1,0) < cw(1,0)) {
r0 = buff(1,0);
} else {
if(pw(1,0) != co(0,cr(1,0))) {
ASSUME(cr(1,0) >= old_cr);
}
pw(1,0) = co(0,cr(1,0));
r0 = mem(0,cr(1,0));
}
ASSUME(creturn[1] >= cr(1,0));
// call void @llvm.dbg.value(metadata i64 %0, metadata !46, metadata !DIExpression()), !dbg !73
// %conv = trunc i64 %0 to i32, !dbg !75
// call void @llvm.dbg.value(metadata i32 %conv, metadata !42, metadata !DIExpression()), !dbg !68
// %tobool = icmp ne i32 %conv, 0, !dbg !76
// br i1 %tobool, label %if.then, label %if.else, !dbg !78
old_cctrl = cctrl[1];
cctrl[1] = get_rng(0,NCONTEXT-1);
ASSUME(cctrl[1] >= old_cctrl);
ASSUME(cctrl[1] >= creg_r0);
ASSUME(cctrl[1] >= 0);
if((r0!=0)) {
goto T1BLOCK2;
} else {
goto T1BLOCK3;
}
T1BLOCK2:
// br label %lbl_LC00, !dbg !79
goto T1BLOCK4;
T1BLOCK3:
// br label %lbl_LC00, !dbg !80
goto T1BLOCK4;
T1BLOCK4:
// call void @llvm.dbg.label(metadata !66), !dbg !81
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 1), metadata !47, metadata !DIExpression()), !dbg !82
// call void @llvm.dbg.value(metadata i64 1, metadata !49, metadata !DIExpression()), !dbg !82
// store atomic i64 1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 1) monotonic, align 8, !dbg !83
// ST: Guess
iw(1,0+1*1) = get_rng(0,NCONTEXT-1);// 1 ASSIGN STIW
old_cw = cw(1,0+1*1);
cw(1,0+1*1) = get_rng(0,NCONTEXT-1);// 1 ASSIGN STCOM
// Check
ASSUME(active[iw(1,0+1*1)] == 1);
ASSUME(active[cw(1,0+1*1)] == 1);
ASSUME(sforbid(0+1*1,cw(1,0+1*1))== 0);
ASSUME(iw(1,0+1*1) >= 0);
ASSUME(iw(1,0+1*1) >= 0);
ASSUME(cw(1,0+1*1) >= iw(1,0+1*1));
ASSUME(cw(1,0+1*1) >= old_cw);
ASSUME(cw(1,0+1*1) >= cr(1,0+1*1));
ASSUME(cw(1,0+1*1) >= cl[1]);
ASSUME(cw(1,0+1*1) >= cisb[1]);
ASSUME(cw(1,0+1*1) >= cdy[1]);
ASSUME(cw(1,0+1*1) >= cdl[1]);
ASSUME(cw(1,0+1*1) >= cds[1]);
ASSUME(cw(1,0+1*1) >= cctrl[1]);
ASSUME(cw(1,0+1*1) >= caddr[1]);
// Update
caddr[1] = max(caddr[1],0);
buff(1,0+1*1) = 1;
mem(0+1*1,cw(1,0+1*1)) = 1;
co(0+1*1,cw(1,0+1*1))+=1;
delta(0+1*1,cw(1,0+1*1)) = -1;
ASSUME(creturn[1] >= cw(1,0+1*1));
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 1), metadata !51, metadata !DIExpression()), !dbg !84
// %1 = load atomic i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 1) monotonic, align 8, !dbg !85
// LD: Guess
old_cr = cr(1,0+1*1);
cr(1,0+1*1) = get_rng(0,NCONTEXT-1);// 1 ASSIGN LDCOM
// Check
ASSUME(active[cr(1,0+1*1)] == 1);
ASSUME(cr(1,0+1*1) >= iw(1,0+1*1));
ASSUME(cr(1,0+1*1) >= 0);
ASSUME(cr(1,0+1*1) >= cdy[1]);
ASSUME(cr(1,0+1*1) >= cisb[1]);
ASSUME(cr(1,0+1*1) >= cdl[1]);
ASSUME(cr(1,0+1*1) >= cl[1]);
// Update
creg_r1 = cr(1,0+1*1);
crmax(1,0+1*1) = max(crmax(1,0+1*1),cr(1,0+1*1));
caddr[1] = max(caddr[1],0);
if(cr(1,0+1*1) < cw(1,0+1*1)) {
r1 = buff(1,0+1*1);
} else {
if(pw(1,0+1*1) != co(0+1*1,cr(1,0+1*1))) {
ASSUME(cr(1,0+1*1) >= old_cr);
}
pw(1,0+1*1) = co(0+1*1,cr(1,0+1*1));
r1 = mem(0+1*1,cr(1,0+1*1));
}
ASSUME(creturn[1] >= cr(1,0+1*1));
// call void @llvm.dbg.value(metadata i64 %1, metadata !53, metadata !DIExpression()), !dbg !84
// %conv6 = trunc i64 %1 to i32, !dbg !86
// call void @llvm.dbg.value(metadata i32 %conv6, metadata !50, metadata !DIExpression()), !dbg !68
// %tobool7 = icmp ne i32 %conv6, 0, !dbg !87
// br i1 %tobool7, label %if.then8, label %if.else9, !dbg !89
old_cctrl = cctrl[1];
cctrl[1] = get_rng(0,NCONTEXT-1);
ASSUME(cctrl[1] >= old_cctrl);
ASSUME(cctrl[1] >= creg_r1);
ASSUME(cctrl[1] >= 0);
if((r1!=0)) {
goto T1BLOCK5;
} else {
goto T1BLOCK6;
}
T1BLOCK5:
// br label %lbl_LC01, !dbg !90
goto T1BLOCK7;
T1BLOCK6:
// br label %lbl_LC01, !dbg !91
goto T1BLOCK7;
T1BLOCK7:
// call void @llvm.dbg.label(metadata !67), !dbg !92
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 2), metadata !54, metadata !DIExpression()), !dbg !93
// call void @llvm.dbg.value(metadata i64 1, metadata !56, metadata !DIExpression()), !dbg !93
// store atomic i64 1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 2) monotonic, align 8, !dbg !94
// ST: Guess
iw(1,0+2*1) = get_rng(0,NCONTEXT-1);// 1 ASSIGN STIW
old_cw = cw(1,0+2*1);
cw(1,0+2*1) = get_rng(0,NCONTEXT-1);// 1 ASSIGN STCOM
// Check
ASSUME(active[iw(1,0+2*1)] == 1);
ASSUME(active[cw(1,0+2*1)] == 1);
ASSUME(sforbid(0+2*1,cw(1,0+2*1))== 0);
ASSUME(iw(1,0+2*1) >= 0);
ASSUME(iw(1,0+2*1) >= 0);
ASSUME(cw(1,0+2*1) >= iw(1,0+2*1));
ASSUME(cw(1,0+2*1) >= old_cw);
ASSUME(cw(1,0+2*1) >= cr(1,0+2*1));
ASSUME(cw(1,0+2*1) >= cl[1]);
ASSUME(cw(1,0+2*1) >= cisb[1]);
ASSUME(cw(1,0+2*1) >= cdy[1]);
ASSUME(cw(1,0+2*1) >= cdl[1]);
ASSUME(cw(1,0+2*1) >= cds[1]);
ASSUME(cw(1,0+2*1) >= cctrl[1]);
ASSUME(cw(1,0+2*1) >= caddr[1]);
// Update
caddr[1] = max(caddr[1],0);
buff(1,0+2*1) = 1;
mem(0+2*1,cw(1,0+2*1)) = 1;
co(0+2*1,cw(1,0+2*1))+=1;
delta(0+2*1,cw(1,0+2*1)) = -1;
ASSUME(creturn[1] >= cw(1,0+2*1));
// %cmp = icmp eq i32 %conv, 1, !dbg !95
// %conv12 = zext i1 %cmp to i32, !dbg !95
// call void @llvm.dbg.value(metadata i32 %conv12, metadata !57, metadata !DIExpression()), !dbg !68
// call void @llvm.dbg.value(metadata i64* @atom_0_X2_1, metadata !58, metadata !DIExpression()), !dbg !96
// %2 = zext i32 %conv12 to i64
// call void @llvm.dbg.value(metadata i64 %2, metadata !60, metadata !DIExpression()), !dbg !96
// store atomic i64 %2, i64* @atom_0_X2_1 seq_cst, align 8, !dbg !97
// ST: Guess
iw(1,3) = get_rng(0,NCONTEXT-1);// 1 ASSIGN STIW
old_cw = cw(1,3);
cw(1,3) = get_rng(0,NCONTEXT-1);// 1 ASSIGN STCOM
// Check
ASSUME(active[iw(1,3)] == 1);
ASSUME(active[cw(1,3)] == 1);
ASSUME(sforbid(3,cw(1,3))== 0);
ASSUME(iw(1,3) >= max(creg_r0,0));
ASSUME(iw(1,3) >= 0);
ASSUME(cw(1,3) >= iw(1,3));
ASSUME(cw(1,3) >= old_cw);
ASSUME(cw(1,3) >= cr(1,3));
ASSUME(cw(1,3) >= cl[1]);
ASSUME(cw(1,3) >= cisb[1]);
ASSUME(cw(1,3) >= cdy[1]);
ASSUME(cw(1,3) >= cdl[1]);
ASSUME(cw(1,3) >= cds[1]);
ASSUME(cw(1,3) >= cctrl[1]);
ASSUME(cw(1,3) >= caddr[1]);
// Update
caddr[1] = max(caddr[1],0);
buff(1,3) = (r0==1);
mem(3,cw(1,3)) = (r0==1);
co(3,cw(1,3))+=1;
delta(3,cw(1,3)) = -1;
ASSUME(creturn[1] >= cw(1,3));
// %cmp16 = icmp eq i32 %conv6, 1, !dbg !98
// %conv17 = zext i1 %cmp16 to i32, !dbg !98
// call void @llvm.dbg.value(metadata i32 %conv17, metadata !61, metadata !DIExpression()), !dbg !68
// call void @llvm.dbg.value(metadata i64* @atom_0_X5_1, metadata !62, metadata !DIExpression()), !dbg !99
// %3 = zext i32 %conv17 to i64
// call void @llvm.dbg.value(metadata i64 %3, metadata !64, metadata !DIExpression()), !dbg !99
// store atomic i64 %3, i64* @atom_0_X5_1 seq_cst, align 8, !dbg !100
// ST: Guess
iw(1,4) = get_rng(0,NCONTEXT-1);// 1 ASSIGN STIW
old_cw = cw(1,4);
cw(1,4) = get_rng(0,NCONTEXT-1);// 1 ASSIGN STCOM
// Check
ASSUME(active[iw(1,4)] == 1);
ASSUME(active[cw(1,4)] == 1);
ASSUME(sforbid(4,cw(1,4))== 0);
ASSUME(iw(1,4) >= max(creg_r1,0));
ASSUME(iw(1,4) >= 0);
ASSUME(cw(1,4) >= iw(1,4));
ASSUME(cw(1,4) >= old_cw);
ASSUME(cw(1,4) >= cr(1,4));
ASSUME(cw(1,4) >= cl[1]);
ASSUME(cw(1,4) >= cisb[1]);
ASSUME(cw(1,4) >= cdy[1]);
ASSUME(cw(1,4) >= cdl[1]);
ASSUME(cw(1,4) >= cds[1]);
ASSUME(cw(1,4) >= cctrl[1]);
ASSUME(cw(1,4) >= caddr[1]);
// Update
caddr[1] = max(caddr[1],0);
buff(1,4) = (r1==1);
mem(4,cw(1,4)) = (r1==1);
co(4,cw(1,4))+=1;
delta(4,cw(1,4)) = -1;
ASSUME(creturn[1] >= cw(1,4));
// ret i8* null, !dbg !101
ret_thread_1 = (- 1);
// Dumping thread 2
int ret_thread_2 = 0;
cdy[2] = get_rng(0,NCONTEXT-1);
ASSUME(cdy[2] >= cstart[2]);
T2BLOCK0:
// call void @llvm.dbg.value(metadata i8* %arg, metadata !104, metadata !DIExpression()), !dbg !117
// br label %label_2, !dbg !53
goto T2BLOCK1;
T2BLOCK1:
// call void @llvm.dbg.label(metadata !116), !dbg !119
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 2), metadata !105, metadata !DIExpression()), !dbg !120
// call void @llvm.dbg.value(metadata i64 2, metadata !107, metadata !DIExpression()), !dbg !120
// store atomic i64 2, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 2) monotonic, align 8, !dbg !56
// ST: Guess
iw(2,0+2*1) = get_rng(0,NCONTEXT-1);// 2 ASSIGN STIW
old_cw = cw(2,0+2*1);
cw(2,0+2*1) = get_rng(0,NCONTEXT-1);// 2 ASSIGN STCOM
// Check
ASSUME(active[iw(2,0+2*1)] == 2);
ASSUME(active[cw(2,0+2*1)] == 2);
ASSUME(sforbid(0+2*1,cw(2,0+2*1))== 0);
ASSUME(iw(2,0+2*1) >= 0);
ASSUME(iw(2,0+2*1) >= 0);
ASSUME(cw(2,0+2*1) >= iw(2,0+2*1));
ASSUME(cw(2,0+2*1) >= old_cw);
ASSUME(cw(2,0+2*1) >= cr(2,0+2*1));
ASSUME(cw(2,0+2*1) >= cl[2]);
ASSUME(cw(2,0+2*1) >= cisb[2]);
ASSUME(cw(2,0+2*1) >= cdy[2]);
ASSUME(cw(2,0+2*1) >= cdl[2]);
ASSUME(cw(2,0+2*1) >= cds[2]);
ASSUME(cw(2,0+2*1) >= cctrl[2]);
ASSUME(cw(2,0+2*1) >= caddr[2]);
// Update
caddr[2] = max(caddr[2],0);
buff(2,0+2*1) = 2;
mem(0+2*1,cw(2,0+2*1)) = 2;
co(0+2*1,cw(2,0+2*1))+=1;
delta(0+2*1,cw(2,0+2*1)) = -1;
ASSUME(creturn[2] >= cw(2,0+2*1));
// call void (...) @dmbsy(), !dbg !57
// dumbsy: Guess
old_cdy = cdy[2];
cdy[2] = get_rng(0,NCONTEXT-1);
// Check
ASSUME(cdy[2] >= old_cdy);
ASSUME(cdy[2] >= cisb[2]);
ASSUME(cdy[2] >= cdl[2]);
ASSUME(cdy[2] >= cds[2]);
ASSUME(cdy[2] >= cctrl[2]);
ASSUME(cdy[2] >= cw(2,0+0));
ASSUME(cdy[2] >= cw(2,0+1));
ASSUME(cdy[2] >= cw(2,0+2));
ASSUME(cdy[2] >= cw(2,4+0));
ASSUME(cdy[2] >= cw(2,7+0));
ASSUME(cdy[2] >= cw(2,3+0));
ASSUME(cdy[2] >= cw(2,5+0));
ASSUME(cdy[2] >= cw(2,6+0));
ASSUME(cdy[2] >= cr(2,0+0));
ASSUME(cdy[2] >= cr(2,0+1));
ASSUME(cdy[2] >= cr(2,0+2));
ASSUME(cdy[2] >= cr(2,4+0));
ASSUME(cdy[2] >= cr(2,7+0));
ASSUME(cdy[2] >= cr(2,3+0));
ASSUME(cdy[2] >= cr(2,5+0));
ASSUME(cdy[2] >= cr(2,6+0));
ASSUME(creturn[2] >= cdy[2]);
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 0), metadata !109, metadata !DIExpression()), !dbg !123
// %0 = load atomic i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 0) monotonic, align 8, !dbg !59
// LD: Guess
old_cr = cr(2,0);
cr(2,0) = get_rng(0,NCONTEXT-1);// 2 ASSIGN LDCOM
// Check
ASSUME(active[cr(2,0)] == 2);
ASSUME(cr(2,0) >= iw(2,0));
ASSUME(cr(2,0) >= 0);
ASSUME(cr(2,0) >= cdy[2]);
ASSUME(cr(2,0) >= cisb[2]);
ASSUME(cr(2,0) >= cdl[2]);
ASSUME(cr(2,0) >= cl[2]);
// Update
creg_r2 = cr(2,0);
crmax(2,0) = max(crmax(2,0),cr(2,0));
caddr[2] = max(caddr[2],0);
if(cr(2,0) < cw(2,0)) {
r2 = buff(2,0);
} else {
if(pw(2,0) != co(0,cr(2,0))) {
ASSUME(cr(2,0) >= old_cr);
}
pw(2,0) = co(0,cr(2,0));
r2 = mem(0,cr(2,0));
}
ASSUME(creturn[2] >= cr(2,0));
// call void @llvm.dbg.value(metadata i64 %0, metadata !111, metadata !DIExpression()), !dbg !123
// %conv = trunc i64 %0 to i32, !dbg !60
// call void @llvm.dbg.value(metadata i32 %conv, metadata !108, metadata !DIExpression()), !dbg !117
// %cmp = icmp eq i32 %conv, 0, !dbg !61
// %conv1 = zext i1 %cmp to i32, !dbg !61
// call void @llvm.dbg.value(metadata i32 %conv1, metadata !112, metadata !DIExpression()), !dbg !117
// call void @llvm.dbg.value(metadata i64* @atom_1_X2_0, metadata !113, metadata !DIExpression()), !dbg !127
// %1 = zext i32 %conv1 to i64
// call void @llvm.dbg.value(metadata i64 %1, metadata !115, metadata !DIExpression()), !dbg !127
// store atomic i64 %1, i64* @atom_1_X2_0 seq_cst, align 8, !dbg !63
// ST: Guess
iw(2,5) = get_rng(0,NCONTEXT-1);// 2 ASSIGN STIW
old_cw = cw(2,5);
cw(2,5) = get_rng(0,NCONTEXT-1);// 2 ASSIGN STCOM
// Check
ASSUME(active[iw(2,5)] == 2);
ASSUME(active[cw(2,5)] == 2);
ASSUME(sforbid(5,cw(2,5))== 0);
ASSUME(iw(2,5) >= max(creg_r2,0));
ASSUME(iw(2,5) >= 0);
ASSUME(cw(2,5) >= iw(2,5));
ASSUME(cw(2,5) >= old_cw);
ASSUME(cw(2,5) >= cr(2,5));
ASSUME(cw(2,5) >= cl[2]);
ASSUME(cw(2,5) >= cisb[2]);
ASSUME(cw(2,5) >= cdy[2]);
ASSUME(cw(2,5) >= cdl[2]);
ASSUME(cw(2,5) >= cds[2]);
ASSUME(cw(2,5) >= cctrl[2]);
ASSUME(cw(2,5) >= caddr[2]);
// Update
caddr[2] = max(caddr[2],0);
buff(2,5) = (r2==0);
mem(5,cw(2,5)) = (r2==0);
co(5,cw(2,5))+=1;
delta(5,cw(2,5)) = -1;
ASSUME(creturn[2] >= cw(2,5));
// ret i8* null, !dbg !64
ret_thread_2 = (- 1);
// Dumping thread 0
int ret_thread_0 = 0;
cdy[0] = get_rng(0,NCONTEXT-1);
ASSUME(cdy[0] >= cstart[0]);
T0BLOCK0:
// %thr0 = alloca i64, align 8
// %thr1 = alloca i64, align 8
// call void @llvm.dbg.value(metadata i32 %argc, metadata !137, metadata !DIExpression()), !dbg !194
// call void @llvm.dbg.value(metadata i8** %argv, metadata !138, metadata !DIExpression()), !dbg !194
// %0 = bitcast i64* %thr0 to i8*, !dbg !100
// call void @llvm.lifetime.start.p0i8(i64 8, i8* %0) #7, !dbg !100
// call void @llvm.dbg.declare(metadata i64* %thr0, metadata !139, metadata !DIExpression()), !dbg !196
// %1 = bitcast i64* %thr1 to i8*, !dbg !102
// call void @llvm.lifetime.start.p0i8(i64 8, i8* %1) #7, !dbg !102
// call void @llvm.dbg.declare(metadata i64* %thr1, metadata !143, metadata !DIExpression()), !dbg !198
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 2), metadata !144, metadata !DIExpression()), !dbg !199
// call void @llvm.dbg.value(metadata i64 0, metadata !146, metadata !DIExpression()), !dbg !199
// store atomic i64 0, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 2) monotonic, align 8, !dbg !105
// ST: Guess
iw(0,0+2*1) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STIW
old_cw = cw(0,0+2*1);
cw(0,0+2*1) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STCOM
// Check
ASSUME(active[iw(0,0+2*1)] == 0);
ASSUME(active[cw(0,0+2*1)] == 0);
ASSUME(sforbid(0+2*1,cw(0,0+2*1))== 0);
ASSUME(iw(0,0+2*1) >= 0);
ASSUME(iw(0,0+2*1) >= 0);
ASSUME(cw(0,0+2*1) >= iw(0,0+2*1));
ASSUME(cw(0,0+2*1) >= old_cw);
ASSUME(cw(0,0+2*1) >= cr(0,0+2*1));
ASSUME(cw(0,0+2*1) >= cl[0]);
ASSUME(cw(0,0+2*1) >= cisb[0]);
ASSUME(cw(0,0+2*1) >= cdy[0]);
ASSUME(cw(0,0+2*1) >= cdl[0]);
ASSUME(cw(0,0+2*1) >= cds[0]);
ASSUME(cw(0,0+2*1) >= cctrl[0]);
ASSUME(cw(0,0+2*1) >= caddr[0]);
// Update
caddr[0] = max(caddr[0],0);
buff(0,0+2*1) = 0;
mem(0+2*1,cw(0,0+2*1)) = 0;
co(0+2*1,cw(0,0+2*1))+=1;
delta(0+2*1,cw(0,0+2*1)) = -1;
ASSUME(creturn[0] >= cw(0,0+2*1));
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 1), metadata !147, metadata !DIExpression()), !dbg !201
// call void @llvm.dbg.value(metadata i64 0, metadata !149, metadata !DIExpression()), !dbg !201
// store atomic i64 0, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 1) monotonic, align 8, !dbg !107
// ST: Guess
iw(0,0+1*1) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STIW
old_cw = cw(0,0+1*1);
cw(0,0+1*1) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STCOM
// Check
ASSUME(active[iw(0,0+1*1)] == 0);
ASSUME(active[cw(0,0+1*1)] == 0);
ASSUME(sforbid(0+1*1,cw(0,0+1*1))== 0);
ASSUME(iw(0,0+1*1) >= 0);
ASSUME(iw(0,0+1*1) >= 0);
ASSUME(cw(0,0+1*1) >= iw(0,0+1*1));
ASSUME(cw(0,0+1*1) >= old_cw);
ASSUME(cw(0,0+1*1) >= cr(0,0+1*1));
ASSUME(cw(0,0+1*1) >= cl[0]);
ASSUME(cw(0,0+1*1) >= cisb[0]);
ASSUME(cw(0,0+1*1) >= cdy[0]);
ASSUME(cw(0,0+1*1) >= cdl[0]);
ASSUME(cw(0,0+1*1) >= cds[0]);
ASSUME(cw(0,0+1*1) >= cctrl[0]);
ASSUME(cw(0,0+1*1) >= caddr[0]);
// Update
caddr[0] = max(caddr[0],0);
buff(0,0+1*1) = 0;
mem(0+1*1,cw(0,0+1*1)) = 0;
co(0+1*1,cw(0,0+1*1))+=1;
delta(0+1*1,cw(0,0+1*1)) = -1;
ASSUME(creturn[0] >= cw(0,0+1*1));
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 0), metadata !150, metadata !DIExpression()), !dbg !203
// call void @llvm.dbg.value(metadata i64 0, metadata !152, metadata !DIExpression()), !dbg !203
// store atomic i64 0, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 0) monotonic, align 8, !dbg !109
// ST: Guess
iw(0,0) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STIW
old_cw = cw(0,0);
cw(0,0) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STCOM
// Check
ASSUME(active[iw(0,0)] == 0);
ASSUME(active[cw(0,0)] == 0);
ASSUME(sforbid(0,cw(0,0))== 0);
ASSUME(iw(0,0) >= 0);
ASSUME(iw(0,0) >= 0);
ASSUME(cw(0,0) >= iw(0,0));
ASSUME(cw(0,0) >= old_cw);
ASSUME(cw(0,0) >= cr(0,0));
ASSUME(cw(0,0) >= cl[0]);
ASSUME(cw(0,0) >= cisb[0]);
ASSUME(cw(0,0) >= cdy[0]);
ASSUME(cw(0,0) >= cdl[0]);
ASSUME(cw(0,0) >= cds[0]);
ASSUME(cw(0,0) >= cctrl[0]);
ASSUME(cw(0,0) >= caddr[0]);
// Update
caddr[0] = max(caddr[0],0);
buff(0,0) = 0;
mem(0,cw(0,0)) = 0;
co(0,cw(0,0))+=1;
delta(0,cw(0,0)) = -1;
ASSUME(creturn[0] >= cw(0,0));
// call void @llvm.dbg.value(metadata i64* @atom_0_X2_1, metadata !153, metadata !DIExpression()), !dbg !205
// call void @llvm.dbg.value(metadata i64 0, metadata !155, metadata !DIExpression()), !dbg !205
// store atomic i64 0, i64* @atom_0_X2_1 monotonic, align 8, !dbg !111
// ST: Guess
iw(0,3) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STIW
old_cw = cw(0,3);
cw(0,3) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STCOM
// Check
ASSUME(active[iw(0,3)] == 0);
ASSUME(active[cw(0,3)] == 0);
ASSUME(sforbid(3,cw(0,3))== 0);
ASSUME(iw(0,3) >= 0);
ASSUME(iw(0,3) >= 0);
ASSUME(cw(0,3) >= iw(0,3));
ASSUME(cw(0,3) >= old_cw);
ASSUME(cw(0,3) >= cr(0,3));
ASSUME(cw(0,3) >= cl[0]);
ASSUME(cw(0,3) >= cisb[0]);
ASSUME(cw(0,3) >= cdy[0]);
ASSUME(cw(0,3) >= cdl[0]);
ASSUME(cw(0,3) >= cds[0]);
ASSUME(cw(0,3) >= cctrl[0]);
ASSUME(cw(0,3) >= caddr[0]);
// Update
caddr[0] = max(caddr[0],0);
buff(0,3) = 0;
mem(3,cw(0,3)) = 0;
co(3,cw(0,3))+=1;
delta(3,cw(0,3)) = -1;
ASSUME(creturn[0] >= cw(0,3));
// call void @llvm.dbg.value(metadata i64* @atom_0_X5_1, metadata !156, metadata !DIExpression()), !dbg !207
// call void @llvm.dbg.value(metadata i64 0, metadata !158, metadata !DIExpression()), !dbg !207
// store atomic i64 0, i64* @atom_0_X5_1 monotonic, align 8, !dbg !113
// ST: Guess
iw(0,4) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STIW
old_cw = cw(0,4);
cw(0,4) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STCOM
// Check
ASSUME(active[iw(0,4)] == 0);
ASSUME(active[cw(0,4)] == 0);
ASSUME(sforbid(4,cw(0,4))== 0);
ASSUME(iw(0,4) >= 0);
ASSUME(iw(0,4) >= 0);
ASSUME(cw(0,4) >= iw(0,4));
ASSUME(cw(0,4) >= old_cw);
ASSUME(cw(0,4) >= cr(0,4));
ASSUME(cw(0,4) >= cl[0]);
ASSUME(cw(0,4) >= cisb[0]);
ASSUME(cw(0,4) >= cdy[0]);
ASSUME(cw(0,4) >= cdl[0]);
ASSUME(cw(0,4) >= cds[0]);
ASSUME(cw(0,4) >= cctrl[0]);
ASSUME(cw(0,4) >= caddr[0]);
// Update
caddr[0] = max(caddr[0],0);
buff(0,4) = 0;
mem(4,cw(0,4)) = 0;
co(4,cw(0,4))+=1;
delta(4,cw(0,4)) = -1;
ASSUME(creturn[0] >= cw(0,4));
// call void @llvm.dbg.value(metadata i64* @atom_1_X2_0, metadata !159, metadata !DIExpression()), !dbg !209
// call void @llvm.dbg.value(metadata i64 0, metadata !161, metadata !DIExpression()), !dbg !209
// store atomic i64 0, i64* @atom_1_X2_0 monotonic, align 8, !dbg !115
// ST: Guess
iw(0,5) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STIW
old_cw = cw(0,5);
cw(0,5) = get_rng(0,NCONTEXT-1);// 0 ASSIGN STCOM
// Check
ASSUME(active[iw(0,5)] == 0);
ASSUME(active[cw(0,5)] == 0);
ASSUME(sforbid(5,cw(0,5))== 0);
ASSUME(iw(0,5) >= 0);
ASSUME(iw(0,5) >= 0);
ASSUME(cw(0,5) >= iw(0,5));
ASSUME(cw(0,5) >= old_cw);
ASSUME(cw(0,5) >= cr(0,5));
ASSUME(cw(0,5) >= cl[0]);
ASSUME(cw(0,5) >= cisb[0]);
ASSUME(cw(0,5) >= cdy[0]);
ASSUME(cw(0,5) >= cdl[0]);
ASSUME(cw(0,5) >= cds[0]);
ASSUME(cw(0,5) >= cctrl[0]);
ASSUME(cw(0,5) >= caddr[0]);
// Update
caddr[0] = max(caddr[0],0);
buff(0,5) = 0;
mem(5,cw(0,5)) = 0;
co(5,cw(0,5))+=1;
delta(5,cw(0,5)) = -1;
ASSUME(creturn[0] >= cw(0,5));
// %call = call i32 @pthread_create(i64* noundef %thr0, %union.pthread_attr_t* noundef null, i8* (i8*)* noundef @t0, i8* noundef null) #7, !dbg !116
// dumbsy: Guess
old_cdy = cdy[0];
cdy[0] = get_rng(0,NCONTEXT-1);
// Check
ASSUME(cdy[0] >= old_cdy);
ASSUME(cdy[0] >= cisb[0]);
ASSUME(cdy[0] >= cdl[0]);
ASSUME(cdy[0] >= cds[0]);
ASSUME(cdy[0] >= cctrl[0]);
ASSUME(cdy[0] >= cw(0,0+0));
ASSUME(cdy[0] >= cw(0,0+1));
ASSUME(cdy[0] >= cw(0,0+2));
ASSUME(cdy[0] >= cw(0,4+0));
ASSUME(cdy[0] >= cw(0,7+0));
ASSUME(cdy[0] >= cw(0,3+0));
ASSUME(cdy[0] >= cw(0,5+0));
ASSUME(cdy[0] >= cw(0,6+0));
ASSUME(cdy[0] >= cr(0,0+0));
ASSUME(cdy[0] >= cr(0,0+1));
ASSUME(cdy[0] >= cr(0,0+2));
ASSUME(cdy[0] >= cr(0,4+0));
ASSUME(cdy[0] >= cr(0,7+0));
ASSUME(cdy[0] >= cr(0,3+0));
ASSUME(cdy[0] >= cr(0,5+0));
ASSUME(cdy[0] >= cr(0,6+0));
ASSUME(creturn[0] >= cdy[0]);
ASSUME(cstart[1] >= cdy[0]);
// %call11 = call i32 @pthread_create(i64* noundef %thr1, %union.pthread_attr_t* noundef null, i8* (i8*)* noundef @t1, i8* noundef null) #7, !dbg !117
// dumbsy: Guess
old_cdy = cdy[0];
cdy[0] = get_rng(0,NCONTEXT-1);
// Check
ASSUME(cdy[0] >= old_cdy);
ASSUME(cdy[0] >= cisb[0]);
ASSUME(cdy[0] >= cdl[0]);
ASSUME(cdy[0] >= cds[0]);
ASSUME(cdy[0] >= cctrl[0]);
ASSUME(cdy[0] >= cw(0,0+0));
ASSUME(cdy[0] >= cw(0,0+1));
ASSUME(cdy[0] >= cw(0,0+2));
ASSUME(cdy[0] >= cw(0,4+0));
ASSUME(cdy[0] >= cw(0,7+0));
ASSUME(cdy[0] >= cw(0,3+0));
ASSUME(cdy[0] >= cw(0,5+0));
ASSUME(cdy[0] >= cw(0,6+0));
ASSUME(cdy[0] >= cr(0,0+0));
ASSUME(cdy[0] >= cr(0,0+1));
ASSUME(cdy[0] >= cr(0,0+2));
ASSUME(cdy[0] >= cr(0,4+0));
ASSUME(cdy[0] >= cr(0,7+0));
ASSUME(cdy[0] >= cr(0,3+0));
ASSUME(cdy[0] >= cr(0,5+0));
ASSUME(cdy[0] >= cr(0,6+0));
ASSUME(creturn[0] >= cdy[0]);
ASSUME(cstart[2] >= cdy[0]);
// %2 = load i64, i64* %thr0, align 8, !dbg !118, !tbaa !119
// LD: Guess
old_cr = cr(0,6);
cr(0,6) = get_rng(0,NCONTEXT-1);// 0 ASSIGN LDCOM
// Check
ASSUME(active[cr(0,6)] == 0);
ASSUME(cr(0,6) >= iw(0,6));
ASSUME(cr(0,6) >= 0);
ASSUME(cr(0,6) >= cdy[0]);
ASSUME(cr(0,6) >= cisb[0]);
ASSUME(cr(0,6) >= cdl[0]);
ASSUME(cr(0,6) >= cl[0]);
// Update
creg_r4 = cr(0,6);
crmax(0,6) = max(crmax(0,6),cr(0,6));
caddr[0] = max(caddr[0],0);
if(cr(0,6) < cw(0,6)) {
r4 = buff(0,6);
} else {
if(pw(0,6) != co(6,cr(0,6))) {
ASSUME(cr(0,6) >= old_cr);
}
pw(0,6) = co(6,cr(0,6));
r4 = mem(6,cr(0,6));
}
ASSUME(creturn[0] >= cr(0,6));
// %call12 = call i32 @pthread_join(i64 noundef %2, i8** noundef null), !dbg !123
// dumbsy: Guess
old_cdy = cdy[0];
cdy[0] = get_rng(0,NCONTEXT-1);
// Check
ASSUME(cdy[0] >= old_cdy);
ASSUME(cdy[0] >= cisb[0]);
ASSUME(cdy[0] >= cdl[0]);
ASSUME(cdy[0] >= cds[0]);
ASSUME(cdy[0] >= cctrl[0]);
ASSUME(cdy[0] >= cw(0,0+0));
ASSUME(cdy[0] >= cw(0,0+1));
ASSUME(cdy[0] >= cw(0,0+2));
ASSUME(cdy[0] >= cw(0,4+0));
ASSUME(cdy[0] >= cw(0,7+0));
ASSUME(cdy[0] >= cw(0,3+0));
ASSUME(cdy[0] >= cw(0,5+0));
ASSUME(cdy[0] >= cw(0,6+0));
ASSUME(cdy[0] >= cr(0,0+0));
ASSUME(cdy[0] >= cr(0,0+1));
ASSUME(cdy[0] >= cr(0,0+2));
ASSUME(cdy[0] >= cr(0,4+0));
ASSUME(cdy[0] >= cr(0,7+0));
ASSUME(cdy[0] >= cr(0,3+0));
ASSUME(cdy[0] >= cr(0,5+0));
ASSUME(cdy[0] >= cr(0,6+0));
ASSUME(creturn[0] >= cdy[0]);
ASSUME(cdy[0] >= creturn[1]);
// %3 = load i64, i64* %thr1, align 8, !dbg !124, !tbaa !119
// LD: Guess
old_cr = cr(0,7);
cr(0,7) = get_rng(0,NCONTEXT-1);// 0 ASSIGN LDCOM
// Check
ASSUME(active[cr(0,7)] == 0);
ASSUME(cr(0,7) >= iw(0,7));
ASSUME(cr(0,7) >= 0);
ASSUME(cr(0,7) >= cdy[0]);
ASSUME(cr(0,7) >= cisb[0]);
ASSUME(cr(0,7) >= cdl[0]);
ASSUME(cr(0,7) >= cl[0]);
// Update
creg_r5 = cr(0,7);
crmax(0,7) = max(crmax(0,7),cr(0,7));
caddr[0] = max(caddr[0],0);
if(cr(0,7) < cw(0,7)) {
r5 = buff(0,7);
} else {
if(pw(0,7) != co(7,cr(0,7))) {
ASSUME(cr(0,7) >= old_cr);
}
pw(0,7) = co(7,cr(0,7));
r5 = mem(7,cr(0,7));
}
ASSUME(creturn[0] >= cr(0,7));
// %call13 = call i32 @pthread_join(i64 noundef %3, i8** noundef null), !dbg !125
// dumbsy: Guess
old_cdy = cdy[0];
cdy[0] = get_rng(0,NCONTEXT-1);
// Check
ASSUME(cdy[0] >= old_cdy);
ASSUME(cdy[0] >= cisb[0]);
ASSUME(cdy[0] >= cdl[0]);
ASSUME(cdy[0] >= cds[0]);
ASSUME(cdy[0] >= cctrl[0]);
ASSUME(cdy[0] >= cw(0,0+0));
ASSUME(cdy[0] >= cw(0,0+1));
ASSUME(cdy[0] >= cw(0,0+2));
ASSUME(cdy[0] >= cw(0,4+0));
ASSUME(cdy[0] >= cw(0,7+0));
ASSUME(cdy[0] >= cw(0,3+0));
ASSUME(cdy[0] >= cw(0,5+0));
ASSUME(cdy[0] >= cw(0,6+0));
ASSUME(cdy[0] >= cr(0,0+0));
ASSUME(cdy[0] >= cr(0,0+1));
ASSUME(cdy[0] >= cr(0,0+2));
ASSUME(cdy[0] >= cr(0,4+0));
ASSUME(cdy[0] >= cr(0,7+0));
ASSUME(cdy[0] >= cr(0,3+0));
ASSUME(cdy[0] >= cr(0,5+0));
ASSUME(cdy[0] >= cr(0,6+0));
ASSUME(creturn[0] >= cdy[0]);
ASSUME(cdy[0] >= creturn[2]);
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 0), metadata !163, metadata !DIExpression()), !dbg !221
// %4 = load atomic i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 0) seq_cst, align 8, !dbg !127
// LD: Guess
old_cr = cr(0,0);
cr(0,0) = get_rng(0,NCONTEXT-1);// 0 ASSIGN LDCOM
// Check
ASSUME(active[cr(0,0)] == 0);
ASSUME(cr(0,0) >= iw(0,0));
ASSUME(cr(0,0) >= 0);
ASSUME(cr(0,0) >= cdy[0]);
ASSUME(cr(0,0) >= cisb[0]);
ASSUME(cr(0,0) >= cdl[0]);
ASSUME(cr(0,0) >= cl[0]);
// Update
creg_r6 = cr(0,0);
crmax(0,0) = max(crmax(0,0),cr(0,0));
caddr[0] = max(caddr[0],0);
if(cr(0,0) < cw(0,0)) {
r6 = buff(0,0);
} else {
if(pw(0,0) != co(0,cr(0,0))) {
ASSUME(cr(0,0) >= old_cr);
}
pw(0,0) = co(0,cr(0,0));
r6 = mem(0,cr(0,0));
}
ASSUME(creturn[0] >= cr(0,0));
// call void @llvm.dbg.value(metadata i64 %4, metadata !165, metadata !DIExpression()), !dbg !221
// %conv = trunc i64 %4 to i32, !dbg !128
// call void @llvm.dbg.value(metadata i32 %conv, metadata !162, metadata !DIExpression()), !dbg !194
// %cmp = icmp eq i32 %conv, 1, !dbg !129
// %conv14 = zext i1 %cmp to i32, !dbg !129
// call void @llvm.dbg.value(metadata i32 %conv14, metadata !166, metadata !DIExpression()), !dbg !194
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 1), metadata !168, metadata !DIExpression()), !dbg !225
// %5 = load atomic i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 1) seq_cst, align 8, !dbg !131
// LD: Guess
old_cr = cr(0,0+1*1);
cr(0,0+1*1) = get_rng(0,NCONTEXT-1);// 0 ASSIGN LDCOM
// Check
ASSUME(active[cr(0,0+1*1)] == 0);
ASSUME(cr(0,0+1*1) >= iw(0,0+1*1));
ASSUME(cr(0,0+1*1) >= 0);
ASSUME(cr(0,0+1*1) >= cdy[0]);
ASSUME(cr(0,0+1*1) >= cisb[0]);
ASSUME(cr(0,0+1*1) >= cdl[0]);
ASSUME(cr(0,0+1*1) >= cl[0]);
// Update
creg_r7 = cr(0,0+1*1);
crmax(0,0+1*1) = max(crmax(0,0+1*1),cr(0,0+1*1));
caddr[0] = max(caddr[0],0);
if(cr(0,0+1*1) < cw(0,0+1*1)) {
r7 = buff(0,0+1*1);
} else {
if(pw(0,0+1*1) != co(0+1*1,cr(0,0+1*1))) {
ASSUME(cr(0,0+1*1) >= old_cr);
}
pw(0,0+1*1) = co(0+1*1,cr(0,0+1*1));
r7 = mem(0+1*1,cr(0,0+1*1));
}
ASSUME(creturn[0] >= cr(0,0+1*1));
// call void @llvm.dbg.value(metadata i64 %5, metadata !170, metadata !DIExpression()), !dbg !225
// %conv18 = trunc i64 %5 to i32, !dbg !132
// call void @llvm.dbg.value(metadata i32 %conv18, metadata !167, metadata !DIExpression()), !dbg !194
// %cmp19 = icmp eq i32 %conv18, 1, !dbg !133
// %conv20 = zext i1 %cmp19 to i32, !dbg !133
// call void @llvm.dbg.value(metadata i32 %conv20, metadata !171, metadata !DIExpression()), !dbg !194
// call void @llvm.dbg.value(metadata i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 2), metadata !173, metadata !DIExpression()), !dbg !229
// %6 = load atomic i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @vars, i64 0, i64 2) seq_cst, align 8, !dbg !135
// LD: Guess
old_cr = cr(0,0+2*1);
cr(0,0+2*1) = get_rng(0,NCONTEXT-1);// 0 ASSIGN LDCOM
// Check
ASSUME(active[cr(0,0+2*1)] == 0);
ASSUME(cr(0,0+2*1) >= iw(0,0+2*1));
ASSUME(cr(0,0+2*1) >= 0);
ASSUME(cr(0,0+2*1) >= cdy[0]);
ASSUME(cr(0,0+2*1) >= cisb[0]);
ASSUME(cr(0,0+2*1) >= cdl[0]);
ASSUME(cr(0,0+2*1) >= cl[0]);
// Update
creg_r8 = cr(0,0+2*1);
crmax(0,0+2*1) = max(crmax(0,0+2*1),cr(0,0+2*1));
caddr[0] = max(caddr[0],0);
if(cr(0,0+2*1) < cw(0,0+2*1)) {
r8 = buff(0,0+2*1);
} else {
if(pw(0,0+2*1) != co(0+2*1,cr(0,0+2*1))) {
ASSUME(cr(0,0+2*1) >= old_cr);
}
pw(0,0+2*1) = co(0+2*1,cr(0,0+2*1));
r8 = mem(0+2*1,cr(0,0+2*1));
}
ASSUME(creturn[0] >= cr(0,0+2*1));
// call void @llvm.dbg.value(metadata i64 %6, metadata !175, metadata !DIExpression()), !dbg !229
// %conv24 = trunc i64 %6 to i32, !dbg !136
// call void @llvm.dbg.value(metadata i32 %conv24, metadata !172, metadata !DIExpression()), !dbg !194
// %cmp25 = icmp eq i32 %conv24, 2, !dbg !137
// %conv26 = zext i1 %cmp25 to i32, !dbg !137
// call void @llvm.dbg.value(metadata i32 %conv26, metadata !176, metadata !DIExpression()), !dbg !194
// call void @llvm.dbg.value(metadata i64* @atom_0_X2_1, metadata !178, metadata !DIExpression()), !dbg !233
// %7 = load atomic i64, i64* @atom_0_X2_1 seq_cst, align 8, !dbg !139
// LD: Guess
old_cr = cr(0,3);
cr(0,3) = get_rng(0,NCONTEXT-1);// 0 ASSIGN LDCOM
// Check
ASSUME(active[cr(0,3)] == 0);
ASSUME(cr(0,3) >= iw(0,3));
ASSUME(cr(0,3) >= 0);
ASSUME(cr(0,3) >= cdy[0]);
ASSUME(cr(0,3) >= cisb[0]);
ASSUME(cr(0,3) >= cdl[0]);
ASSUME(cr(0,3) >= cl[0]);
// Update
creg_r9 = cr(0,3);
crmax(0,3) = max(crmax(0,3),cr(0,3));
caddr[0] = max(caddr[0],0);
if(cr(0,3) < cw(0,3)) {
r9 = buff(0,3);
} else {
if(pw(0,3) != co(3,cr(0,3))) {
ASSUME(cr(0,3) >= old_cr);
}
pw(0,3) = co(3,cr(0,3));
r9 = mem(3,cr(0,3));
}
ASSUME(creturn[0] >= cr(0,3));
// call void @llvm.dbg.value(metadata i64 %7, metadata !180, metadata !DIExpression()), !dbg !233
// %conv30 = trunc i64 %7 to i32, !dbg !140
// call void @llvm.dbg.value(metadata i32 %conv30, metadata !177, metadata !DIExpression()), !dbg !194
// call void @llvm.dbg.value(metadata i64* @atom_0_X5_1, metadata !182, metadata !DIExpression()), !dbg !236
// %8 = load atomic i64, i64* @atom_0_X5_1 seq_cst, align 8, !dbg !142
// LD: Guess
old_cr = cr(0,4);
cr(0,4) = get_rng(0,NCONTEXT-1);// 0 ASSIGN LDCOM
// Check
ASSUME(active[cr(0,4)] == 0);
ASSUME(cr(0,4) >= iw(0,4));
ASSUME(cr(0,4) >= 0);
ASSUME(cr(0,4) >= cdy[0]);
ASSUME(cr(0,4) >= cisb[0]);
ASSUME(cr(0,4) >= cdl[0]);
ASSUME(cr(0,4) >= cl[0]);
// Update
creg_r10 = cr(0,4);
crmax(0,4) = max(crmax(0,4),cr(0,4));
caddr[0] = max(caddr[0],0);
if(cr(0,4) < cw(0,4)) {
r10 = buff(0,4);
} else {
if(pw(0,4) != co(4,cr(0,4))) {
ASSUME(cr(0,4) >= old_cr);
}
pw(0,4) = co(4,cr(0,4));
r10 = mem(4,cr(0,4));
}
ASSUME(creturn[0] >= cr(0,4));
// call void @llvm.dbg.value(metadata i64 %8, metadata !184, metadata !DIExpression()), !dbg !236
// %conv34 = trunc i64 %8 to i32, !dbg !143
// call void @llvm.dbg.value(metadata i32 %conv34, metadata !181, metadata !DIExpression()), !dbg !194
// call void @llvm.dbg.value(metadata i64* @atom_1_X2_0, metadata !186, metadata !DIExpression()), !dbg !239
// %9 = load atomic i64, i64* @atom_1_X2_0 seq_cst, align 8, !dbg !145
// LD: Guess
old_cr = cr(0,5);
cr(0,5) = get_rng(0,NCONTEXT-1);// 0 ASSIGN LDCOM
// Check
ASSUME(active[cr(0,5)] == 0);
ASSUME(cr(0,5) >= iw(0,5));
ASSUME(cr(0,5) >= 0);
ASSUME(cr(0,5) >= cdy[0]);
ASSUME(cr(0,5) >= cisb[0]);
ASSUME(cr(0,5) >= cdl[0]);
ASSUME(cr(0,5) >= cl[0]);
// Update
creg_r11 = cr(0,5);
crmax(0,5) = max(crmax(0,5),cr(0,5));
caddr[0] = max(caddr[0],0);
if(cr(0,5) < cw(0,5)) {
r11 = buff(0,5);
} else {
if(pw(0,5) != co(5,cr(0,5))) {
ASSUME(cr(0,5) >= old_cr);
}
pw(0,5) = co(5,cr(0,5));
r11 = mem(5,cr(0,5));
}
ASSUME(creturn[0] >= cr(0,5));
// call void @llvm.dbg.value(metadata i64 %9, metadata !188, metadata !DIExpression()), !dbg !239
// %conv38 = trunc i64 %9 to i32, !dbg !146
// call void @llvm.dbg.value(metadata i32 %conv38, metadata !185, metadata !DIExpression()), !dbg !194
// %and = and i32 %conv34, %conv38, !dbg !147
creg_r12 = max(creg_r10,creg_r11);
ASSUME(active[creg_r12] == 0);
r12 = r10 & r11;
// call void @llvm.dbg.value(metadata i32 %and, metadata !189, metadata !DIExpression()), !dbg !194
// %and39 = and i32 %conv30, %and, !dbg !148
creg_r13 = max(creg_r9,creg_r12);
ASSUME(active[creg_r13] == 0);
r13 = r9 & r12;
// call void @llvm.dbg.value(metadata i32 %and39, metadata !190, metadata !DIExpression()), !dbg !194
// %and40 = and i32 %conv26, %and39, !dbg !149
creg_r14 = max(max(creg_r8,0),creg_r13);
ASSUME(active[creg_r14] == 0);
r14 = (r8==2) & r13;
// call void @llvm.dbg.value(metadata i32 %and40, metadata !191, metadata !DIExpression()), !dbg !194
// %and41 = and i32 %conv20, %and40, !dbg !150
creg_r15 = max(max(creg_r7,0),creg_r14);
ASSUME(active[creg_r15] == 0);
r15 = (r7==1) & r14;
// call void @llvm.dbg.value(metadata i32 %and41, metadata !192, metadata !DIExpression()), !dbg !194
// %and42 = and i32 %conv14, %and41, !dbg !151
creg_r16 = max(max(creg_r6,0),creg_r15);
ASSUME(active[creg_r16] == 0);
r16 = (r6==1) & r15;
// call void @llvm.dbg.value(metadata i32 %and42, metadata !193, metadata !DIExpression()), !dbg !194
// %cmp43 = icmp eq i32 %and42, 1, !dbg !152
// br i1 %cmp43, label %if.then, label %if.end, !dbg !154
old_cctrl = cctrl[0];
cctrl[0] = get_rng(0,NCONTEXT-1);
ASSUME(cctrl[0] >= old_cctrl);
ASSUME(cctrl[0] >= creg_r16);
ASSUME(cctrl[0] >= 0);
if((r16==1)) {
goto T0BLOCK1;
} else {
goto T0BLOCK2;
}
T0BLOCK1:
// call void @__assert_fail(i8* noundef getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* noundef getelementptr inbounds ([111 x i8], [111 x i8]* @.str.1, i64 0, i64 0), i32 noundef 78, i8* noundef getelementptr inbounds ([23 x i8], [23 x i8]* @__PRETTY_FUNCTION__.main, i64 0, i64 0)) #8, !dbg !155
// unreachable, !dbg !155
r17 = 1;
T0BLOCK2:
// %10 = bitcast i64* %thr1 to i8*, !dbg !158
// call void @llvm.lifetime.end.p0i8(i64 8, i8* %10) #7, !dbg !158
// %11 = bitcast i64* %thr0 to i8*, !dbg !158
// call void @llvm.lifetime.end.p0i8(i64 8, i8* %11) #7, !dbg !158
// ret i32 0, !dbg !159
ret_thread_0 = 0;
ASSERT(r17== 0);
}
| [
"tuan-phong.ngo@it.uu.se"
] | tuan-phong.ngo@it.uu.se |
fc53a96b9b7ae14a57f2a8c8bda3ce4bbd14b13e | 8e4905788246a7654cfac6ca77f8c3ae66562b54 | /KalkonenWare/stdafx.h | f7e26478b649fd7ebcf317a3bb9d4e44cf3d236c | [] | no_license | w47gntw478tea5wv/kalkware | f9ea22845ec7d016f1f5652ae85b0f247fa6dfc2 | cb4ee8a4731bb6195def8cc7fa5d284949889150 | refs/heads/master | 2020-03-18T15:58:15.611437 | 2018-05-23T12:26:16 | 2018-05-23T12:26:16 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,088 | h | #pragma once
#define WIN32_LEAN_AND_MEAN
#define IMPLEMENT_SINGLETON(classname)\
public:\
static std::shared_ptr<classname> GetInstance() {\
static std::shared_ptr<classname> instance(new classname);\
return instance;\
}\
private:\
classname() {}\
classname(classname const&) = delete;\
void operator=(classname const&) = delete;
#include "targetver.h"
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <sstream>
#include <string>
#include <psapi.h>
#include <time.h>
#include <process.h>
#include <vector>
#include <map>
#include <ostream>
#include <Shlobj.h>
#include <stdint.h>
#include <string>
#include <string.h>
#include <cmath>
#include <float.h>
#include <codecvt>
#include <WinUser.h>
using namespace std;
#include <atlbase.h>
#include <atlcom.h>
#include <sapi.h>
#include <algorithm>
#include <iterator>
#include "SDK/SDK Headers/IEffects.h"
#include <d3d9.h>
#include <d3dx9.h>
#include <playsoundapi.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "winmm.lib")
/* Some other shit */
#include "ConsoleColours.h"
DWORD WINAPI CheatMain( LPVOID lpThreadParameter );
#include "VMTManager.h"
extern VTHookManager VMTPanel;
extern VTHookManager VMTClient;
extern VTHookManager VMTEngine;
extern VTHookManager VMTModelRender;
extern VTHookManager VMTGameEventManager;
extern VTHookManager VMTSurface;
extern VTHookManager VMTD3D;
extern VTHookManager VMTSOUND;
extern VTHookManager VMTMDL;
extern VTHookManager VMTViewRender;
extern VTHookManager VMTNetChan;
extern VTHookManager VMTSendMove;
#include "Tools\IMGUI\imgui.h"
class FontsXD;
extern FontsXD fontskek;
/*SDK*/
#include "SDK/Math/Vectors.h"
#include "SDK/Math/Math.h"
#include "Utils/Utils.h"
#include "SDK/SDK.h"
#include "strenc.h"
/* Cheat And Hooks */
class CHackManager;
extern CHackManager Hacks;
namespace INIT
{
extern HMODULE Dll;
extern HWND Window;
extern WNDPROC OldWindow;
}
extern void Unhook();
#include "Hooks.h"
#include "Tools\Menu\Vars.h"
#include "Tools\Menu\Controls.h" | [
"noreply@github.com"
] | noreply@github.com |
efb070ede99fb857e5d780492d6367a079bf7913 | dc4b164e14034ea26c27259f7aa9c96584fc1d1e | /server_src/db_proxy_server/DBPool.cpp | fe30a3733195bffc20f6c6153fc1913c30ad8623 | [] | no_license | hlyces/teamtalk_TT | c3f4b2b92a3758ffa3d132c5a2605a3c3b15e7a6 | e31d80694170045836a78131737148c51d344c4f | refs/heads/master | 2021-01-20T23:09:03.304309 | 2015-12-28T07:03:22 | 2015-12-28T07:03:22 | 43,662,835 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 11,702 | cpp | /*
* DBPool.cpp
*
* Created on: 2014年7月22日
* Author: ziteng
* Modify By ZhangYuanhao
* 2015-01-12
* enable config the max connection of every instance
* 2015-01-25
* modify the charset.
*/
#include "DBPool.h"
#include "ConfigFileReader.h"
#define MIN_DB_CONN_CNT 2
CDBManager* CDBManager::s_db_manager = NULL;
CResultSet::CResultSet(MYSQL_RES* res)
{
m_res = NULL;
Init(res);
}
CResultSet::CResultSet()
{
m_res = NULL;
}
bool CResultSet::Init(MYSQL_RES* res)
{
Clear();
m_res = res;
//2.map table field key to index in the result array
int num_fields = mysql_num_fields(m_res); //mysql_num_fields() 函数返回结果集中字段的数。
MYSQL_FIELD* fields = mysql_fetch_fields(m_res); //对于结果集,返回所有MYSQL_FIELD结构的数组。每个结构提供了结果集中1列的字段定义。关于结果集所有列的MYSQL_FIELD结构的数组
for(int i = 0; i < num_fields; i++)
{
m_key_map.insert(make_pair(fields[i].name, i));
}
return true;
}
bool CResultSet::Clear()
{
//1.clear
if (m_res) {
mysql_free_result(m_res);
m_res = NULL;
}
m_key_map.clear();
return true;
}
CResultSet::~CResultSet()
{
Clear();
}
bool CResultSet::Next()
{
m_row = mysql_fetch_row(m_res);
if (m_row) {
return true;
} else {
return false;
}
}
int CResultSet::_GetIndex(const char* key)
{
map<string, int>::iterator it = m_key_map.find(key);
if (it == m_key_map.end()) {
return -1;
} else {
return it->second;
}
}
int CResultSet::GetInt(const char* key)
{
int idx = _GetIndex(key);
if (idx == -1) {
return 0;
} else {
if(NULL==m_row[idx])
return 0;
else
return atoi(m_row[idx]);
}
}
long CResultSet::GetLong(const char* key)
{
int idx = _GetIndex(key);
if (idx == -1) {
return 0;
} else {
if(NULL==m_row[idx])
return 0;
else
return atol(m_row[idx]);
}
}
static const char* s_sNULL = "";
const char* CResultSet::GetString(const char* key)
{
int idx = _GetIndex(key);
if (idx == -1) {
return s_sNULL;
} else {
if(NULL==m_row[idx])
return s_sNULL;
else
return m_row[idx];
}
}
/////////////////////////////////////////
CPrepareStatement::CPrepareStatement()
{
m_stmt = NULL;
m_param_bind = NULL;
m_param_cnt = 0;
}
CPrepareStatement::~CPrepareStatement()
{
if (m_stmt) {
mysql_stmt_close(m_stmt);
m_stmt = NULL;
}
if (m_param_bind) {
delete [] m_param_bind;
m_param_bind = NULL;
}
}
bool CPrepareStatement::Init(MYSQL* mysql, string& sql)
{
mysql_ping(mysql);
m_stmt = mysql_stmt_init(mysql);
if (!m_stmt) {
log("mysql_stmt_init failed");
return false;
}
if (mysql_stmt_prepare(m_stmt, sql.c_str(), sql.size())) {
log("mysql_stmt_prepare failed: %s", mysql_stmt_error(m_stmt));
return false;
}
m_param_cnt = mysql_stmt_param_count(m_stmt);
if (m_param_cnt > 0) {
m_param_bind = new MYSQL_BIND [m_param_cnt];
if (!m_param_bind) {
log("new failed");
return false;
}
memset(m_param_bind, 0, sizeof(MYSQL_BIND) * m_param_cnt);
}
return true;
}
void CPrepareStatement::SetParam(uint32_t index, int& value)
{
if (index >= m_param_cnt) {
log("index too large: %d", index);
return;
}
m_param_bind[index].buffer_type = MYSQL_TYPE_LONG;
m_param_bind[index].buffer = &value;
}
void CPrepareStatement::SetParam(uint32_t index, uint32_t& value)
{
if (index >= m_param_cnt) {
log("index too large: %d", index);
return;
}
m_param_bind[index].buffer_type = MYSQL_TYPE_LONG;
m_param_bind[index].buffer = &value;
}
void CPrepareStatement::SetParam(uint32_t index, string& value)
{
if (index >= m_param_cnt) {
log("index too large: %d", index);
return;
}
m_param_bind[index].buffer_type = MYSQL_TYPE_STRING;
m_param_bind[index].buffer = (char*)value.c_str();
m_param_bind[index].buffer_length = value.size();
}
void CPrepareStatement::SetParam(uint32_t index, const string& value)
{
if (index >= m_param_cnt) {
log("index too large: %d", index);
return;
}
m_param_bind[index].buffer_type = MYSQL_TYPE_STRING;
m_param_bind[index].buffer = (char*)value.c_str();
m_param_bind[index].buffer_length = value.size();
}
bool CPrepareStatement::ExecuteUpdate()
{
if (!m_stmt) {
log("no m_stmt");
return false;
}
if (mysql_stmt_bind_param(m_stmt, m_param_bind)) {
log("mysql_stmt_bind_param failed: %s", mysql_stmt_error(m_stmt));
return false;
}
if (mysql_stmt_execute(m_stmt)) {
log("mysql_stmt_execute failed: %s", mysql_stmt_error(m_stmt));
return false;
}
if (mysql_stmt_affected_rows(m_stmt) == 0) {
log("ExecuteUpdate have no effect");
return false;
}
return true;
}
uint32_t CPrepareStatement::GetInsertId()
{
return mysql_stmt_insert_id(m_stmt);
}
/////////////////////
CDBConn::CDBConn(CDBPool* pPool)
{
m_pDBPool = pPool;
m_mysql = NULL;
m_pResult_set = new CResultSet();
}
CDBConn::~CDBConn()
{
if(m_pResult_set)
{
delete m_pResult_set;
m_pResult_set = NULL;
}
if(m_mysql)
{
mysql_close(m_mysql);
m_mysql = NULL;
}
}
int CDBConn::Init()
{
m_mysql = mysql_init(NULL);
if (!m_mysql) {
log("mysql_init failed");
return 1;
}
my_bool reconnect = true;
mysql_options(m_mysql, MYSQL_OPT_RECONNECT, &reconnect);
mysql_options(m_mysql, MYSQL_SET_CHARSET_NAME, "utf8mb4");
if (!mysql_real_connect(m_mysql, m_pDBPool->GetDBServerIP(), m_pDBPool->GetUsername(), m_pDBPool->GetPasswrod(),
m_pDBPool->GetDBName(), m_pDBPool->GetDBServerPort(), NULL, 0)) {
log("mysql_real_connect failed: %s", mysql_error(m_mysql));
return 2;
}
return 0;
}
const char* CDBConn::GetPoolName()
{
return m_pDBPool->GetPoolName();
}
//若要嵌套使用ExecuteQuery,应该用多个CDBConn对象,因为m_pResult_set在同一连接下是共用的
CResultSet* CDBConn::ExecuteQuery(const char* sql_query)
{
mysql_ping(m_mysql);
if (mysql_real_query(m_mysql, sql_query, strlen(sql_query))) {
log("mysql_real_query failed: %s, sql: %s", mysql_error(m_mysql), sql_query);
return NULL;
}
MYSQL_RES* res = mysql_store_result(m_mysql);
if (!res) {
log("mysql_store_result failed: %s", mysql_error(m_mysql));
return NULL;
}
//CResultSet* result_set = new CResultSet(res);
m_pResult_set->Init( res);
return m_pResult_set;
}
bool CDBConn::ExecuteUpdate(const char* sql_query)
{
mysql_ping(m_mysql);
if (mysql_real_query(m_mysql, sql_query, strlen(sql_query))) {
log("mysql_real_query failed: %s, sql: %s", mysql_error(m_mysql), sql_query);
return false;
}
if (mysql_affected_rows(m_mysql) > 0) {
return true;
} else {
return false;
}
}
char* CDBConn::EscapeString(const char* content, uint32_t content_len)
{
if (content_len > (MAX_ESCAPE_STRING_LEN >> 1)) {
m_escape_string[0] = 0;
} else {
mysql_real_escape_string(m_mysql, m_escape_string, content, content_len); //转义 SQL 语句中使用的字符串中的特殊字符
}
return m_escape_string;
}
uint32_t CDBConn::GetInsertId()
{
return (uint32_t)mysql_insert_id(m_mysql);
}
////////////////
CDBPool::CDBPool(const char* pool_name, const char* db_server_ip, uint16_t db_server_port,
const char* username, const char* password, const char* db_name, int max_conn_cnt)
{
m_pool_name = pool_name;
m_db_server_ip = db_server_ip;
m_db_server_port = db_server_port;
m_username = username;
m_password = password;
m_db_name = db_name;
m_db_max_conn_cnt = max_conn_cnt;
m_db_cur_conn_cnt = MIN_DB_CONN_CNT;
}
CDBPool::~CDBPool()
{
for (list<CDBConn*>::iterator it = m_free_list.begin(); it != m_free_list.end(); it++) {
CDBConn* pConn = *it;
delete pConn;
}
m_free_list.clear();
}
int CDBPool::Init()
{
for (int i = 0; i < m_db_cur_conn_cnt; i++) {
CDBConn* pDBConn = new CDBConn(this);
int ret = pDBConn->Init();
if (ret) {
delete pDBConn;
return ret;
}
m_free_list.push_back(pDBConn);
}
log("db pool: %s, size: %d", m_pool_name.c_str(), (int)m_free_list.size());
return 0;
}
/*
*TODO: 增加保护机制,把分配的连接加入另一个队列,这样获取连接时,如果没有空闲连接,
*TODO: 检查已经分配的连接多久没有返回,如果超过一定时间,则自动收回连接,放在用户忘了调用释放连接的接口
*/
CDBConn* CDBPool::GetDBConn()
{
m_free_notify.Lock();
while (m_free_list.empty()) {
if (m_db_cur_conn_cnt >= m_db_max_conn_cnt) {
m_free_notify.Wait();
} else {
CDBConn* pDBConn = new CDBConn(this);
int ret = pDBConn->Init();
if (ret) {
log("Init DBConnecton failed");
delete pDBConn;
m_free_notify.Unlock();
return NULL;
} else {
m_free_list.push_back(pDBConn);
m_db_cur_conn_cnt++;
log("new db connection: %s, conn_cnt: %d", m_pool_name.c_str(), m_db_cur_conn_cnt);
}
}
}
CDBConn* pConn = m_free_list.front();
m_free_list.pop_front();
m_free_notify.Unlock();
return pConn;
}
void CDBPool::RelDBConn(CDBConn* pConn)
{
m_free_notify.Lock();
list<CDBConn*>::iterator it = m_free_list.begin();
for (; it != m_free_list.end(); it++) {
if (*it == pConn) {
break;
}
}
if (it == m_free_list.end()) {
m_free_list.push_back(pConn);
}
m_free_notify.Signal();
m_free_notify.Unlock();
}
/////////////////
CDBManager::CDBManager()
{
}
CDBManager::~CDBManager()
{
}
CDBManager* CDBManager::getInstance(const char* szConfigFile)
{
if (!s_db_manager) {
s_db_manager = new CDBManager();
if (s_db_manager->Init(szConfigFile)) {
delete s_db_manager;
s_db_manager = NULL;
}
}
return s_db_manager;
}
/*
* 2015-01-12
* modify by ZhangYuanhao :enable config the max connection of every instance
*
*/
int CDBManager::Init(const char* szConfigFile)
{
CConfigFileReader config_file(szConfigFile);
char* db_instances = config_file.GetConfigName("DBInstances");
if (!db_instances) {
log("not configure DBInstances");
return 1;
}
char host[64];
char port[64];
char dbname[64];
char username[64];
char password[64];
char maxconncnt[64];
CStrExplode instances_name(db_instances, ',');
for (uint32_t i = 0; i < instances_name.GetItemCnt(); i++) {
char* pool_name = instances_name.GetItem(i);
snprintf(host, 64, "%s_host", pool_name);
snprintf(port, 64, "%s_port", pool_name);
snprintf(dbname, 64, "%s_dbname", pool_name);
snprintf(username, 64, "%s_username", pool_name);
snprintf(password, 64, "%s_password", pool_name);
snprintf(maxconncnt, 64, "%s_maxconncnt", pool_name);
char* db_host = config_file.GetConfigName(host);
char* str_db_port = config_file.GetConfigName(port);
char* db_dbname = config_file.GetConfigName(dbname);
char* db_username = config_file.GetConfigName(username);
char* db_password = config_file.GetConfigName(password);
char* str_maxconncnt = config_file.GetConfigName(maxconncnt);
if (!db_host || !str_db_port || !db_dbname || !db_username || !db_password || !str_maxconncnt) {
log("not configure db instance: %s", pool_name);
return 2;
}
int db_port = atoi(str_db_port);
int db_maxconncnt = atoi(str_maxconncnt);
CDBPool* pDBPool = new CDBPool(pool_name, db_host, db_port, db_username, db_password, db_dbname, db_maxconncnt);
if (pDBPool->Init()) {
log("init db instance failed: %s", pool_name);
return 3;
}
m_dbpool_map.insert(make_pair(pool_name, pDBPool));
}
return 0;
}
CDBConn* CDBManager::GetDBConn(const char* dbpool_name)
{
map<string, CDBPool*>::iterator it = m_dbpool_map.find(dbpool_name);
if (it == m_dbpool_map.end()) {
return NULL;
} else {
return it->second->GetDBConn();
}
}
void CDBManager::RelDBConn(CDBConn* pConn)
{
if (!pConn) {
return;
}
map<string, CDBPool*>::iterator it = m_dbpool_map.find(pConn->GetPoolName());
if (it != m_dbpool_map.end()) {
it->second->RelDBConn(pConn);
}
}
| [
"heyihua@dffx.com"
] | heyihua@dffx.com |
b237933392deae93f04dd69b2bd0fec5275ae5d2 | b179ee1c603139301b86fa44ccbbd315a148c47b | /engine/calculators/source/ModifyStatisticsCalculator.cpp | baf13ba79757a14d32275ea9991a696c872f50b6 | [
"MIT",
"Zlib"
] | permissive | prolog/shadow-of-the-wyrm | 06de691e94c2cb979756cee13d424a994257b544 | cd419efe4394803ff3d0553acf890f33ae1e4278 | refs/heads/master | 2023-08-31T06:08:23.046409 | 2023-07-08T14:45:27 | 2023-07-08T14:45:27 | 203,472,742 | 71 | 9 | MIT | 2023-07-08T14:45:29 | 2019-08-21T00:01:37 | C++ | UTF-8 | C++ | false | false | 417 | cpp | #include "ModifyStatisticsCalculator.hpp"
#include "Random.hpp"
const int ModifyStatisticsCalculator::BASE_MODIFY_STATISTICS_DURATION_MEAN = 20;
// Calculate the duration in minutes.
int ModifyStatisticsCalculator::calculate_duration() const
{
// Statistics modification lasts around twenty minutes.
PoissonDistribution p(BASE_MODIFY_STATISTICS_DURATION_MEAN);
int duration = p.next();
return duration;
}
| [
"jcd748@mail.usask.ca"
] | jcd748@mail.usask.ca |
8266367c6556fe778568a437d5e044b326be64be | 8b0ebc13974ca2e6dbecbb5e6b1f9e58629ff9ce | /CppND-Concurrent-Traffic-Simulation/src/TrafficLight.h | f79e31a8a19250765e966e4fd54b0ac6a8949a84 | [] | no_license | aiswaryacyriac91/Udacity_Cpp | d741051d59f9831eb86bb54903f4f259b3636e4f | 90c1d93e9a9717e554e29ccfe46d1fff131eb25d | refs/heads/master | 2022-06-28T22:41:28.459034 | 2020-05-14T16:21:09 | 2020-05-14T16:21:09 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,186 | h | #ifndef TRAFFICLIGHT_H
#define TRAFFICLIGHT_H
#include <mutex>
#include <deque>
#include <condition_variable>
#include "TrafficObject.h"
// forward declarations to avoid include cycle
class Vehicle;
enum TrafficLightPhase{green, red};
// FP.3 Define a class „MessageQueue“ which has the public methods send and receive.
// Send should take an rvalue reference of type TrafficLightPhase whereas receive should return this type.
// Also, the class should define an std::dequeue called _queue, which stores objects of type TrafficLightPhase.
// Also, there should be an std::condition_variable as well as an std::mutex as private members.
template <class T>
class MessageQueue
{
public:
MessageQueue() {}
T receive()
void send(T &&Message)
private:
std::mutex _mutex;
std::condition_variable _cond;
std::deque<T> _messages; // list of all vehicles waiting to enter this intersection
};
// FP.1 : Define a class „TrafficLight“ which is a child class of TrafficObject.
// The class shall have the public methods „void waitForGreen()“ and „void simulate()“
// as well as „TrafficLightPhase getCurrentPhase()“, where TrafficLightPhase is an enum that
// can be either „red“ or „green“. Also, add the private method „void cycleThroughPhases()“.
// Furthermore, there shall be the private member _currentPhase which can take „red“ or „green“ as its value.
class TrafficLight : public TrafficObject
{
public:
// constructor / desctructor
TrafficLight()
// getters / setters
TrafficLightPhase getCurrentPhase();
// typical behaviour methods
void waitForGreen();
void simulate();
private:
// typical behaviour methods
void cycleThroughPhases();
// FP.4b : create a private member of type MessageQueue for messages of type TrafficLightPhase
// and use it within the infinite loop to push each new TrafficLightPhase into it by calling
// send in conjunction with move semantics.
std::shared_ptr<MessageQueue<TrafficLightPhase>> msg_queue_;
TrafficLightPhase _currentPhase;
std::condition_variable _condition;
std::mutex _mutex;
};
#endif | [
"noreply@github.com"
] | noreply@github.com |
55b37b5ee38ec857c79319e967a9cb23b57f5087 | cee85adb63ea9f557336ed4dc7b1e8a00a97d1f4 | /src/lumoKinematics.h | d1c95aeaa8dd3dc6e6cb485378cad9263774ce38 | [] | no_license | julienvh/NewGui | ed17747938b519107925c68b1b2c359af493f216 | 0786f6c19ebf617f9a8e7c2af2391bb57614b347 | refs/heads/master | 2021-01-11T13:54:26.076831 | 2017-06-20T12:07:48 | 2017-06-20T12:07:48 | 94,886,828 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,494 | h | #pragma once
#ifndef lumoKinematics_hpp
#define lumoKinematics_hpp
#include <stdio.h>
#include <ofMain.h>
#include "ofxCv.h"
#include "ofxOpenCv.h"
class lumoKinematics {
public:
void setup();
string draw(int x, int y);
void update();
void inverse();
void direct(float a, float b);
void drawaxes();
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void moveTo(int x, int y);
void moveToComplex(int a, int b, int c, int d, int e, int f);
int originX = 300;
int originY = 700;
int
//targetx = 200, //Doelposities, halen uit mouseDragged()
//targety = 200,
draai1, //Dit willen we doorsturen
draai2,
draai3;
float
L1, //Lengtes van de armen
L2,
L3,
L31,
L32,
Yc, //Posities voor het rekenen
Xc,
Xwc,
Ywc,
Xcw, //Posities voor het tekenen van de armen
Ycw,
Xcwd,
Ycwd,
Xcw8,
Ycw8,
Xc8,
Yc8,
D,
theta2,
theta3,
angle2,
angle4,
angle5 = 0,
angle6;
int targety;
int targetx;
vector<string> movements = {"","",""};
std::ostringstream oss;
bool bDraw = false;
bool nextPosition = false;
bool bComplex = false;
int arrayComplex[6];
int complex = 1;
int testar[6];
bool finished = false;
int x1, x2, x3, y1, y2, y3;
int complexTimer = -1;
bool bComplexRun = false;
};
#endif /* lumoKinematics_hpp */ | [
"julienvanhaeren@live.nl"
] | julienvanhaeren@live.nl |
3ecbf86f6164f44e906dfe4e9a734d37bd0036c4 | d732c881b57ef5e3c8f8d105b2f2e09b86bcc3fe | /src/module-jpeg/VType_Tag.cpp | 7fbe865a1dd27c4d3625d922bffa0be574cbbdb4 | [] | no_license | gura-lang/gurax | 9180861394848fd0be1f8e60322b65a92c4c604d | d9fedbc6e10f38af62c53c1bb8a4734118d14ce4 | refs/heads/master | 2023-09-01T09:15:36.548730 | 2023-09-01T08:49:33 | 2023-09-01T08:49:33 | 160,017,455 | 10 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,996 | cpp | //==============================================================================
// VType_Tag.cpp
//==============================================================================
#include "stdafx.h"
Gurax_BeginModuleScope(jpeg)
//------------------------------------------------------------------------------
// Help
//------------------------------------------------------------------------------
static const char* g_docHelp_en = u8R"""(
# Overview
# Predefined Variable
${help.ComposePropertyHelp(jpeg.Tag, `en)}
# Operator
# Cast Operation
${help.ComposeConstructorHelp(jpeg.Tag, `en)}
${help.ComposeMethodHelp(jpeg.Tag, `en)}
)""";
//------------------------------------------------------------------------------
// Implementation of constructor
//------------------------------------------------------------------------------
// jpeg.Tag(symbolOfIFD as Symbol, symbol as Symbol, value as any) {block?}
Gurax_DeclareConstructor(Tag)
{
Declare(VTYPE_Tag, Flag::None);
DeclareArg("symbolOfIFD", VTYPE_Symbol, ArgOccur::Once, ArgFlag::None);
DeclareArg("symbol", VTYPE_Symbol, ArgOccur::Once, ArgFlag::None);
DeclareArg("value", VTYPE_Any, ArgOccur::Once, ArgFlag::None);
DeclareBlock(BlkOccur::ZeroOrOnce);
AddHelp(Gurax_Symbol(en), u8R"""(
Creates a `jpeg.Tag` instance.
)""");
}
Gurax_ImplementConstructor(Tag)
{
// Arguments
ArgPicker args(argument);
const Symbol* pSymbolOfIFD = args.PickSymbol();
const Symbol* pSymbol = args.PickSymbol();
const Value& value = args.PickValue();
// Function body
RefPtr<Tag> pTag(Tag::Create(pSymbolOfIFD, pSymbol));
if (!pTag) return Value::nil();
if (!pTag->AssignValue(value.Reference())) return false;
return argument.ReturnValue(processor, new Value_Tag(pTag.release()));
}
//-----------------------------------------------------------------------------
// Implementation of method
//-----------------------------------------------------------------------------
// jpeg.Tag#MethodSkeleton(num1:Number, num2:Number)
Gurax_DeclareMethod(Tag, MethodSkeleton)
{
Declare(VTYPE_List, Flag::None);
DeclareArg("num1", VTYPE_Number, ArgOccur::Once, ArgFlag::None);
DeclareArg("num2", VTYPE_Number, ArgOccur::Once, ArgFlag::None);
AddHelp(Gurax_Symbol(en), u8R"""(
Skeleton.
)""");
}
Gurax_ImplementMethod(Tag, MethodSkeleton)
{
// Target
//auto& valueThis = GetValueThis(argument);
// Arguments
ArgPicker args(argument);
Double num1 = args.PickNumber<Double>();
Double num2 = args.PickNumber<Double>();
// Function body
return new Value_Number(num1 + num2);
}
//-----------------------------------------------------------------------------
// Implementation of property
//-----------------------------------------------------------------------------
// jpeg.Tag#name
Gurax_DeclareProperty_R(Tag, name)
{
Declare(VTYPE_String, Flag::None);
AddHelp(Gurax_Symbol(en), u8R"""(
)""");
}
Gurax_ImplementPropertyGetter(Tag, name)
{
auto& valueThis = GetValueThis(valueTarget);
return new Value_String(valueThis.GetTag().GetSymbol()->GetName());
}
// jpeg.Tag#orderHint
Gurax_DeclareProperty_R(Tag, orderHint)
{
Declare(VTYPE_Number, Flag::None);
AddHelp(Gurax_Symbol(en), u8R"""(
)""");
}
Gurax_ImplementPropertyGetter(Tag, orderHint)
{
auto& valueThis = GetValueThis(valueTarget);
return new Value_Number(valueThis.GetTag().GetOrderHint());
}
// jpeg.Tag#symbol
Gurax_DeclareProperty_R(Tag, symbol)
{
Declare(VTYPE_Symbol, Flag::None);
AddHelp(Gurax_Symbol(en), u8R"""(
)""");
}
Gurax_ImplementPropertyGetter(Tag, symbol)
{
auto& valueThis = GetValueThis(valueTarget);
return new Value_Symbol(valueThis.GetTag().GetSymbol());
}
// jpeg.Tag#tagId
Gurax_DeclareProperty_R(Tag, tagId)
{
Declare(VTYPE_Number, Flag::None);
AddHelp(Gurax_Symbol(en), u8R"""(
)""");
}
Gurax_ImplementPropertyGetter(Tag, tagId)
{
auto& valueThis = GetValueThis(valueTarget);
return new Value_Number(valueThis.GetTag().GetTagId());
}
// jpeg.Tag#type
Gurax_DeclareProperty_R(Tag, type)
{
Declare(VTYPE_Symbol, Flag::None);
AddHelp(Gurax_Symbol(en), u8R"""(
)""");
}
Gurax_ImplementPropertyGetter(Tag, type)
{
auto& valueThis = GetValueThis(valueTarget);
return new Value_Symbol(Tag::TypeIdToSymbol(valueThis.GetTag().GetTypeId()));
}
// jpeg.Tag#typeId
Gurax_DeclareProperty_R(Tag, typeId)
{
Declare(VTYPE_Number, Flag::None);
AddHelp(Gurax_Symbol(en), u8R"""(
)""");
}
Gurax_ImplementPropertyGetter(Tag, typeId)
{
auto& valueThis = GetValueThis(valueTarget);
return new Value_Number(valueThis.GetTag().GetTypeIdRaw());
}
// jpeg.Tag#value
Gurax_DeclareProperty_RW(Tag, value)
{
Declare(VTYPE_Any, Flag::None);
AddHelp(Gurax_Symbol(en), u8R"""(
)""");
}
Gurax_ImplementPropertyGetter(Tag, value)
{
auto& valueThis = GetValueThis(valueTarget);
return valueThis.GetTag().GetValue().Reference();
}
Gurax_ImplementPropertySetter(Tag, value)
{
auto& valueThis = GetValueThis(valueTarget);
valueThis.GetTag().AssignValue(value.Reference());
}
// jpeg.Tag#vtypeAcceptable
Gurax_DeclareProperty_R(Tag, vtypeAcceptable)
{
Declare(VTYPE_VType, Flag::None);
AddHelp(Gurax_Symbol(en), u8R"""(
)""");
}
Gurax_ImplementPropertyGetter(Tag, vtypeAcceptable)
{
auto& valueThis = GetValueThis(valueTarget);
VType& vtype = valueThis.GetTag().GetVTypeAcceptable();
return new Value_VType(vtype);
}
//------------------------------------------------------------------------------
// VType_Tag
//------------------------------------------------------------------------------
VType_Tag VTYPE_Tag("Tag");
void VType_Tag::DoPrepare(Frame& frameOuter)
{
// Add help
AddHelp(Gurax_Symbol(en), g_docHelp_en);
// Declaration of VType
Declare(VTYPE_Object, Flag::Immutable, Gurax_CreateConstructor(Tag));
// Assignment of method
Assign(Gurax_CreateMethod(Tag, MethodSkeleton));
// Assignment of property
Assign(Gurax_CreateProperty(Tag, name));
Assign(Gurax_CreateProperty(Tag, orderHint));
Assign(Gurax_CreateProperty(Tag, symbol));
Assign(Gurax_CreateProperty(Tag, tagId));
Assign(Gurax_CreateProperty(Tag, type));
Assign(Gurax_CreateProperty(Tag, typeId));
Assign(Gurax_CreateProperty(Tag, value));
Assign(Gurax_CreateProperty(Tag, vtypeAcceptable));
}
//------------------------------------------------------------------------------
// VType_Tag::Iterator_Each
//------------------------------------------------------------------------------
Value* VType_Tag::Iterator_Each::DoNextValue()
{
if (_idx >= GetTagOwner().size()) return nullptr;
RefPtr<Tag> pTag(GetTagOwner()[_idx]->Reference());
_idx++;
return new Value_Tag(pTag.release());
}
String VType_Tag::Iterator_Each::ToString(const StringStyle& ss) const
{
return "Tag.Each";
}
//------------------------------------------------------------------------------
// Value_Tag
//------------------------------------------------------------------------------
VType& Value_Tag::vtype = VTYPE_Tag;
String Value_Tag::ToString(const StringStyle& ss) const
{
return ToStringGeneric(ss, GetTag().ToString(ss));
}
Gurax_EndModuleScope(jpeg)
| [
"ypsitau@nifty.com"
] | ypsitau@nifty.com |
39c5228d60efe75685ed3f0bb277f6b7c6245c73 | eedcfd982b1cb324c799d7c6a8de0cade48aa11d | /trunk/falcon/literal.hpp | d2cf23175c38e95a22c84f27fcbc7769153192fc | [] | no_license | BGCX067/falcon-library-svn-to-git | ccaed2f07f0dfac2f752ff9fc5febb351754c0ac | 1fd15b25308570f7b32b4aa636a083be3f48d22c | refs/heads/master | 2021-01-13T00:56:29.835953 | 2015-12-28T14:19:27 | 2015-12-28T14:19:27 | 48,870,996 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 115 | hpp | #ifndef _FALCON_FALCON_LITERAL_HPP
#define _FALCON_FALCON_LITERAL_HPP
#include <falcon/literal/chrono.hpp>
#endif | [
"you@example.com"
] | you@example.com |
10b3976188216cec85978a24dfad46d85fc09242 | 184180d341d2928ab7c5a626d94f2a9863726c65 | /issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/probTTree_DeepState_TestHarness.cpp | beff1566ba66391492c2764e8a4818517d1a7dc6 | [] | no_license | akhikolla/RcppDeepStateTest | f102ddf03a22b0fc05e02239d53405c8977cbc2b | 97e73fe4f8cb0f8e5415f52a2474c8bc322bbbe5 | refs/heads/master | 2023-03-03T12:19:31.725234 | 2021-02-12T21:50:12 | 2021-02-12T21:50:12 | 254,214,504 | 2 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 4,509 | cpp | #include <fstream>
#include <ctime>
#include <RInside.h>
#include <iostream>
#include <RcppDeepState.h>
#include <qs.h>
#include <DeepState.hpp>
double probTTree(NumericMatrix ttree, double rOff, double pOff, double pi, double shGen, double scGen, double shSam, double scSam, double dateT, double delta_t);
TEST(TransPhylo_deepstate_test,probTTree_test){
RInside R;
std::time_t t = std::time(0);
std::cout << "input starts" << std::endl;
NumericMatrix ttree = RcppDeepState_NumericMatrix();
std::string ttree_t = "/home/akhila/R/x86_64-pc-linux-gnu-library/3.6/RcppDeepState/extdata/issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/afl_inputs/" + std::to_string(t) + "_ttree.qs";
qs::c_qsave(ttree,ttree_t,
"high", "zstd", 1, 15, true, 1);
std::cout << "ttree values: "<< ttree << std::endl;
NumericVector rOff(1);
rOff[0] = RcppDeepState_double();
std::string rOff_t = "/home/akhila/R/x86_64-pc-linux-gnu-library/3.6/RcppDeepState/extdata/issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/afl_inputs/" + std::to_string(t) + "_rOff.qs";
qs::c_qsave(rOff,rOff_t,
"high", "zstd", 1, 15, true, 1);
std::cout << "rOff values: "<< rOff << std::endl;
NumericVector pOff(1);
pOff[0] = RcppDeepState_double();
std::string pOff_t = "/home/akhila/R/x86_64-pc-linux-gnu-library/3.6/RcppDeepState/extdata/issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/afl_inputs/" + std::to_string(t) + "_pOff.qs";
qs::c_qsave(pOff,pOff_t,
"high", "zstd", 1, 15, true, 1);
std::cout << "pOff values: "<< pOff << std::endl;
NumericVector pi(1);
pi[0] = RcppDeepState_double();
std::string pi_t = "/home/akhila/R/x86_64-pc-linux-gnu-library/3.6/RcppDeepState/extdata/issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/afl_inputs/" + std::to_string(t) + "_pi.qs";
qs::c_qsave(pi,pi_t,
"high", "zstd", 1, 15, true, 1);
std::cout << "pi values: "<< pi << std::endl;
NumericVector shGen(1);
shGen[0] = RcppDeepState_double();
std::string shGen_t = "/home/akhila/R/x86_64-pc-linux-gnu-library/3.6/RcppDeepState/extdata/issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/afl_inputs/" + std::to_string(t) + "_shGen.qs";
qs::c_qsave(shGen,shGen_t,
"high", "zstd", 1, 15, true, 1);
std::cout << "shGen values: "<< shGen << std::endl;
NumericVector scGen(1);
scGen[0] = RcppDeepState_double();
std::string scGen_t = "/home/akhila/R/x86_64-pc-linux-gnu-library/3.6/RcppDeepState/extdata/issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/afl_inputs/" + std::to_string(t) + "_scGen.qs";
qs::c_qsave(scGen,scGen_t,
"high", "zstd", 1, 15, true, 1);
std::cout << "scGen values: "<< scGen << std::endl;
NumericVector shSam(1);
shSam[0] = RcppDeepState_double();
std::string shSam_t = "/home/akhila/R/x86_64-pc-linux-gnu-library/3.6/RcppDeepState/extdata/issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/afl_inputs/" + std::to_string(t) + "_shSam.qs";
qs::c_qsave(shSam,shSam_t,
"high", "zstd", 1, 15, true, 1);
std::cout << "shSam values: "<< shSam << std::endl;
NumericVector scSam(1);
scSam[0] = RcppDeepState_double();
std::string scSam_t = "/home/akhila/R/x86_64-pc-linux-gnu-library/3.6/RcppDeepState/extdata/issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/afl_inputs/" + std::to_string(t) + "_scSam.qs";
qs::c_qsave(scSam,scSam_t,
"high", "zstd", 1, 15, true, 1);
std::cout << "scSam values: "<< scSam << std::endl;
NumericVector dateT(1);
dateT[0] = RcppDeepState_double();
std::string dateT_t = "/home/akhila/R/x86_64-pc-linux-gnu-library/3.6/RcppDeepState/extdata/issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/afl_inputs/" + std::to_string(t) + "_dateT.qs";
qs::c_qsave(dateT,dateT_t,
"high", "zstd", 1, 15, true, 1);
std::cout << "dateT values: "<< dateT << std::endl;
NumericVector delta_t(1);
delta_t[0] = RcppDeepState_double();
std::string delta_t_t = "/home/akhila/R/x86_64-pc-linux-gnu-library/3.6/RcppDeepState/extdata/issuestests/TransPhylo/inst/testfiles/probTTree/AFL_probTTree/afl_inputs/" + std::to_string(t) + "_delta_t.qs";
qs::c_qsave(delta_t,delta_t_t,
"high", "zstd", 1, 15, true, 1);
std::cout << "delta_t values: "<< delta_t << std::endl;
std::cout << "input ends" << std::endl;
try{
probTTree(ttree,rOff[0],pOff[0],pi[0],shGen[0],scGen[0],shSam[0],scSam[0],dateT[0],delta_t[0]);
}
catch(Rcpp::exception& e){
std::cout<<"Exception Handled"<<std::endl;
}
}
| [
"akhilakollasrinu424jf@gmail.com"
] | akhilakollasrinu424jf@gmail.com |
02bb79bddefac004bb0c27496fc362012b801f00 | 2e9bcf4f49d45bdaab8338d9d719aba82e6f0ee8 | /src/Task5/src/task5_1.cpp | e1f1166068bc3fd2cf124cd5ea812adab4767938 | [] | no_license | dlbuger/OOP_Practical | 819432f365a549bdc72e382419efff5f62643507 | 2c30dcd4f4b3a4eaafb0d40831608adcddadc114 | refs/heads/master | 2020-07-16T17:58:09.680780 | 2019-09-10T15:05:02 | 2019-09-10T15:05:02 | 205,837,465 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,389 | cpp | #include <iostream>
using namespace std;
class Task5
{
private:
const int NUMBER_OF_PLANTS = 4;
int *production = new int[NUMBER_OF_PLANTS];
public:
void inputData()
{
for (int i = 1; i <= NUMBER_OF_PLANTS; i++)
{
cout << endl
<< "Enter production data for plant number "
<< i << endl;
getTotal(production[i - 1]);
}
}
void getTotal(int &amount)
{
cout << "Enter a positive integer of units produced by each department, ranging from 1-20.\n"
<< endl;
cin >> amount;
while (amount < 0)
{
cout << "input again" << endl;
cin >> amount;
}
}
void graph()
{
cout << "\nUnits produced in units:\n";
for (int i = 1; i <= NUMBER_OF_PLANTS; i++)
{
cout << "Plant #" << i << " ";
printAsterisks(production[i - 1]);
cout << endl;
}
}
void printAsterisks(int n)
{
for (int count = 1; count <= n; count++)
cout << "*";
}
Task5()
{
cout << "This program displays a graph showing\n"
<< "production for each plant in the company.\n";
inputData();
graph();
}
~Task5()
{
delete[] production;
}
};
int main()
{
Task5 t;
}
| [
"zhongxiao0711@gmail.com"
] | zhongxiao0711@gmail.com |
9ea2362618e0be455345fddfb30e183858c8b45b | 5a2497e0c96d8b04512b69f769f360e3fe872571 | /STL in C++/vector.cpp | 0a57f232a73523ad7e060ffdf37123b7ae8966c4 | [] | no_license | naman99lalit/Data-Structures-and-Algorithms | 10a5d7989cc8801bedca9139d57def8f862be0df | 4209c33f9319cd2eef610773a835ef01e5d62acd | refs/heads/master | 2021-06-28T14:41:07.792562 | 2020-10-29T16:42:18 | 2020-10-29T16:42:18 | 166,237,802 | 0 | 2 | null | 2020-10-29T16:42:19 | 2019-01-17T14:19:23 | C++ | UTF-8 | C++ | false | false | 329 | cpp | #include<bits/stdc++.h>
using namespace std;
int main()
{
vector<int> v;
vector<int> :: iterator it;
v.push_back(5);
v.push_back(10);
v.push_back(19);
v.push_back(2);
v.push_back(12);
cout<<"Sorting A Vector in C++"<<endl;
sort(v.begin(),v.end());
for(it=v.begin();it<v.end();it++)
{
cout<<*it<<" ";
}
return 0;
} | [
"naman.lalit@gmail.com"
] | naman.lalit@gmail.com |
2a4e4c72713019f038bd703069ed444dbacab921 | 0d6080677f8b2d6d85362b0b26c86dffb2fb4c6f | /builder.cpp | 9128b14f867ae3b129685612cd360d48d70a7aa5 | [] | no_license | WpiszCokolwiek/Projekt_DP | 62491ec19cc2b6a1e39d1f1795cfc91a13ba04f9 | c1cb3c9a20cc04999f5d39e5da8cbaa4ec8131f9 | refs/heads/master | 2020-04-09T23:07:56.104347 | 2018-12-06T09:53:51 | 2018-12-06T09:53:51 | 160,647,734 | 0 | 1 | null | 2018-12-06T09:44:06 | 2018-12-06T09:03:06 | C++ | UTF-8 | C++ | false | false | 3,297 | cpp | /****************************************
* Wzorzec Projektowy Builder *
* (budowniczy) *
* www.algorytm.org *
* Opracowal Dworak Kamil *
*****************************************/
"Ver 1.1"
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class ZestawKomputerowy {
private:
string monitor;
string procesor;
string grafika;
string ram;
string hdd;
public:
void setMonitor(string m){
monitor = m ;
}
void setProcesor(string p){
procesor = p;
}
void setGrafika(string g){
grafika = g;
}
void setRam(string r){
ram = r;
}
void setHdd(string h){
hdd = h;
}
void show(){
if(monitor!="") cout<< "Monitor = " << monitor << endl;
if(procesor!="") cout << "Procesor = " << procesor << endl;
if(grafika!="") cout << "Grafika = " << grafika << endl;
if(ram!="") cout << "RAM = " << ram << endl;
if(hdd!="") cout << "HDD = " << hdd << endl;
}
};
/* nasz glowny interdace */
class Builder {
protected:
ZestawKomputerowy* zestawKomputerowy;
public:
void newZestaw(){
zestawKomputerowy = new ZestawKomputerowy();
}
ZestawKomputerowy getZestaw(){
return* zestawKomputerowy;
}
virtual void buildMonitor()=0;
virtual void buildProcesor()=0;
virtual void buildGrafika()=0;
virtual void buildRam()=0;
virtual void buildHdd()=0;
};
class ZestawXT001:public Builder {
public :
ZestawXT001():Builder(){
}
void buildMonitor(){
zestawKomputerowy->setMonitor("Benq 19");
}
void buildProcesor(){
zestawKomputerowy->setProcesor("amd");
}
void buildGrafika(){
zestawKomputerowy->setGrafika("ATI");
}
void buildRam(){
zestawKomputerowy->setRam("DDR3");
}
void buildHdd(){
int t;
while(true){
cout << "Dysk do wyboru: (1) Samsung, (2) Segate, (3) Caviar"<<endl;
cin >> t;
if(t>0 && t<4) break;
}
string wynik;
if(t==1) wynik = "Samsung";
else if(t==2) wynik = "Segate";
else if(t==3) wynik = "Caviar";
zestawKomputerowy->setHdd(wynik);
}
};
class ZestawABC996:public Builder {
public:
ZestawABC996():Builder(){
}
void buildMonitor(){
zestawKomputerowy->setMonitor("LG");
}
void buildProcesor(){
zestawKomputerowy->setProcesor("INTEL");
}
void buildGrafika(){
//zestaw nie obejmuje karty graficznej
}
void buildRam(){
zestawKomputerowy->setRam("DDR");
}
void buildHdd(){
zestawKomputerowy->setHdd("Samsung");
}
};
/* kierownik */
class Director {
private:
Builder* builder;
public:
void setBuilder(Builder* b){
builder = b;
}
ZestawKomputerowy getZestaw(){
return builder->getZestaw();
}
void skladaj(){
builder->newZestaw();
builder->buildMonitor();
builder->buildProcesor();
builder->buildHdd();
builder->buildRam();
builder->buildGrafika();
}
};
int main(){
Director* szef = new Director();
Builder* builder = new ZestawXT001();
Builder* builder2 = new ZestawABC996();
cout<<"\nZESTAW 1\n";
szef->setBuilder(builder);
szef->skladaj();
ZestawKomputerowy zestaw1 = szef->getZestaw();
szef->setBuilder(builder2);
szef->skladaj();
ZestawKomputerowy zestaw2 = szef->getZestaw();
zestaw1.show();
cout << "\n\nZESTAW2\n" ;
zestaw2.show();
int x;
cin >>x;
}
| [
"noreply@github.com"
] | noreply@github.com |
5718f84bddbd52134b565087a4e7ca6d37b62655 | 93fa04a88ebd209fcf8f73df87967bbb1b11722a | /SMLib/operand.h | f14cb9cd139219055deac37e5325faadfd96c96e | [] | no_license | Wrobelaf/SML | 41afb3e7a27fd70394570c2dbd6f9a1080e77bb4 | e46a4d45fe8ac8129e98d64af24bb48a59355ca6 | refs/heads/master | 2020-12-03T01:57:59.384688 | 2017-06-30T13:30:43 | 2017-06-30T13:30:43 | 95,887,704 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 578 | h | /*
operand.h
Class holding the operand part of SML instruction words.
*/
#ifndef __OPERAND_
#define __OPERAND_
namespace SML {
class Operand
{
public:
Operand(unsigned int);
~Operand();
unsigned int operator*(void) const;
Operand &operator++();
Operand operator++(int);
int GetSignedValue(void) const;
void MakeAsSignedValue(void);
void SetOperand(const unsigned int);
friend ostream &operator<<(ostream &, const Operand &);
bool debug(void) const;
bool debug(const bool pb);
private:
int op;
bool dbug;
};
} // Namespace SML
#endif // __OPERAND_
| [
"noreply@github.com"
] | noreply@github.com |
eeab5795fddd8d8144cde85a067932cb9bcf0917 | 08a1dcd97e825d147bd05762b31db7cc71545da9 | /mooc_cpp1/week3_a.cpp | bbd22ba0d183fedfae63b577afe925f015d34caf | [] | no_license | zhufree/repos | e790e227b4975888a780fde417fdc879095f68fa | ec5ed8863f7b03499bca3494d89e76828b1123d4 | refs/heads/master | 2021-01-19T10:34:28.018160 | 2017-03-08T05:26:10 | 2017-03-08T05:26:10 | 82,192,032 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,472 | cpp | #include <cstdio>
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
/*
假设鸡尾酒疗法的有效率为x,新疗法的有效率为y,
如果y-x大于5%,则效果更好,如果x-y大于5%,则效果更差,否则称为效果差不多。
下面给 出n组临床对照实验,其中第一组采用鸡尾酒疗法,其他n-1组为各种不同的改进疗法。
请写程序判定各种改进疗法效果如何。
输入
第一行为整数n( 1 < n <= 20);
其余n行每行两个整数,第一个整数是临床实验的总病例数(小于等于10000),
第二个疗效有效的病例数。
这n行数据中,第一行为鸡尾酒疗法的数据,其余各行为各种改进疗法的数据。
输出
有n-1行输出,分别表示对应改进疗法的效果:
如果效果更好,输出better;如果效果更差,输出worse;否则输出same
*/
int n, dx, dy, x, y;
double dr, r;
scanf("%d", &n);
int result[n];
scanf("%d %d", &dx, &dy);
dr = (double)dy/dx;
for (int i = 1; i < n; ++i)
{
scanf("%d %d", &x, &y);
// printf("%.5lf\n", (double)y/x);
if (dr - (double)y/x > 0.05) {
result[i-1] = -1;
} else if ((double)y/x - dr > 0.05) {
result[i-1] = 1;
} else {
result[i-1] = 0;
}
}
for (int i = 0; i < n-1; ++i)
{
if (result[i] == 1) {
printf("better\n");
} else if (result[i] == -1) {
printf("worse\n");
} else {
printf("same\n");
}
}
return 0;
} | [
"zhufree2013@gmail.com"
] | zhufree2013@gmail.com |
dadb40220f49ec7715b2b74f5a6b410ac6d03815 | dc327c3d79f343ae8b4d1f9d07a3ff6b57af1895 | /exo1tp7/tp7.cpp | b9215840ac24816ecb355de57a098bf4098489ba | [] | no_license | dm0lz/CPlusPlus | fdaf1bf3e2ffbc0d2206178f1cc16a9e89fa4c73 | 1129a09ff63c1183ac1694ab1c26787222c53eb9 | refs/heads/master | 2021-05-27T20:44:58.745033 | 2012-10-18T02:43:46 | 2012-10-18T02:43:46 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 148 | cpp | /*
* tp7.cpp
* exo1tp7
*
* Created by molz on 11/01/11.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/
#include "tp7.h"
| [
"ducrouxolivier@gmail.com"
] | ducrouxolivier@gmail.com |
9116826d1e386647016be1c55e56aff1c0cf00ea | 9b6acaebd72bb1914838fb3091c0d447bf03104a | /apoenum/apoenum/main.cpp | 63415b51d250205346edc0781d97990c923fe994 | [] | no_license | mvaneerde/blog | 31ad3ab0d1c13e49da5d9f04994c706c2dd36e5e | 55e6f077b034e90dadfa63b51af5e37d0a3cf6ca | refs/heads/develop | 2023-09-03T19:31:53.969123 | 2023-08-25T17:52:56 | 2023-08-25T17:52:56 | 42,925,860 | 223 | 122 | null | 2021-05-11T11:50:34 | 2015-09-22T09:56:16 | HTML | UTF-8 | C++ | false | false | 188 | cpp | // main.cpp
#include <windows.h>
#include <stdio.h>
#include "log.h"
#include "apoenum.h"
int _cdecl wmain() {
HRESULT hr = EnumerateAudioProcessingObjects();
return hr;
} | [
"mvaneerde@yahoo.com"
] | mvaneerde@yahoo.com |
b871490e68614a18503b34605617c9484ae69fec | f17bfe06ef0ebbcfe35b0de57b9915193c191e39 | /boggleplayer.cpp | f484df745493f8521b4c16e5f86f1ca738b2a533 | [] | no_license | Patchett/Boggle-Game | cb9ceefac52bfd76b3501535cd465dbc665403d8 | 210be7032327388c1a9d894e2574baf8c534966a | refs/heads/master | 2021-01-10T18:49:54.944064 | 2016-02-17T09:33:19 | 2016-02-17T09:33:19 | 29,002,196 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,552 | cpp | #include "boggleplayer.h"
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
void BogglePlayer::setBoard(unsigned int rows, unsigned int cols, std::string **diceArray)
{
ROWS = rows;
COLS = cols;
// Clear and resize boardVector
boardVector.clear();
boardVector.resize(ROWS, vector<string>(COLS));
// Clear and resize wasVisited
wasVisited.clear();
wasVisited.resize(ROWS, vector<bool>(COLS));
// cout << "==== The Board ====" << endl;
// Traverse diceArray and convert all elements to lowercase. The store the
// elements in boardVector
for (unsigned int r = 0; r < rows; r++)
{
for (unsigned int c = 0; c < cols; c++)
{
// Convert diceArray[r][c] to all lowercase and insert
// the result into the board
boardVector[r][c] = diceArray[r][c];
transform(diceArray[r][c].begin(),
diceArray[r][c].end(),
boardVector[r][c].begin(), ::tolower);
// cout << boardVector[r][c];
}
// cout << "\n";
}
// cout << "===================" << endl;
boardExists = true;
}
vector<int> BogglePlayer::isOnBoard(const string &word_to_check)
{
// convert word_to_check to lowercase
string lowerCaseWord = word_to_check;
transform(word_to_check.begin(), word_to_check.end(),
lowerCaseWord.begin(), ::tolower);
// Location of the word in the board
vector<int> wordLocation;
// Check if setBoard has been called yet
if (!boardExists)
return wordLocation;
// Traverse every element in the board
for (int r = 0 ; r < ROWS; r++)
{
for (int c = 0 ; c < COLS; c++)
{
// Recursively search for the word at the current index
if (searchAtIndex(lowerCaseWord, wordLocation, r, c))
return wordLocation;
}
}
return wordLocation;
}
bool BogglePlayer::searchAtIndex(const string &word_to_check,
vector<int> &wordLocation, int r, int c)
{
// Make sure that the board exists
if (!boardExists)
return false;
// Make sure that the current position is in range
if (r > (ROWS-1) || c > (COLS-1) || r < 0 || c < 0)
return false;
// The word to check is smaller than the contents of
// this element in the board
if (word_to_check.length() < boardVector[r][c].length())
return false;
// Check if this element has already been visited
if (wasVisited[r][c])
return false;
// Check if current element in the board is a substring of word_to_check
if (word_to_check.substr(0, boardVector[r][c].length()) != boardVector[r][c])
return false;
// All checks passed. This element of
// boardVector contains the string we need
wordLocation.push_back(COLS * r + c);
if (word_to_check == boardVector[r][c])
return true;
wasVisited[r][c] = true;
// Recursively iterate through the adjust[][] array defined in boggleplayer.h which allows
// us to check all of the current element's neighbors for strings that match
// what we are looking for
for (short zod = 0; zod < 8; zod++)
{
// Jump to the next neighbor and call the recursive search function
if (searchAtIndex(word_to_check.substr(boardVector[r][c].length()),
wordLocation, adjust[0][zod] + r, adjust[1][zod] + c))
{
// Once a word is found, set wasVisited to false as we move back up
// the stack frame
wasVisited[r][c] = false;
return true;
}
}
// The next part of the word_to_check was not found
// in any of the surrounding elements
wasVisited[r][c] = false;
// Clear wordLocation vector
wordLocation.pop_back();
return false;
}
void BogglePlayer::buildLexicon(const set<string> &word_list)
{
if (lexiconExists)
delete Lexicon;
Lexicon = new TST();
// cout << "Building Lexicon..." << endl;
// Store the set in a vector so that it can be shuffled
vector<string> lexVector(word_list.begin(), word_list.end());
// Shuffle the vector so that the structure of the TST is not a linked list
random_shuffle(lexVector.begin(), lexVector.end());
// Insert all elements into the TST
for (auto &zod : lexVector)
{
// cout << "Inserting " << zod << " into Lexicon" << endl;
Lexicon->insert(zod, Lexicon->root);
}
lexVector.clear();
// cout << "Core dump is here " << endl;
// cout << "Root of Lexicon is: " << Lexicon->root->data << endl;
// cout << "Mid of Lexicon is: " << Lexicon->root->mid->data << endl;
lexiconExists = true;
}
bool BogglePlayer::getAllValidWords(unsigned int minimum_word_length, set<string> *words)
{
// Store the minimum_word_length
minWordLength = minimum_word_length;
// Check if Lexicon and Board exist
if (!lexiconExists || !boardExists)
return false;
// Iterate through the entire board
// Call the recursive function at each element on the board that will get
// all valid words that start with that element
for (int r = 0; r < ROWS; r++)
{
for (int c = 0; c < COLS; c++)
{
// cout << "Get all valid words at " << boardVector[r][c] << endl;
getAllValidWordsAtIndex("", words, r, c);
}
}
return true;
}
bool BogglePlayer::getAllValidWordsAtIndex(string currentWord, set<string> *words, int r, int c)
{
// Make sure that the current position is in range
if (r > (ROWS-1) || c > (COLS-1) || r < 0 || c < 0)
return false;
// Check if this element has already been visited
if (wasVisited[r][c])
return false;
// Concatenate the contents of the current element of the board with currentWord
currentWord += boardVector[r][c];
// Check if the new concatenated word is a prefix of a word in the Lexicon
char prefix = Lexicon->find(currentWord, Lexicon->root);
// New concatenated string is not a prefix.
if (!prefix)
return false;
wasVisited[r][c] = true;
// currentWord is a valid word in the Lexicon. Insert it into the set
if (currentWord.size() >= minWordLength && prefix == 2)
words->insert(currentWord);
// Check all of the current element's neighbors for strings that are in the
// lexicon by iterating through the adjust[][] vector to visit the neighbors
for (short zod = 0; zod < 8; zod++)
getAllValidWordsAtIndex(currentWord, words, adjust[0][zod] + r, adjust[1][zod] + c);
wasVisited[r][c] = false;
return true;
}
bool BogglePlayer::isInLexicon(const string &word_to_check)
{
// Check if Lexicon exists
if (!lexiconExists)
return false;
// Find the word in the Lexicon
char result = Lexicon->find(word_to_check, Lexicon->root);
// Word was found if result is 2
if (result == 2)
return true;
// Word was not found if result was 0 or 1
else return false;
}
// This is producing a segfault when invoked. Not mandatory for assignment.
void BogglePlayer::getCustomBoard(string ** &new_board, unsigned int *rows, unsigned int *cols)
{
COLS = *cols;
ROWS = *rows;
std::ifstream customBoard("brd.txt");
// Clear and resize boardVector
boardVector.clear();
boardVector.resize(ROWS, vector<string>(COLS));
// Clear and resize wasVisited
wasVisited.clear();
wasVisited.resize(ROWS, vector<bool>(COLS));
// cout << "==== The Board ====" << endl;
//
// Allocate space for the new board
new_board = new std::string*[ROWS];
for (unsigned int r=0; r < *rows; ++r)
{
string *row = new std::string[COLS];
for (unsigned int c = 0; c < *cols; ++c)
customBoard >> row[c];
new_board[r] = row;
}
// store new board
for (unsigned int r = 0; r < *rows; r++)
{
for (unsigned int c = 0; c < *cols; c++)
{
// Convert diceArray[r][c] to all lowercase and insert
// the result into the board
boardVector[r][c] = new_board[r][c];
transform(new_board[r][c].begin(),
new_board[r][c].end(),
boardVector[r][c].begin(), ::tolower);
// cout << boardVector[r][c];
}
// cout << "\n";
}
// cout << "===================" << endl;
boardExists = true;
}
| [
"rybridges16@gmail.com"
] | rybridges16@gmail.com |
66c64669ec64ff8e7ca9ac43efebdf9133269eac | 31bd4984f3cb44e1292321895cec5ff5d993aac6 | /Test_Roxlu_Flock_Windows/src/application/visuals/Cloak.h | 869c0200b9804a97d01995b08921a59328fccf9a | [
"MIT"
] | permissive | HellicarAndLewis/Triptych | a221a1cd58d9232ca58adbaad5f3610eba6547eb | 866e865f60ddd24efee57a6a8904567669ff71a4 | refs/heads/master | 2020-12-24T15:31:57.395363 | 2013-12-12T13:30:49 | 2013-12-12T13:30:49 | 4,615,958 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 430 | h | #ifndef ROXLU_CLOAKH
#define ROXLU_CLOAKH
//#include "Roxlu.h"
//#include "PBD.h"
#include <roxlu/Roxlu.h>
#include <pbd/PBD.h>
class Cloak {
public:
Cloak(Particles3& ps, vector<Triangle>& tris);
void setup();
void update();
void debugDraw();
void draw(const Mat4& pm, const Mat4& vm, const Mat3& nm);
Particles3& ps;
vector<Triangle>& tris;
VerticesPNC vertices;
VAO vao;
GLuint vbo;
Shader shader;
};
#endif | [
"diederickh@gmail.com"
] | diederickh@gmail.com |
40dfa6a6ca4b4550b14bc2fb1a0cbd493d6604cb | 3f6da80eab43b2247dba2bc1cb39310bd0fcf67a | /include/trading_system.hpp | 1d833302e742a249e9180a29b50e65ce2ae7a6ed | [] | no_license | Kyle0923/catan | 330812686029181ae57793ffe437dff59ccbcdc0 | 23500c3becb7d3a645ed21ee4be71bd398b6233c | refs/heads/master | 2023-06-07T22:24:45.574976 | 2021-06-21T00:10:57 | 2021-06-21T00:10:57 | 350,213,471 | 0 | 0 | null | 2021-05-29T22:12:33 | 2021-03-22T05:04:03 | C++ | UTF-8 | C++ | false | false | 4,022 | hpp | /**
* Project: catan
* @file trading_system.hpp
* @brief handlers that related to trading
*
* @author Zonghao Huang <kyle0923@qq.com>
*
* All right reserved.
*/
#ifndef INCLUDE_TRADING_SYSTEM_HPP
#define INCLUDE_TRADING_SYSTEM_HPP
#include <map>
#include "command_dispatcher.hpp"
#include "command_parameter_reader.hpp"
#include "command_common.hpp"
#include "game_map.hpp"
#include "user_interface.hpp"
#include "utility.hpp"
#include "logger.hpp"
#if 0
Offer_composer
Trade |- With_bank
|- With_player -> offer_initiator -> offer_broker -> offer_finalizer
#endif
struct Offer_t {
size_t offeror;
std::map<ResourceTypes, int> resources;
};
/**
* @brief
* an helper class to compose the offer,
* does not inherit from CommandHandler,
* therefore, it is not expected to be used by itself
*/
class OfferComposer
{
private:
bool mOfferComplete;
Offer_t mOffer;
public:
ActionStatus composeOffer(const std::vector<std::string>& aArgs, std::vector<std::string>& aReturnMsg);
const std::vector<std::string>& paramAutoFillPool(size_t aParamIndex) const;
void instruction(std::vector<std::string>& aReturnMsg) const;
void reset();
bool isOfferComplete() const;
const Offer_t& getOffer() const;
OfferComposer(const size_t aPlayerId);
};
class TradeHandler: public StatelessCommandHandler
{
private:
static const std::vector<std::string> mTradingTargets;
void instruction(std::vector<std::string>& aReturnMsg) const;
protected:
virtual ActionStatus statelessRun(GameMap& aMap, UserInterface& aUi, const std::vector<std::string>& aArgs, std::vector<std::string>& aReturnMsg) override final;
public:
virtual std::string command() const override final;
virtual std::string description() const override final;
virtual const std::vector<std::string>& paramAutoFillPool(size_t aParamIndex) const override final;
};
class OfferInitiator: public StatefulCommandHandler
{
private:
OfferComposer mOfferComposer;
protected:
virtual ActionStatus statefulRun(GameMap& aMap, UserInterface& aUi, std::vector<std::string>& aReturnMsg) override final;
virtual ActionStatus onStringParametersReceive(GameMap& aMap, const std::vector<std::string>& aArgs, std::vector<std::string>& aReturnMsg) override final;
virtual bool parameterComplete() const override final;
// not used
virtual ActionStatus onParameterReceive(GameMap& aMap, const std::string& aParam, Point_t aPoint, std::vector<std::string>& aReturnMsg) override final;
public:
virtual std::string command() const override final;
virtual const std::vector<std::string>& paramAutoFillPool(size_t aParamIndex) const override final;
virtual void resetParameters() override final;
virtual void instruction(std::vector<std::string>& aReturnMsg) const override final;
OfferInitiator(const size_t aPlayerId);
};
class OfferBroker: public StatefulCommandHandler
{
private:
bool mOfferComplete;
Offer_t mIncomingOffer;
protected:
virtual ActionStatus statefulRun(GameMap& aMap, UserInterface& aUi, std::vector<std::string>& aReturnMsg) override final;
virtual ActionStatus onStringParametersReceive(GameMap& aMap, const std::vector<std::string>& aArgs, std::vector<std::string>& aReturnMsg) override final;
virtual bool parameterComplete() const override final;
// not used
virtual ActionStatus onParameterReceive(GameMap& aMap, const std::string& aParam, Point_t aPoint, std::vector<std::string>& aReturnMsg) override final;
public:
virtual std::string command() const override final;
virtual std::string description() const override final;
virtual const std::vector<std::string>& paramAutoFillPool(size_t aParamIndex) const override final;
virtual size_t currentParamIndex() const override final;
virtual void resetParameters() override final;
virtual void instruction(std::vector<std::string>& aReturnMsg) const override final;
OfferBroker();
};
#endif /* INCLUDE_TRADING_SYSTEM_HPP */ | [
"kyle0923@qq.com"
] | kyle0923@qq.com |
1fdd00a2d83069c8b33149fe45ad75c418fa6b55 | f9e966301e911c9da67479538808c08f80c96247 | /src/tcpserver.h | 92ce221b113685d59b57adacdd2f40bdba133950 | [
"Unlicense"
] | permissive | eaglesquads/http-plus-plus | 4241e38b6c670d1ac8a77d1cb71a310c4cc5d611 | 56e50f384026fcae86f4ee34f162f616cc24a672 | refs/heads/master | 2021-01-09T02:51:47.830964 | 2016-10-24T22:36:27 | 2016-10-24T22:36:27 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,057 | h | #ifndef SOCKET_H
#define SOCKET_H
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <netinet/in.h>
#include <resolv.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <pthread.h>
#include <stdexcept>
#include "tcpsocket.h"
/**
* @brief The TcpServer class
* @remarks Creates socket, binds to port, and listens to it
* @abstract
*/
class TcpServer
{
public:
TcpServer(unsigned short port);
virtual ~TcpServer();
virtual void run() = 0;
class SocketOpenException {};
class SocketBindException {};
class SocketListenException {};
class SocketAcceptException {};
protected:
void openSocket();
void bindPort();
void listenSocket();
void closeSocket();
/* accepts a client, returns their socket descriptor */
TcpSocket* acceptClient(); // must be freed by the caller
private:
int _sock; /* master socket */
unsigned short _port;
struct sockaddr_in _servAddr; /* Local address */
};
#endif // SOCKET_H
| [
"zerosum0x0@gmail.com"
] | zerosum0x0@gmail.com |
b4a4f61312454d063378a1fd90134f4dc7cebe79 | 7fdc57a2c776a1c6bc1bc856b51249b3d95717b1 | /ZMPOZD2/Bird.cpp | e613e51209010d691a7451ae6975bc5974d44d5f | [] | no_license | Lamsko/class-hierarchy | 0b40540ac69b76669277a071618c97474f920e20 | 7687434170383037034e1861ace12cd3bf975d06 | refs/heads/master | 2021-01-11T19:11:51.927915 | 2017-01-21T16:37:26 | 2017-01-21T16:37:26 | 79,331,964 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 222 | cpp | #include "stdafx.h"
#include "Bird.h"
Bird::Bird()
{
}
Bird::~Bird()
{
}
void Bird::f()
{
cout << "Przedstawienie klasy Bird." << endl;
}
void Bird::vf()
{
cout << "Wirtualne przedstawienie klasy Bird." << endl;
}
| [
"w.mormul@gmail.com"
] | w.mormul@gmail.com |
f8a64fada07e31bc8c927514b54538cbeb9a9baa | 4352b5c9e6719d762e6a80e7a7799630d819bca3 | /tutorials/eulerVortex.twitch/eulerVortex.cyclic.twitch.test.test/1.01/T | c067f9a6a1dde1ca921c0c39e039e1494adb4644 | [] | no_license | dashqua/epicProject | d6214b57c545110d08ad053e68bc095f1d4dc725 | 54afca50a61c20c541ef43e3d96408ef72f0bcbc | refs/heads/master | 2022-02-28T17:20:20.291864 | 2019-10-28T13:33:16 | 2019-10-28T13:33:16 | 184,294,390 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 67,115 | /*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 6
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "1.01";
object T;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 1 0 0 0];
internalField nonuniform List<scalar>
22500
(
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999999
0.999999
0.999999
0.999999
0.999999
0.999999
0.999999
0.999999
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999999
0.999999
0.999998
0.999998
0.999998
0.999997
0.999997
0.999997
0.999997
0.999997
0.999998
0.999998
0.999998
0.999999
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999998
0.999998
0.999997
0.999997
0.999996
0.999995
0.999995
0.999995
0.999994
0.999995
0.999995
0.999996
0.999996
0.999997
0.999997
0.999998
0.999998
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999999
0.999999
0.999997
0.999997
0.999996
0.999995
0.999994
0.999992
0.999992
0.999991
0.99999
0.99999
0.99999
0.999991
0.999992
0.999992
0.999993
0.999995
0.999996
0.999997
0.999998
0.999998
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999998
0.999997
0.999996
0.999994
0.999993
0.999991
0.999988
0.999986
0.999985
0.999983
0.999982
0.999982
0.999982
0.999983
0.999984
0.999986
0.999988
0.99999
0.999992
0.999994
0.999995
0.999997
0.999998
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999997
0.999996
0.999995
0.999993
0.99999
0.999987
0.999983
0.999979
0.999975
0.999972
0.999969
0.999967
0.999966
0.999967
0.999968
0.999971
0.999974
0.999978
0.999982
0.999986
0.999989
0.999992
0.999994
0.999996
0.999997
0.999998
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999997
0.999996
0.999994
0.999991
0.999987
0.999982
0.999976
0.999969
0.999962
0.999956
0.999949
0.999944
0.999941
0.999939
0.99994
0.999943
0.999947
0.999953
0.99996
0.999967
0.999974
0.99998
0.999985
0.999989
0.999993
0.999995
0.999997
0.999998
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999997
0.999996
0.999993
0.999989
0.999984
0.999977
0.999968
0.999958
0.999947
0.999934
0.999923
0.999911
0.999903
0.999896
0.999894
0.999896
0.9999
0.999908
0.999919
0.99993
0.999942
0.999954
0.999964
0.999974
0.999981
0.999987
0.999991
0.999994
0.999996
0.999998
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
0.999998
0.999997
0.999996
0.999993
0.999988
0.999981
0.999972
0.999961
0.999947
0.999928
0.999909
0.999887
0.999867
0.999847
0.999832
0.999822
0.999818
0.999819
0.999827
0.999841
0.999859
0.999879
0.9999
0.99992
0.999939
0.999954
0.999967
0.999977
0.999985
0.99999
0.999993
0.999996
0.999998
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999998
0.999996
0.999992
0.999988
0.99998
0.999969
0.999954
0.999934
0.999909
0.999879
0.999847
0.999811
0.999776
0.999743
0.999717
0.999699
0.999691
0.999694
0.999709
0.999732
0.999761
0.999795
0.999831
0.999865
0.999896
0.999922
0.999944
0.999961
0.999974
0.999983
0.999989
0.999993
0.999996
0.999998
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999998
0.999996
0.999994
0.999988
0.99998
0.999967
0.999948
0.999924
0.99989
0.99985
0.999801
0.999745
0.999687
0.999628
0.999575
0.999531
0.999501
0.999487
0.999493
0.999515
0.999554
0.999603
0.99966
0.999719
0.999775
0.999827
0.999871
0.999907
0.999935
0.999956
0.999972
0.999982
0.999989
0.999993
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999997
0.999994
0.999989
0.99998
0.999967
0.999946
0.999917
0.999876
0.999823
0.999756
0.999677
0.999587
0.999491
0.999396
0.999309
0.999237
0.999187
0.999165
0.999172
0.99921
0.999272
0.999353
0.999445
0.999541
0.999634
0.999717
0.999789
0.999848
0.999894
0.999929
0.999953
0.999971
0.999982
0.999989
0.999994
0.999997
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999995
0.999991
0.999982
0.999969
0.999947
0.999915
0.999868
0.999803
0.999718
0.999612
0.999485
0.999342
0.99919
0.999037
0.998897
0.998781
0.9987
0.998664
0.998676
0.998734
0.998834
0.998964
0.999112
0.999266
0.999414
0.999549
0.999663
0.999757
0.999831
0.999886
0.999926
0.999953
0.999971
0.999983
0.99999
0.999994
0.999997
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999996
0.999992
0.999985
0.999973
0.999951
0.999918
0.999867
0.999793
0.999692
0.999559
0.999393
0.999195
0.99897
0.998731
0.998492
0.99827
0.998087
0.997959
0.997902
0.997919
0.998011
0.998167
0.998372
0.998605
0.998847
0.99908
0.999291
0.999473
0.999621
0.999736
0.999822
0.999884
0.999926
0.999955
0.999973
0.999984
0.999991
0.999995
0.999997
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999994
0.999988
0.999977
0.999957
0.999925
0.999873
0.999795
0.999683
0.999528
0.999324
0.999068
0.998764
0.998418
0.998049
0.99768
0.997337
0.997052
0.996854
0.996763
0.996789
0.99693
0.997172
0.997489
0.997849
0.998224
0.998585
0.99891
0.99919
0.999417
0.999594
0.999726
0.999821
0.999887
0.999931
0.999959
0.999976
0.999987
0.999993
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999996
0.999991
0.999982
0.999965
0.999935
0.999887
0.99981
0.999692
0.999522
0.999288
0.998981
0.998595
0.998135
0.997614
0.997054
0.996494
0.995973
0.99554
0.995236
0.995096
0.995135
0.995349
0.995716
0.996197
0.996746
0.997315
0.997861
0.998355
0.998778
0.999122
0.999389
0.999588
0.999732
0.99983
0.999896
0.999938
0.999964
0.99998
0.999989
0.999994
0.999997
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999994
0.999987
0.999973
0.999948
0.999905
0.999832
0.999718
0.999545
0.999293
0.998947
0.998493
0.997921
0.997238
0.996464
0.995632
0.994797
0.994021
0.993373
0.992919
0.992707
0.992764
0.993083
0.99363
0.994348
0.995168
0.996017
0.996831
0.997565
0.998193
0.998702
0.999098
0.999393
0.999605
0.99975
0.999847
0.999909
0.999948
0.999971
0.999984
0.999992
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999996
0.999991
0.999981
0.999961
0.999925
0.999862
0.999757
0.999591
0.999339
0.998974
0.998471
0.997809
0.996978
0.995984
0.994854
0.993641
0.992419
0.991283
0.990335
0.989669
0.989359
0.989441
0.989908
0.99071
0.991762
0.992961
0.994202
0.995392
0.996464
0.997378
0.998119
0.998695
0.999123
0.999428
0.999639
0.999779
0.999869
0.999925
0.999958
0.999977
0.999988
0.999994
0.999997
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999995
0.999987
0.999973
0.999945
0.999893
0.999804
0.999654
0.999418
0.999058
0.998537
0.99782
0.996875
0.995687
0.994265
0.992649
0.99091
0.989159
0.98753
0.986171
0.985217
0.984774
0.984893
0.985565
0.986716
0.988226
0.989945
0.991724
0.993429
0.994963
0.99627
0.997328
0.998147
0.998756
0.99919
0.999489
0.999687
0.999814
0.999893
0.99994
0.999967
0.999983
0.999991
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999992
0.999982
0.999962
0.999923
0.999851
0.999726
0.999518
0.999186
0.998682
0.997954
0.996948
0.995623
0.993957
0.991962
0.989692
0.98725
0.984792
0.982506
0.980601
0.979268
0.978652
0.978825
0.979771
0.981388
0.983507
0.985921
0.988418
0.990812
0.992964
0.994793
0.996275
0.99742
0.998268
0.998874
0.99929
0.999566
0.999742
0.999851
0.999917
0.999955
0.999976
0.999988
0.999994
0.999997
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999996
0.99999
0.999975
0.999948
0.999894
0.999796
0.999626
0.99934
0.998883
0.998192
0.997191
0.995808
0.993984
0.991691
0.988945
0.985821
0.982464
0.979085
0.975951
0.973344
0.971527
0.970696
0.970942
0.972243
0.974463
0.97737
0.980684
0.984114
0.987403
0.99036
0.992874
0.994906
0.996476
0.997638
0.998465
0.999032
0.999408
0.999649
0.999798
0.999887
0.999939
0.999968
0.999983
0.999991
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999994
0.999985
0.999966
0.99993
0.999858
0.999728
0.999497
0.999112
0.998498
0.997566
0.996215
0.994349
0.991888
0.988793
0.985088
0.980878
0.97636
0.971823
0.967626
0.964149
0.961736
0.960643
0.960987
0.962734
0.965704
0.969599
0.974042
0.978648
0.98307
0.987051
0.990434
0.993168
0.995277
0.996837
0.997947
0.998707
0.99921
0.999531
0.99973
0.999849
0.999918
0.999957
0.999978
0.999989
0.999994
0.999997
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999996
0.999992
0.99998
0.999956
0.999908
0.999814
0.999641
0.999338
0.99883
0.998019
0.996785
0.994997
0.992526
0.989269
0.985177
0.980284
0.974732
0.968788
0.96284
0.957359
0.95284
0.94972
0.948318
0.948781
0.951064
0.954939
0.960024
0.965841
0.971885
0.977701
0.982945
0.987406
0.991012
0.993792
0.995847
0.997306
0.998305
0.998965
0.999387
0.999647
0.999803
0.999893
0.999944
0.999971
0.999985
0.999993
0.999997
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999998
0.999996
0.99999
0.999975
0.999944
0.999882
0.999761
0.999538
0.999147
0.998488
0.997437
0.995837
0.993515
0.990308
0.986084
0.980785
0.97446
0.967303
0.959668
0.95206
0.945084
0.939358
0.935427
0.933673
0.934274
0.937172
0.942091
0.948563
0.955992
0.963739
0.97122
0.97798
0.983741
0.988401
0.991994
0.994649
0.996532
0.997819
0.99867
0.999212
0.999547
0.999747
0.999863
0.999928
0.999963
0.999982
0.999991
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999995
0.999987
0.999968
0.999929
0.99985
0.999698
0.999417
0.998921
0.998085
0.996749
0.994713
0.991758
0.98768
0.982315
0.975599
0.967605
0.958592
0.94902
0.939532
0.930876
0.923808
0.918975
0.916827
0.917571
0.921145
0.927222
0.935249
0.944504
0.954202
0.963605
0.972132
0.979419
0.98532
0.989873
0.993234
0.995619
0.997248
0.998322
0.999007
0.999429
0.999681
0.999828
0.999909
0.999954
0.999977
0.999989
0.999995
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
1
1
0.999999
0.999997
0.999994
0.999983
0.99996
0.999914
0.999816
0.999627
0.999278
0.998662
0.997624
0.995959
0.993419
0.989737
0.984655
0.977984
0.969656
0.959781
0.948697
0.936988
0.925447
0.914979
0.906471
0.900671
0.898094
0.898977
0.903254
0.910561
0.920262
0.931511
0.943364
0.954917
0.965439
0.974459
0.981779
0.987434
0.99161
0.994571
0.996592
0.997924
0.998772
0.999295
0.999607
0.999787
0.999888
0.999943
0.999972
0.999986
0.999993
0.999997
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999992
0.99998
0.999953
0.999895
0.999777
0.999548
0.999125
0.998375
0.99711
0.995078
0.991976
0.987477
0.981279
0.973162
0.963063
0.951141
0.93783
0.923851
0.910158
0.897807
0.887813
0.881014
0.877983
0.878986
0.883963
0.892519
0.903951
0.917292
0.931439
0.94531
0.958006
0.968932
0.977825
0.984706
0.989793
0.993399
0.99586
0.997479
0.99851
0.999145
0.999523
0.999742
0.999865
0.999931
0.999966
0.999983
0.999992
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999996
0.99999
0.999976
0.999944
0.999875
0.999735
0.999464
0.998961
0.998068
0.996558
0.994128
0.990416
0.985034
0.977633
0.967969
0.955994
0.941925
0.926309
0.910014
0.894152
0.879925
0.868458
0.860667
0.857172
0.858269
0.863908
0.873682
0.886827
0.902278
0.918771
0.935044
0.950021
0.96297
0.973546
0.981748
0.98782
0.992127
0.995065
0.996998
0.998227
0.998983
0.999434
0.999693
0.999839
0.999918
0.999959
0.99998
0.999991
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999996
0.999989
0.999972
0.999934
0.999854
0.999693
0.999377
0.998792
0.99775
0.995986
0.993142
0.988792
0.982489
0.973836
0.962576
0.948683
0.932451
0.914544
0.89598
0.878021
0.862001
0.849137
0.840403
0.836456
0.837619
0.843859
0.854765
0.86954
0.887026
0.905819
0.924479
0.941755
0.956764
0.969073
0.978648
0.985748
0.99079
0.99423
0.996493
0.99793
0.998813
0.99934
0.999643
0.999812
0.999904
0.999953
0.999977
0.999989
0.999995
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999998
0.999994
0.999987
0.999968
0.999926
0.999834
0.99965
0.999292
0.998624
0.997436
0.995418
0.992158
0.987167
0.979941
0.970038
0.957194
0.941421
0.923094
0.903002
0.882308
0.862411
0.844753
0.830622
0.821034
0.816672
0.817878
0.824639
0.836557
0.852813
0.87218
0.89313
0.914061
0.933548
0.950564
0.964579
0.975519
0.983652
0.989435
0.993383
0.99598
0.997628
0.998641
0.999245
0.999592
0.999786
0.999891
0.999946
0.999974
0.999987
0.999994
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999995
0.999985
0.999964
0.999917
0.999816
0.99961
0.999211
0.998467
0.99714
0.99488
0.991224
0.98562
0.977506
0.966408
0.952063
0.934523
0.914255
0.892173
0.869569
0.847963
0.828879
0.813657
0.803337
0.798614
0.799846
0.807043
0.819826
0.837372
0.858403
0.881285
0.90427
0.92578
0.944655
0.960268
0.972502
0.981622
0.98812
0.99256
0.995481
0.997336
0.998475
0.999152
0.999542
0.99976
0.999878
0.99994
0.999971
0.999986
0.999993
0.999997
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999994
0.999984
0.999961
0.999909
0.999798
0.999575
0.999139
0.998327
0.996878
0.994404
0.990391
0.984231
0.975312
0.963129
0.947426
0.92831
0.906336
0.88253
0.858304
0.835269
0.815011
0.798903
0.787989
0.782972
0.784221
0.791769
0.80526
0.823879
0.846312
0.870837
0.895584
0.918841
0.939336
0.956358
0.969746
0.979758
0.986906
0.991799
0.995021
0.997066
0.998321
0.999067
0.999496
0.999736
0.999866
0.999934
0.999968
0.999985
0.999993
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999994
0.999982
0.999958
0.999902
0.999784
0.999545
0.999081
0.998214
0.996664
0.994015
0.989707
0.983083
0.97348
0.960376
0.943524
0.923086
0.899703
0.8745
0.848982
0.824832
0.803675
0.786892
0.775533
0.770295
0.771555
0.779369
0.79341
0.812878
0.836428
0.862268
0.888425
0.913085
0.934888
0.95306
0.967401
0.97816
0.985862
0.991142
0.994622
0.996832
0.998188
0.998994
0.999457
0.999716
0.999855
0.999928
0.999965
0.999984
0.999993
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999993
0.999982
0.999956
0.999897
0.999774
0.999524
0.999039
0.998133
0.996513
0.993738
0.989215
0.982242
0.97212
0.958304
0.940567
0.919117
0.894669
0.868436
0.841988
0.817052
0.795273
0.778032
0.766369
0.760978
0.762246
0.770246
0.784686
0.804773
0.829145
0.855949
0.883131
0.908804
0.931551
0.95056
0.965605
0.976923
0.985046
0.990625
0.994307
0.996647
0.998083
0.998936
0.999427
0.9997
0.999847
0.999925
0.999964
0.999983
0.999993
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
0.999999
0.999997
0.999992
0.999981
0.999954
0.999895
0.999768
0.999512
0.999016
0.998089
0.996432
0.993591
0.988946
0.981765
0.971317
0.957041
0.938721
0.916608
0.89148
0.864604
0.837599
0.812211
0.790083
0.772589
0.76076
0.755284
0.756553
0.764666
0.779353
0.799836
0.824729
0.852131
0.879934
0.906203
0.9295
0.948996
0.964459
0.976121
0.98451
0.990283
0.994097
0.996523
0.998013
0.998897
0.999406
0.999689
0.999842
0.999922
0.999963
0.999983
0.999992
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999993
0.999981
0.999954
0.999894
0.999767
0.99951
0.999013
0.998085
0.996427
0.993581
0.988918
0.981685
0.971126
0.956667
0.938098
0.915701
0.890293
0.863178
0.835992
0.810476
0.788267
0.770719
0.758853
0.753354
0.754623
0.762775
0.777564
0.798217
0.823328
0.850956
0.87896
0.905398
0.928832
0.948453
0.964033
0.975803
0.984287
0.990135
0.994004
0.996468
0.997981
0.99888
0.999397
0.999685
0.99984
0.999921
0.999962
0.999982
0.999992
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999993
0.999982
0.999955
0.999895
0.999771
0.999518
0.999029
0.99812
0.996496
0.993708
0.989132
0.982007
0.971564
0.957215
0.938748
0.916456
0.891179
0.864228
0.837231
0.811912
0.789879
0.772469
0.760693
0.755234
0.756496
0.764617
0.779361
0.799959
0.824977
0.852451
0.880236
0.90641
0.929575
0.948956
0.96435
0.97599
0.984392
0.990193
0.994037
0.996486
0.997992
0.998886
0.9994
0.999686
0.999841
0.999922
0.999963
0.999983
0.999992
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999993
0.999982
0.999956
0.999899
0.999778
0.999535
0.999065
0.998191
0.996634
0.993961
0.989569
0.982709
0.972605
0.958658
0.940645
0.918853
0.894112
0.867724
0.841282
0.816472
0.794869
0.777787
0.766225
0.760867
0.762122
0.770138
0.78469
0.804996
0.829605
0.856541
0.883685
0.909174
0.931675
0.95047
0.965388
0.97667
0.98482
0.990455
0.994192
0.996576
0.998043
0.998915
0.999416
0.999695
0.999845
0.999924
0.999963
0.999983
0.999992
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999993
0.999983
0.999958
0.999904
0.99979
0.999561
0.999117
0.998295
0.996832
0.994324
0.990201
0.983742
0.974184
0.960916
0.943694
0.92278
0.898973
0.87353
0.847997
0.824003
0.803078
0.786512
0.775292
0.770099
0.771343
0.779179
0.793383
0.813155
0.837029
0.863046
0.889144
0.913547
0.935016
0.952906
0.967084
0.977802
0.985546
0.990904
0.994462
0.996733
0.998132
0.998964
0.999442
0.999708
0.999852
0.999927
0.999965
0.999984
0.999993
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999993
0.999984
0.999961
0.999911
0.999805
0.999593
0.999183
0.998425
0.997077
0.994772
0.990984
0.985038
0.976199
0.963855
0.947732
0.928047
0.905542
0.881409
0.857121
0.834239
0.814237
0.798375
0.787623
0.782654
0.783882
0.791462
0.805156
0.824145
0.846961
0.871689
0.896358
0.919312
0.939423
0.956128
0.969341
0.979318
0.986526
0.991515
0.99483
0.996949
0.998254
0.999032
0.999479
0.999728
0.999862
0.999932
0.999967
0.999985
0.999993
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999994
0.999985
0.999964
0.999919
0.999823
0.99963
0.99926
0.998573
0.997356
0.995279
0.991871
0.986516
0.978527
0.9673
0.952533
0.934381
0.91351
0.891019
0.868288
0.846797
0.827954
0.812976
0.802814
0.79813
0.799335
0.806577
0.819597
0.837557
0.859006
0.882102
0.905
0.926189
0.94467
0.959967
0.972036
0.981136
0.987705
0.992252
0.995276
0.99721
0.998403
0.999114
0.999523
0.999751
0.999874
0.999938
0.99997
0.999986
0.999994
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
0.999999
0.999998
0.999995
0.999987
0.999969
0.999928
0.999842
0.999671
0.999341
0.998733
0.997655
0.99582
0.992814
0.988094
0.981032
0.971053
0.957831
0.941454
0.922489
0.901923
0.881028
0.86118
0.843712
0.829791
0.820334
0.81599
0.817163
0.823983
0.836168
0.852869
0.872669
0.893836
0.914682
0.933858
0.950504
0.964229
0.975028
0.983155
0.989018
0.993075
0.995775
0.997503
0.99857
0.999206
0.999572
0.999777
0.999887
0.999945
0.999974
0.999988
0.999995
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999998
0.999996
0.999988
0.999972
0.999937
0.999862
0.999712
0.999425
0.998896
0.99796
0.996369
0.99377
0.989692
0.983584
0.974915
0.963348
0.948905
0.932043
0.913623
0.894786
0.876795
0.860891
0.848175
0.839526
0.835573
0.836702
0.843023
0.854228
0.869464
0.887385
0.906391
0.924978
0.941973
0.956652
0.96871
0.978169
0.985277
0.990398
0.993942
0.996301
0.997812
0.998746
0.999303
0.999625
0.999804
0.999901
0.999951
0.999977
0.999989
0.999995
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999999
0.999996
0.99999
0.999976
0.999946
0.999882
0.999754
0.999508
0.999056
0.998258
0.996906
0.994701
0.991247
0.986072
0.978706
0.968817
0.956374
0.941723
0.925585
0.908962
0.892985
0.878791
0.867402
0.859647
0.856125
0.857201
0.862958
0.873061
0.886677
0.902547
0.919243
0.935452
0.950184
0.962848
0.973213
0.981321
0.987404
0.991782
0.994812
0.996829
0.998123
0.998924
0.999402
0.999678
0.999832
0.999915
0.999958
0.99998
0.999991
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999996
0.999991
0.99998
0.999955
0.999901
0.999793
0.999587
0.999208
0.998541
0.997413
0.995576
0.992705
0.988408
0.982281
0.974018
0.963545
0.951111
0.937301
0.922962
0.909087
0.896693
0.886714
0.879912
0.876852
0.877868
0.883011
0.891929
0.903824
0.917556
0.931881
0.945688
0.958168
0.968848
0.97756
0.98436
0.989451
0.993116
0.995651
0.997339
0.998424
0.999095
0.999497
0.999729
0.999858
0.999928
0.999965
0.999983
0.999993
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999997
0.999993
0.999983
0.999963
0.999918
0.999829
0.99966
0.999349
0.998802
0.997877
0.996375
0.994034
0.990534
0.98554
0.978785
0.970172
0.959869
0.948331
0.936256
0.92449
0.913924
0.905386
0.89957
0.896987
0.897938
0.902437
0.910127
0.920269
0.93186
0.943849
0.955327
0.965649
0.974448
0.981605
0.987182
0.991354
0.994354
0.99643
0.997814
0.998704
0.999255
0.999585
0.999776
0.999883
0.999941
0.999971
0.999986
0.999994
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999994
0.999987
0.99997
0.999934
0.999862
0.999726
0.999475
0.999034
0.998291
0.997086
0.995211
0.992413
0.988423
0.983015
0.976089
0.967752
0.958344
0.948427
0.938698
0.929915
0.922799
0.91796
0.915854
0.916734
0.920582
0.927048
0.935471
0.945001
0.954779
0.964085
0.972417
0.979497
0.985245
0.989718
0.993061
0.995466
0.997131
0.998242
0.998956
0.9994
0.999665
0.999819
0.999906
0.999953
0.999977
0.999989
0.999995
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
1
1
1
0.999998
0.999996
0.99999
0.999976
0.999947
0.999891
0.999783
0.999585
0.999237
0.99865
0.997701
0.996227
0.994032
0.990905
0.986664
0.981216
0.974624
0.96714
0.959196
0.951358
0.944251
0.938483
0.934576
0.932922
0.933722
0.936932
0.942223
0.949027
0.956653
0.96442
0.971775
0.978338
0.983903
0.988415
0.991924
0.994546
0.996434
0.997741
0.998614
0.999177
0.999527
0.999736
0.999857
0.999926
0.999963
0.999982
0.999991
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999997
0.999992
0.999981
0.999959
0.999916
0.999832
0.999678
0.999408
0.998955
0.99822
0.997084
0.995395
0.992989
0.989729
0.985534
0.98044
0.974629
0.968427
0.962277
0.956684
0.952143
0.949089
0.94784
0.948548
0.951152
0.955357
0.960698
0.966632
0.972641
0.978309
0.983356
0.98763
0.991094
0.993787
0.995802
0.997252
0.998258
0.99893
0.999364
0.999633
0.999796
0.99989
0.999943
0.999971
0.999986
0.999993
0.999997
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999997
0.999994
0.999986
0.999969
0.999936
0.999872
0.999755
0.99955
0.999206
0.99865
0.997789
0.996513
0.9947
0.992242
0.98908
0.985231
0.980825
0.976105
0.971409
0.967129
0.963661
0.961349
0.960443
0.961047
0.963093
0.966335
0.970407
0.974899
0.979429
0.983692
0.987482
0.990692
0.993294
0.995318
0.996833
0.997926
0.998684
0.999191
0.999519
0.999722
0.999845
0.999917
0.999956
0.999978
0.999989
0.999995
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
1
0.999999
0.999998
0.999995
0.999989
0.999977
0.999952
0.999905
0.999817
0.999665
0.999409
0.998995
0.998357
0.997411
0.996071
0.994256
0.991921
0.989076
0.985816
0.982313
0.978822
0.975639
0.973066
0.971371
0.970734
0.971229
0.972785
0.975207
0.978224
0.981536
0.984865
0.987996
0.990779
0.993138
0.995051
0.996543
0.99766
0.998465
0.999025
0.9994
0.999643
0.999794
0.999885
0.999938
0.999968
0.999983
0.999992
0.999996
0.999998
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999998
0.999997
0.999992
0.999983
0.999965
0.99993
0.999867
0.999755
0.999568
0.999267
0.998803
0.998115
0.997143
0.99583
0.994142
0.992087
0.989728
0.987194
0.984666
0.982364
0.98051
0.979302
0.978868
0.979252
0.980394
0.982152
0.984326
0.986706
0.989096
0.991344
0.993345
0.995042
0.996422
0.997498
0.998304
0.998887
0.999293
0.999565
0.999741
0.99985
0.999917
0.999955
0.999976
0.999988
0.999994
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
1
0.999999
0.999997
0.999995
0.999988
0.999975
0.99995
0.999905
0.999825
0.999691
0.999476
0.999145
0.998656
0.997965
0.997034
0.995838
0.994386
0.992719
0.99093
0.989146
0.987524
0.986224
0.985383
0.985093
0.985376
0.986189
0.987426
0.988954
0.990624
0.992302
0.993882
0.99529
0.996488
0.997462
0.998224
0.998796
0.999209
0.999497
0.99969
0.999815
0.999893
0.999941
0.999968
0.999984
0.999992
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999997
0.999992
0.999982
0.999966
0.999933
0.999877
0.999784
0.999634
0.999402
0.99906
0.99858
0.997932
0.997104
0.9961
0.994948
0.993713
0.992484
0.99137
0.990479
0.989908
0.989715
0.989915
0.990474
0.991324
0.992372
0.993518
0.994672
0.99576
0.996732
0.997561
0.998236
0.998764
0.999162
0.999449
0.999649
0.999784
0.999871
0.999926
0.999959
0.999978
0.999988
0.999994
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999997
0.999994
0.999988
0.999976
0.999954
0.999916
0.999851
0.999749
0.99959
0.999357
0.999029
0.998588
0.998026
0.997345
0.996567
0.995734
0.994907
0.994159
0.993562
0.99318
0.993052
0.993187
0.993563
0.994132
0.994835
0.995605
0.996382
0.997119
0.997776
0.998338
0.998797
0.999157
0.999428
0.999624
0.999761
0.999853
0.999912
0.999949
0.999972
0.999985
0.999992
0.999996
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
0.999999
0.999999
0.999998
0.999996
0.999992
0.999984
0.999969
0.999944
0.999901
0.999831
0.999726
0.999569
0.99935
0.999056
0.998682
0.998231
0.997716
0.997166
0.996621
0.996128
0.995736
0.995486
0.995401
0.995488
0.995733
0.996107
0.99657
0.997078
0.997591
0.998078
0.998516
0.99889
0.999196
0.999436
0.999617
0.999748
0.99984
0.999901
0.999941
0.999966
0.999981
0.99999
0.999995
0.999998
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999994
0.99999
0.99998
0.999963
0.999935
0.999889
0.99982
0.999717
0.999575
0.999382
0.999139
0.998845
0.998511
0.998155
0.997803
0.997485
0.997233
0.997071
0.997015
0.99707
0.997227
0.997467
0.997764
0.998093
0.998427
0.998743
0.999028
0.999273
0.999473
0.999631
0.999748
0.999835
0.999895
0.999935
0.999961
0.999978
0.999988
0.999993
0.999997
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999998
0.999997
0.999994
0.999987
0.999976
0.999958
0.999929
0.999884
0.999819
0.999727
0.999604
0.999449
0.999262
0.999049
0.998824
0.998601
0.998399
0.998238
0.998135
0.9981
0.998134
0.998231
0.998382
0.998571
0.998779
0.998991
0.999194
0.999376
0.999533
0.999662
0.999763
0.999838
0.999894
0.999933
0.999958
0.999975
0.999986
0.999992
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999995
0.999992
0.999985
0.999974
0.999956
0.999927
0.999887
0.999828
0.999752
0.999654
0.999538
0.999406
0.999266
0.999126
0.999001
0.998901
0.998836
0.998813
0.998834
0.998894
0.998987
0.999104
0.999234
0.999367
0.999493
0.999608
0.999706
0.999786
0.99985
0.999899
0.999933
0.999957
0.999974
0.999984
0.999991
0.999995
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
0.999999
0.999999
0.999998
0.999995
0.999991
0.999984
0.999973
0.999955
0.99993
0.999895
0.999848
0.999788
0.999716
0.999636
0.99955
0.999466
0.999388
0.999328
0.999288
0.999273
0.999285
0.999321
0.999378
0.999449
0.999529
0.99961
0.999688
0.999758
0.999819
0.999868
0.999908
0.999937
0.999959
0.999974
0.999984
0.999991
0.999995
0.999997
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999998
0.999997
0.999995
0.99999
0.999984
0.999974
0.999957
0.999937
0.999909
0.999873
0.99983
0.999782
0.99973
0.999679
0.999634
0.999597
0.999573
0.999564
0.99957
0.999592
0.999626
0.999668
0.999716
0.999765
0.999812
0.999854
0.999891
0.99992
0.999944
0.999962
0.999975
0.999984
0.99999
0.999994
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999999
0.999998
0.999994
0.99999
0.999984
0.999975
0.999963
0.999946
0.999925
0.999901
0.999871
0.999842
0.999812
0.999784
0.999763
0.99975
0.999744
0.999747
0.999759
0.99978
0.999804
0.999832
0.999861
0.999888
0.999914
0.999935
0.999952
0.999966
0.999978
0.999985
0.99999
0.999994
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
1
0.999999
0.999998
0.999997
0.999994
0.999991
0.999986
0.999979
0.999969
0.999957
0.999943
0.999927
0.999909
0.999892
0.999876
0.999863
0.999856
0.999852
0.999854
0.999861
0.999872
0.999886
0.999903
0.99992
0.999935
0.99995
0.999963
0.999973
0.999981
0.999987
0.999992
0.999994
0.999996
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
0.999999
1
0.999999
0.999999
0.999998
0.999997
0.999995
0.999992
0.999988
0.999982
0.999976
0.999968
0.999959
0.999949
0.999939
0.999931
0.999923
0.999918
0.999917
0.999918
0.999921
0.999927
0.999936
0.999945
0.999954
0.999964
0.999971
0.999978
0.999984
0.999989
0.999992
0.999995
0.999997
0.999998
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999999
0.999997
0.999995
0.999994
0.999991
0.999987
0.999983
0.999977
0.999972
0.999967
0.999962
0.999958
0.999955
0.999953
0.999955
0.999956
0.999959
0.999964
0.999969
0.999974
0.999979
0.999984
0.999988
0.999991
0.999994
0.999996
0.999997
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
1
1
1
0.999999
0.999998
0.999997
0.999997
0.999996
0.999994
0.99999
0.999988
0.999985
0.999982
0.999979
0.999978
0.999975
0.999975
0.999976
0.999977
0.999978
0.99998
0.999983
0.999986
0.999989
0.999992
0.999993
0.999995
0.999997
0.999997
0.999998
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
1
0.999999
0.999999
0.999999
0.999998
0.999997
0.999997
0.999995
0.999994
0.999992
0.999991
0.999989
0.999987
0.999988
0.999986
0.999986
0.999987
0.999988
0.99999
0.999991
0.999993
0.999994
0.999995
0.999997
0.999998
0.999998
0.999998
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999998
0.999998
0.999997
0.999996
0.999995
0.999994
0.999994
0.999993
0.999993
0.999993
0.999993
0.999994
0.999994
0.999995
0.999996
0.999997
0.999997
0.999998
0.999999
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999999
0.999999
0.999998
0.999997
0.999998
0.999997
0.999997
0.999996
0.999996
0.999997
0.999997
0.999997
0.999997
0.999998
0.999998
0.999999
0.999999
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
1
0.999999
1
0.999999
0.999999
1
0.999999
0.999999
0.999999
0.999998
0.999998
0.999999
0.999998
0.999999
0.999999
0.999999
0.999999
1
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
0.999999
0.999999
0.999999
0.999999
0.999999
1
1
0.999999
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.999999
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
)
;
boundaryField
{
emptyPatches_empt
{
type empty;
}
top_cyc
{
type cyclic;
}
bottom_cyc
{
type cyclic;
}
inlet_cyc
{
type cyclic;
}
outlet_cyc
{
type cyclic;
}
}
// ************************************************************************* //
| [
"tdg@debian"
] | tdg@debian | |
77355761b12bd4f181da9ebef5ef2a601317141b | ad3cd7b86529daa21ccf068045bf769c6fc96132 | /NewTrainingFramework/HelperFunctions.h | a5f237c68c39dcf16e786db5d10dbc921f8f3c59 | [] | no_license | JamShan/Game-Engine | 0dc9ed58d5e9da18054be8e1aacabf0d166bc7f1 | 56af6debba97b2607c0a1675c08f5966ea30406a | refs/heads/master | 2020-03-17T11:04:56.547181 | 2017-04-09T21:55:01 | 2017-04-09T21:55:01 | 133,537,465 | 3 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 464 | h | #pragma once
#include <string>
#include <memory>
#include <vector>
#include <fstream>
#include <sstream>
#include <GLES2\gl2.h>
#include "Vertex.h"
#include "../Utilities/Math.h"
#include "../Utilities/utilities.h"
namespace helperfunctions
{
// helper function for parsing
template< typename T >
T stringToNumber(const std::string s) // string to number conversion
{
std::stringstream ss;
ss << s;
T nr;
ss >> nr;
return nr;
}
}// namespace | [
"mihaiandrei95.tanase@gmail.com"
] | mihaiandrei95.tanase@gmail.com |
522e41e7f1531069746beefb2377317688021707 | 83b8a9e0ba13a792f44fca455ba01043b9a81c78 | /BOJ_Implement/BOJ_Implement/BOJ_5565.cpp | 94b4cf1602b10ff85e2358aaa4cf8b59e86520b5 | [] | no_license | BoGyuPark/VS_BOJ | 0799a0c62fd72a6fc1e6f7e34fc539a742c0782b | 965973600dedbd5f3032c3adb4b117cc43c62a8f | refs/heads/master | 2020-04-14T12:45:53.930735 | 2019-12-04T03:06:44 | 2019-12-04T03:06:44 | 163,849,994 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 160 | cpp | #include<iostream>
using namespace std;
int main() {
int sum = 0, f,t;
cin >> f;
for (int i = 0; i < 9; i++) {
cin >> t;
sum += t;
}
cout << f - sum;
} | [
"shaing123@naver.com"
] | shaing123@naver.com |
02eba2f464c6c54d1f04449719cbc7bdd74f9365 | 631fbe796f6d1b21a09cfc6ffd7694084dda63ca | /src/Layers/xrRender/HW.cpp | 3cdc3136522574635c3bd8020f350e715a66a90a | [] | no_license | NikitaNikson/X-Ray_1.6_Sources_VS2019 | 93c4bbe3fd4f100928165e5b28397f1f62c3d635 | 74c5a6b785ba6a9cd8ca1b53e44182f664fc15c4 | refs/heads/main | 2023-07-01T06:02:42.433190 | 2021-08-10T10:14:32 | 2021-08-10T10:14:32 | 394,604,416 | 1 | 0 | null | 2021-08-10T09:59:37 | 2021-08-10T09:59:36 | null | UTF-8 | C++ | false | false | 20,008 | cpp | // HW.cpp: implementation of the CHW class.
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#pragma hdrstop
#pragma warning(disable:4995)
#include <d3dx9.h>
#pragma warning(default:4995)
#include "HW.h"
#include "../../xrEngine/XR_IOConsole.h"
#ifndef _EDITOR
void fill_vid_mode_list (CHW* _hw);
void free_vid_mode_list ();
void fill_render_mode_list ();
void free_render_mode_list ();
#else
void fill_vid_mode_list (CHW* _hw) {}
void free_vid_mode_list () {}
void fill_render_mode_list () {}
void free_render_mode_list () {}
#endif
CHW HW;
#ifdef DEBUG
IDirect3DStateBlock9* dwDebugSB = 0;
#endif
CHW::CHW() :
hD3D(NULL),
pD3D(NULL),
pDevice(NULL),
pBaseRT(NULL),
pBaseZB(NULL),
m_move_window(true)
{
;
}
CHW::~CHW()
{
;
}
void CHW::Reset (HWND hwnd)
{
#ifdef DEBUG
_RELEASE (dwDebugSB);
#endif
_RELEASE (pBaseZB);
_RELEASE (pBaseRT);
#ifndef _EDITOR
//#ifndef DEDICATED_SERVER
// BOOL bWindowed = !psDeviceFlags.is (rsFullscreen);
//#else
// BOOL bWindowed = TRUE;
//#endif
BOOL bWindowed = TRUE;
if (!g_dedicated_server)
bWindowed = !psDeviceFlags.is (rsFullscreen);
selectResolution (DevPP.BackBufferWidth, DevPP.BackBufferHeight, bWindowed);
// Windoze
DevPP.SwapEffect = bWindowed?D3DSWAPEFFECT_COPY:D3DSWAPEFFECT_DISCARD;
DevPP.Windowed = bWindowed;
DevPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
if( !bWindowed ) DevPP.FullScreen_RefreshRateInHz = selectRefresh (DevPP.BackBufferWidth,DevPP.BackBufferHeight,Caps.fTarget);
else DevPP.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
#endif
while (TRUE) {
HRESULT _hr = HW.pDevice->Reset (&DevPP);
if (SUCCEEDED(_hr)) break;
Msg ("! ERROR: [%dx%d]: %s",DevPP.BackBufferWidth,DevPP.BackBufferHeight,Debug.error2string(_hr));
Sleep (100);
}
R_CHK (pDevice->GetRenderTarget (0,&pBaseRT));
R_CHK (pDevice->GetDepthStencilSurface (&pBaseZB));
#ifdef DEBUG
R_CHK (pDevice->CreateStateBlock (D3DSBT_ALL,&dwDebugSB));
#endif
#ifndef _EDITOR
updateWindowProps (hwnd);
#endif
}
//xr_token* vid_mode_token = NULL;
//extern xr_token* vid_mode_token;
#include "../../Include/xrAPI/xrAPI.h"
//xr_token* vid_quality_token = NULL;
void CHW::CreateD3D ()
{
//#ifndef DEDICATED_SERVER
// LPCSTR _name = "d3d9.dll";
//#else
// LPCSTR _name = "xrd3d9-null.dll";
//#endif
LPCSTR _name = "xrd3d9-null.dll";
#ifndef _EDITOR
if (!g_dedicated_server)
#endif
_name = "d3d9.dll";
hD3D = LoadLibrary(_name);
R_ASSERT2 (hD3D,"Can't find 'd3d9.dll'\nPlease install latest version of DirectX before running this program");
typedef IDirect3D9 * WINAPI _Direct3DCreate9(UINT SDKVersion);
_Direct3DCreate9* createD3D = (_Direct3DCreate9*)GetProcAddress(hD3D,"Direct3DCreate9"); R_ASSERT(createD3D);
this->pD3D = createD3D( D3D_SDK_VERSION );
R_ASSERT2 (this->pD3D,"Please install DirectX 9.0c");
}
void CHW::DestroyD3D()
{
_RELEASE (this->pD3D);
FreeLibrary (hD3D);
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
D3DFORMAT CHW::selectDepthStencil (D3DFORMAT fTarget)
{
// R2 hack
#pragma todo("R2 need to specify depth format")
if (psDeviceFlags.test(rsR2)) return D3DFMT_D24S8;
// R1 usual
static D3DFORMAT fDS_Try1[6] =
{D3DFMT_D24S8,D3DFMT_D24X4S4,D3DFMT_D32,D3DFMT_D24X8,D3DFMT_D16,D3DFMT_D15S1};
D3DFORMAT* fDS_Try = fDS_Try1;
int fDS_Cnt = 6;
for (int it = 0; it<fDS_Cnt; it++){
if (SUCCEEDED(pD3D->CheckDeviceFormat(
DevAdapter,DevT,fTarget,
D3DUSAGE_DEPTHSTENCIL,D3DRTYPE_SURFACE,fDS_Try[it])))
{
if( SUCCEEDED( pD3D->CheckDepthStencilMatch(
DevAdapter,DevT,
fTarget, fTarget, fDS_Try[it]) ) )
{
return fDS_Try[it];
}
}
}
return D3DFMT_UNKNOWN;
}
void CHW::DestroyDevice ()
{
_SHOW_REF ("refCount:pBaseZB",pBaseZB);
_RELEASE (pBaseZB);
_SHOW_REF ("refCount:pBaseRT",pBaseRT);
_RELEASE (pBaseRT);
#ifdef DEBUG
_SHOW_REF ("refCount:dwDebugSB",dwDebugSB);
_RELEASE (dwDebugSB);
#endif
#ifdef _EDITOR
_RELEASE (HW.pDevice);
#else
_SHOW_REF ("DeviceREF:",HW.pDevice);
_RELEASE (HW.pDevice);
#endif
DestroyD3D ();
#ifndef _EDITOR
free_vid_mode_list ();
#endif
}
void CHW::selectResolution (u32 &dwWidth, u32 &dwHeight, BOOL bWindowed)
{
fill_vid_mode_list (this);
#ifndef _EDITOR
if (g_dedicated_server)
{
dwWidth = 640;
dwHeight = 480;
}
else
#endif
{
if(bWindowed)
{
dwWidth = psCurrentVidMode[0];
dwHeight = psCurrentVidMode[1];
}else //check
{
#ifndef _EDITOR
string64 buff;
xr_sprintf (buff,sizeof(buff),"%dx%d",psCurrentVidMode[0],psCurrentVidMode[1]);
if(_ParseItem(buff,vid_mode_token)==u32(-1)) //not found
{ //select safe
xr_sprintf (buff,sizeof(buff),"vid_mode %s",vid_mode_token[0].name);
Console->Execute (buff);
}
dwWidth = psCurrentVidMode[0];
dwHeight = psCurrentVidMode[1];
#endif
}
}
//#endif
}
void CHW::CreateDevice (HWND m_hWnd, bool move_window)
{
m_move_window = move_window;
CreateD3D ();
// General - select adapter and device
//#ifdef DEDICATED_SERVER
// BOOL bWindowed = TRUE;
//#else
// BOOL bWindowed = !psDeviceFlags.is(rsFullscreen);
//#endif
BOOL bWindowed = TRUE;
#ifndef _EDITOR
if (!g_dedicated_server)
bWindowed = !psDeviceFlags.is(rsFullscreen);
#else
bWindowed = 1;
#endif
DevAdapter = D3DADAPTER_DEFAULT;
DevT = Caps.bForceGPU_REF?D3DDEVTYPE_REF:D3DDEVTYPE_HAL;
#ifndef MASTER_GOLD
// Look for 'NVIDIA NVPerfHUD' adapter
// If it is present, override default settings
for (UINT Adapter=0;Adapter<pD3D->GetAdapterCount();Adapter++) {
D3DADAPTER_IDENTIFIER9 Identifier;
HRESULT Res=pD3D->GetAdapterIdentifier(Adapter,0,&Identifier);
if (SUCCEEDED(Res) && (xr_strcmp(Identifier.Description,"NVIDIA PerfHUD")==0))
{
DevAdapter =Adapter;
DevT =D3DDEVTYPE_REF;
break;
}
}
#endif // MASTER_GOLD
// Display the name of video board
D3DADAPTER_IDENTIFIER9 adapterID;
R_CHK (pD3D->GetAdapterIdentifier(DevAdapter,0,&adapterID));
Msg ("* GPU [vendor:%X]-[device:%X]: %s",adapterID.VendorId,adapterID.DeviceId,adapterID.Description);
u16 drv_Product = HIWORD(adapterID.DriverVersion.HighPart);
u16 drv_Version = LOWORD(adapterID.DriverVersion.HighPart);
u16 drv_SubVersion = HIWORD(adapterID.DriverVersion.LowPart);
u16 drv_Build = LOWORD(adapterID.DriverVersion.LowPart);
Msg ("* GPU driver: %d.%d.%d.%d",u32(drv_Product),u32(drv_Version),u32(drv_SubVersion), u32(drv_Build));
Caps.id_vendor = adapterID.VendorId;
Caps.id_device = adapterID.DeviceId;
// Retreive windowed mode
D3DDISPLAYMODE mWindowed;
R_CHK(pD3D->GetAdapterDisplayMode(DevAdapter, &mWindowed));
// Select back-buffer & depth-stencil format
D3DFORMAT& fTarget = Caps.fTarget;
D3DFORMAT& fDepth = Caps.fDepth;
if (bWindowed)
{
fTarget = mWindowed.Format;
R_CHK(pD3D->CheckDeviceType (DevAdapter,DevT,fTarget,fTarget,TRUE));
fDepth = selectDepthStencil(fTarget);
} else {
switch (psCurrentBPP) {
case 32:
fTarget = D3DFMT_X8R8G8B8;
if (SUCCEEDED(pD3D->CheckDeviceType(DevAdapter,DevT,fTarget,fTarget,FALSE)))
break;
fTarget = D3DFMT_A8R8G8B8;
if (SUCCEEDED(pD3D->CheckDeviceType(DevAdapter,DevT,fTarget,fTarget,FALSE)))
break;
fTarget = D3DFMT_R8G8B8;
if (SUCCEEDED(pD3D->CheckDeviceType(DevAdapter,DevT,fTarget,fTarget,FALSE)))
break;
fTarget = D3DFMT_UNKNOWN;
break;
case 16:
default:
fTarget = D3DFMT_R5G6B5;
if (SUCCEEDED(pD3D->CheckDeviceType(DevAdapter,DevT,fTarget,fTarget,FALSE)))
break;
fTarget = D3DFMT_X1R5G5B5;
if (SUCCEEDED(pD3D->CheckDeviceType(DevAdapter,DevT,fTarget,fTarget,FALSE)))
break;
fTarget = D3DFMT_X4R4G4B4;
if (SUCCEEDED(pD3D->CheckDeviceType(DevAdapter,DevT,fTarget,fTarget,FALSE)))
break;
fTarget = D3DFMT_UNKNOWN;
break;
}
fDepth = selectDepthStencil(fTarget);
}
if ((D3DFMT_UNKNOWN==fTarget) || (D3DFMT_UNKNOWN==fTarget)) {
Msg ("Failed to initialize graphics hardware.\n"
"Please try to restart the game.\n"
"Can not find matching format for back buffer."
);
FlushLog ();
MessageBox (NULL,"Failed to initialize graphics hardware.\nPlease try to restart the game.","Error!",MB_OK|MB_ICONERROR);
TerminateProcess (GetCurrentProcess(),0);
}
// Set up the presentation parameters
D3DPRESENT_PARAMETERS& P = DevPP;
ZeroMemory ( &P, sizeof(P) );
#ifndef _EDITOR
selectResolution (P.BackBufferWidth, P.BackBufferHeight, bWindowed);
#endif
// Back buffer
//. P.BackBufferWidth = dwWidth;
//. P.BackBufferHeight = dwHeight;
P.BackBufferFormat = fTarget;
P.BackBufferCount = 1;
// Multisample
P.MultiSampleType = D3DMULTISAMPLE_NONE;
P.MultiSampleQuality = 0;
// Windoze
P.SwapEffect = bWindowed?D3DSWAPEFFECT_COPY:D3DSWAPEFFECT_DISCARD;
P.hDeviceWindow = m_hWnd;
P.Windowed = bWindowed;
// Depth/stencil
P.EnableAutoDepthStencil= TRUE;
P.AutoDepthStencilFormat= fDepth;
P.Flags = 0; //. D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
// Refresh rate
P.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
if( !bWindowed ) P.FullScreen_RefreshRateInHz = selectRefresh (P.BackBufferWidth, P.BackBufferHeight,fTarget);
else P.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
// Create the device
u32 GPU = selectGPU();
HRESULT R = HW.pD3D->CreateDevice(DevAdapter,
DevT,
m_hWnd,
GPU | D3DCREATE_MULTITHREADED, //. ? locks at present
&P,
&pDevice );
if (FAILED(R)) {
R = HW.pD3D->CreateDevice( DevAdapter,
DevT,
m_hWnd,
GPU | D3DCREATE_MULTITHREADED, //. ? locks at present
&P,
&pDevice );
}
if (D3DERR_DEVICELOST==R) {
// Fatal error! Cannot create rendering device AT STARTUP !!!
Msg ("Failed to initialize graphics hardware.\n"
"Please try to restart the game.\n"
"CreateDevice returned 0x%08x(D3DERR_DEVICELOST)", R);
FlushLog ();
MessageBox (NULL,"Failed to initialize graphics hardware.\nPlease try to restart the game.","Error!",MB_OK|MB_ICONERROR);
TerminateProcess (GetCurrentProcess(),0);
};
R_CHK (R);
_SHOW_REF ("* CREATE: DeviceREF:",HW.pDevice);
switch (GPU)
{
case D3DCREATE_SOFTWARE_VERTEXPROCESSING:
Log ("* Vertex Processor: SOFTWARE");
break;
case D3DCREATE_MIXED_VERTEXPROCESSING:
Log ("* Vertex Processor: MIXED");
break;
case D3DCREATE_HARDWARE_VERTEXPROCESSING:
Log ("* Vertex Processor: HARDWARE");
break;
case D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_PUREDEVICE:
Log ("* Vertex Processor: PURE HARDWARE");
break;
}
// Capture misc data
#ifdef DEBUG
R_CHK (pDevice->CreateStateBlock (D3DSBT_ALL,&dwDebugSB));
#endif
R_CHK (pDevice->GetRenderTarget (0,&pBaseRT));
R_CHK (pDevice->GetDepthStencilSurface (&pBaseZB));
u32 memory = pDevice->GetAvailableTextureMem ();
Msg ("* Texture memory: %d M", memory/(1024*1024));
Msg ("* DDI-level: %2.1f", float(D3DXGetDriverLevel(pDevice))/100.f);
#ifndef _EDITOR
updateWindowProps (m_hWnd);
fill_vid_mode_list (this);
#endif
}
u32 CHW::selectPresentInterval ()
{
D3DCAPS9 caps;
pD3D->GetDeviceCaps(DevAdapter,DevT,&caps);
if (!psDeviceFlags.test(rsVSync))
{
if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE)
return D3DPRESENT_INTERVAL_IMMEDIATE;
if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE)
return D3DPRESENT_INTERVAL_ONE;
}
return D3DPRESENT_INTERVAL_DEFAULT;
}
u32 CHW::selectGPU ()
{
#if RENDER == R_R1
BOOL isIntelGMA = FALSE;
if ( Caps.id_vendor == 0x8086 ) { // Intel
#define GMA_SL_SIZE 43
DWORD IntelGMA_SoftList[ GMA_SL_SIZE ] = {
0x2782,0x2582,0x2792,0x2592,0x2772,0x2776,0x27A2,0x27A6,0x27AE,
0x2982,0x2983,0x2992,0x2993,0x29A2,0x29A3,0x2972,0x2973,0x2A02,
0x2A03,0x2A12,0x2A13,0x29C2,0x29C3,0x29B2,0x29B3,0x29D2,0x29D3,
0x2A42,0x2A43,0x2E02,0x2E03,0x2E12,0x2E13,0x2E22,0x2E23,0x2E32,
0x2E33,0x2E42,0x2E43,0x2E92,0x2E93,0x0042,0x0046
};
for ( int idx = 0 ; idx < GMA_SL_SIZE ; ++idx )
if ( IntelGMA_SoftList[ idx ] == Caps.id_device ) {
isIntelGMA = TRUE;
break;
}
}
if ( isIntelGMA )
switch ( ps_r1_SoftwareSkinning ) {
case 0 :
Msg( "* Enabling software skinning" );
ps_r1_SoftwareSkinning = 1;
break;
case 1 :
Msg( "* Using software skinning" );
break;
case 2 :
Msg( "* WARNING: Using hardware skinning" );
Msg( "* setting 'r1_software_skinning' to '1' may improve performance" );
break;
} else
if ( ps_r1_SoftwareSkinning == 1 ) {
Msg( "* WARNING: Using software skinning" );
Msg( "* setting 'r1_software_skinning' to '0' should improve performance" );
}
#endif // RENDER == R_R1
if ( Caps.bForceGPU_SW )
return D3DCREATE_SOFTWARE_VERTEXPROCESSING;
D3DCAPS9 caps;
pD3D->GetDeviceCaps(DevAdapter,DevT,&caps);
if(caps.DevCaps&D3DDEVCAPS_HWTRANSFORMANDLIGHT)
{
if (Caps.bForceGPU_NonPure) return D3DCREATE_HARDWARE_VERTEXPROCESSING;
else {
if (caps.DevCaps&D3DDEVCAPS_PUREDEVICE) return D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_PUREDEVICE;
else return D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
// return D3DCREATE_MIXED_VERTEXPROCESSING;
} else return D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
u32 CHW::selectRefresh(u32 dwWidth, u32 dwHeight, D3DFORMAT fmt)
{
if (psDeviceFlags.is(rsRefresh60hz)) return D3DPRESENT_RATE_DEFAULT;
else
{
u32 selected = D3DPRESENT_RATE_DEFAULT;
u32 count = pD3D->GetAdapterModeCount(DevAdapter,fmt);
for (u32 I=0; I<count; I++)
{
D3DDISPLAYMODE Mode;
pD3D->EnumAdapterModes(DevAdapter,fmt,I,&Mode);
if (Mode.Width==dwWidth && Mode.Height==dwHeight)
{
#ifndef ECO_RENDER
if (Mode.RefreshRate>selected) selected = Mode.RefreshRate;
#else
if (Mode.RefreshRate <= (UINT)maxRefreshRate && Mode.RefreshRate>selected) selected = Mode.RefreshRate; //ECO_RENDER modif.
#endif
}
}
return selected;
}
}
BOOL CHW::support (D3DFORMAT fmt, DWORD type, DWORD usage)
{
HRESULT hr = pD3D->CheckDeviceFormat(DevAdapter,DevT,Caps.fTarget,usage,(D3DRESOURCETYPE)type,fmt);
if (FAILED(hr)) return FALSE;
else return TRUE;
}
void CHW::updateWindowProps (HWND m_hWnd)
{
// BOOL bWindowed = strstr(Core.Params,"-dedicated") ? TRUE : !psDeviceFlags.is (rsFullscreen);
//#ifndef DEDICATED_SERVER
// BOOL bWindowed = !psDeviceFlags.is (rsFullscreen);
//#else
// BOOL bWindowed = TRUE;
//#endif
BOOL bWindowed = TRUE;
#ifndef _EDITOR
if (!g_dedicated_server)
bWindowed = !psDeviceFlags.is(rsFullscreen);
#endif
u32 dwWindowStyle = 0;
// Set window properties depending on what mode were in.
if (bWindowed) {
if (m_move_window) {
if (strstr(Core.Params,"-no_dialog_header"))
SetWindowLong ( m_hWnd, GWL_STYLE, dwWindowStyle=(WS_BORDER|WS_VISIBLE) );
else
SetWindowLong ( m_hWnd, GWL_STYLE, dwWindowStyle=(WS_BORDER|WS_DLGFRAME|WS_VISIBLE|WS_SYSMENU|WS_MINIMIZEBOX ) );
// When moving from fullscreen to windowed mode, it is important to
// adjust the window size after recreating the device rather than
// beforehand to ensure that you get the window size you want. For
// example, when switching from 640x480 fullscreen to windowed with
// a 1000x600 window on a 1024x768 desktop, it is impossible to set
// the window size to 1000x600 until after the display mode has
// changed to 1024x768, because windows cannot be larger than the
// desktop.
RECT m_rcWindowBounds;
BOOL bCenter = FALSE;
if (strstr(Core.Params, "-center_screen")) bCenter = TRUE;
#ifndef _EDITOR
if (g_dedicated_server)
bCenter = TRUE;
#endif
if(bCenter){
RECT DesktopRect;
GetClientRect (GetDesktopWindow(), &DesktopRect);
SetRect( &m_rcWindowBounds,
(DesktopRect.right-DevPP.BackBufferWidth)/2,
(DesktopRect.bottom-DevPP.BackBufferHeight)/2,
(DesktopRect.right+DevPP.BackBufferWidth)/2,
(DesktopRect.bottom+DevPP.BackBufferHeight)/2 );
}else{
SetRect( &m_rcWindowBounds,
0,
0,
DevPP.BackBufferWidth,
DevPP.BackBufferHeight );
};
AdjustWindowRect ( &m_rcWindowBounds, dwWindowStyle, FALSE );
SetWindowPos ( m_hWnd,
HWND_NOTOPMOST,
m_rcWindowBounds.left,
m_rcWindowBounds.top,
( m_rcWindowBounds.right - m_rcWindowBounds.left ),
( m_rcWindowBounds.bottom - m_rcWindowBounds.top ),
SWP_SHOWWINDOW|SWP_NOCOPYBITS|SWP_DRAWFRAME );
}
}
else
{
SetWindowLong ( m_hWnd, GWL_STYLE, dwWindowStyle=(WS_POPUP|WS_VISIBLE) );
SetWindowLong ( m_hWnd, GWL_EXSTYLE, WS_EX_TOPMOST);
}
#ifndef _EDITOR
if (!g_dedicated_server)
{
ShowCursor (FALSE);
SetForegroundWindow( m_hWnd );
}
#endif
}
struct _uniq_mode
{
_uniq_mode(LPCSTR v):_val(v){}
LPCSTR _val;
bool operator() (LPCSTR _other) {return !stricmp(_val,_other);}
};
#ifndef _EDITOR
/*
void free_render_mode_list()
{
for( int i=0; vid_quality_token[i].name; i++ )
{
xr_free (vid_quality_token[i].name);
}
xr_free (vid_quality_token);
vid_quality_token = NULL;
}
*/
/*
void fill_render_mode_list()
{
if(vid_quality_token != NULL) return;
D3DCAPS9 caps;
CHW _HW;
_HW.CreateD3D ();
_HW.pD3D->GetDeviceCaps (D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&caps);
_HW.DestroyD3D ();
u16 ps_ver_major = u16 ( u32(u32(caps.PixelShaderVersion)&u32(0xf << 8ul))>>8 );
xr_vector<LPCSTR> _tmp;
u32 i = 0;
for(; i<5; ++i)
{
bool bBreakLoop = false;
switch (i)
{
case 3: //"renderer_r2.5"
if (ps_ver_major < 3)
bBreakLoop = true;
break;
case 4: //"renderer_r_dx10"
bBreakLoop = true;
break;
default: ;
}
if (bBreakLoop) break;
_tmp.push_back (NULL);
LPCSTR val = NULL;
switch (i)
{
case 0: val ="renderer_r1"; break;
case 1: val ="renderer_r2a"; break;
case 2: val ="renderer_r2"; break;
case 3: val ="renderer_r2.5"; break;
case 4: val ="renderer_r_dx10"; break; // -)
}
_tmp.back() = xr_strdup(val);
}
u32 _cnt = _tmp.size()+1;
vid_quality_token = xr_alloc<xr_token>(_cnt);
vid_quality_token[_cnt-1].id = -1;
vid_quality_token[_cnt-1].name = NULL;
#ifdef DEBUG
Msg("Available render modes[%d]:",_tmp.size());
#endif // DEBUG
for(u32 i=0; i<_tmp.size();++i)
{
vid_quality_token[i].id = i;
vid_quality_token[i].name = _tmp[i];
#ifdef DEBUG
Msg ("[%s]",_tmp[i]);
#endif // DEBUG
}
}
*/
void free_vid_mode_list()
{
for( int i=0; vid_mode_token[i].name; i++ )
{
xr_free (vid_mode_token[i].name);
}
xr_free (vid_mode_token);
vid_mode_token = NULL;
}
void fill_vid_mode_list(CHW* _hw)
{
if(vid_mode_token != NULL) return;
xr_vector<LPCSTR> _tmp;
u32 cnt = _hw->pD3D->GetAdapterModeCount (_hw->DevAdapter, _hw->Caps.fTarget);
u32 i;
for(i=0; i<cnt;++i)
{
D3DDISPLAYMODE Mode;
string32 str;
_hw->pD3D->EnumAdapterModes(_hw->DevAdapter, _hw->Caps.fTarget, i, &Mode);
if(Mode.Width < 800) continue;
xr_sprintf (str,sizeof(str),"%dx%d", Mode.Width, Mode.Height);
if(_tmp.end() != std::find_if(_tmp.begin(), _tmp.end(), _uniq_mode(str)))
continue;
_tmp.push_back (NULL);
_tmp.back() = xr_strdup(str);
}
u32 _cnt = _tmp.size()+1;
vid_mode_token = xr_alloc<xr_token>(_cnt);
vid_mode_token[_cnt-1].id = -1;
vid_mode_token[_cnt-1].name = NULL;
#ifdef DEBUG
Msg("Available video modes[%d]:",_tmp.size());
#endif // DEBUG
for(i=0; i<_tmp.size();++i)
{
vid_mode_token[i].id = i;
vid_mode_token[i].name = _tmp[i];
#ifdef DEBUG
Msg ("[%s]",_tmp[i]);
#endif // DEBUG
}
}
#endif
| [
"stepadunaevskij@gmail.com"
] | stepadunaevskij@gmail.com |
8fb58f743de8910a855df2596828d6755adf17da | a00e2f77f98badc5fd65317c9165bdd319e6c449 | /3rdparty/stout/include/stout/os/getcwd.hpp | 63ecc98326a4ba9d78eb0bcec18407c3f4a76de3 | [
"Apache-2.0"
] | permissive | HICAS-ChameLeon/Chameleon | 3c2bb65b4ef0eb0b7a6a6034e1be1d3f255b6cf4 | cd0666317eb4e92a4f9fe0b2955b46bc224cf862 | refs/heads/master | 2020-04-07T22:24:35.330187 | 2019-07-14T10:38:35 | 2019-07-14T10:38:35 | 158,769,069 | 4 | 4 | Apache-2.0 | 2019-07-14T10:38:36 | 2018-11-23T02:07:17 | JavaScript | UTF-8 | C++ | false | false | 1,232 | hpp | // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __STOUT_OS_GETCWD_HPP__
#define __STOUT_OS_GETCWD_HPP__
#include <stout/try.hpp>
#ifdef __WINDOWS__
#include <stout/windows.hpp> // To be certain we're using the right `getcwd`.
#endif // __WINDOWS__
namespace os {
inline std::string getcwd()
{
size_t size = 100;
while (true) {
char* temp = new char[size];
if (::getcwd(temp, size) == temp) {
std::string result(temp);
delete[] temp;
return result;
} else {
if (errno != ERANGE) {
delete[] temp;
return std::string();
}
size *= 2;
delete[] temp;
}
}
return std::string();
}
} // namespace os {
#endif // __STOUT_OS_GETCWD_HPP__
| [
"lilelr@163.com"
] | lilelr@163.com |
ef862cc31876c47076281de0b51711670883d97d | 5107e9eccb45fcce5def7c4ecbec3281226242db | /yeti_at_home_resolverd.cpp | 9f34c8e2e2674889fbb0397aaa0361561416983e | [] | no_license | qbolec/c | 1b2b0276497f60f5b117c1393d828b8c4dc16dc2 | 52a6144c68def40748f37e8862edde16d23a4e1d | refs/heads/master | 2020-06-08T23:07:37.339071 | 2009-09-30T07:29:00 | 2009-09-30T07:29:00 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,134 | cpp | #include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
const int T=1000000;
long double beta[T];
int main(){
double x=1.3;
double y=1.6;
while(x+0.00001<y){
const long double a=(x+y)/2;
for(int k=4;k<1000;k++){
const long double f=k/(k-a);
for(int t=0;t<k;t++){
beta[t]=(a-1)*pow(f,t+1);
// cout << "beta[" << t << "]=" << beta[t]<<endl;
}
beta[k]= f* ( (a-1) *(pow(f,k)-f ) -1 );
// cout << "beta[" << k << "]=" << beta[k]<<endl;
for(int t=k+1;t<T;t++){
beta[t]=beta[t-1]+ a*(beta[t-1]-beta[t-k])/(k-a);
// cout << "beta[" << t << "]=" << beta[t]<<endl;
if(beta[t]<0.0001){
cout << "bad " << a << " for k=" <<k << " t=" << t << " beta=" << beta[t] << endl;
goto bad_alfa;
}else if(beta[t]>1000000){
cout << "seems good" << a << " for k=" <<k << " t=" << t << " beta=" << beta[t] << endl;
// system("PAUSE");
break;
}
}
}
y=a;
cout << "good " << a << endl;
continue;
bad_alfa:
x=a;
}
cout << "x=" << x << endl;
system("PAUSE");
}
| [
"qbolec@gmail.com"
] | qbolec@gmail.com |
b7d94f11c63005fb627446312709a64129fb0fc2 | a8dead89e139e09733d559175293a5d3b2aef56c | /src/demi/gfx/GfxPrerequisites.h | 77566cb88f820a2497a5eda031cb35b28fbac496 | [
"MIT"
] | permissive | riyanhax/Demi3D | 4f3a48e6d76462a998b1b08935b37d8019815474 | 73e684168bd39b894f448779d41fab600ba9b150 | refs/heads/master | 2021-12-04T06:24:26.642316 | 2015-01-29T22:06:00 | 2015-01-29T22:06:00 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,399 | h | /**********************************************************************
This source file is a part of Demi3D
__ ___ __ __ __
| \|_ |\/|| _)| \
|__/|__| || __)|__/
Copyright (c) 2013-2014 Demi team
https://github.com/wangyanxing/Demi3D
Released under the MIT License
https://github.com/wangyanxing/Demi3D/blob/master/License.txt
***********************************************************************/
#ifndef DiGfxPrerequisites_h__
#define DiGfxPrerequisites_h__
#include "CommonEnum.h"
#include "Str.h"
namespace Demi
{
class DiLogger;
class DiArchive;
class DiFileArchive;
class DiZipArchive;
class DiArchiveManager;
class DiSystem;
class DiGpuVariable;
class DiShaderEnvironment;
class DiMaterial;
class DiShaderParameter;
class DiAsset;
class DiAssetManager;
class DiTexture;
class DiCamera;
class DiViewport;
class DiGraphics;
class DiRenderPipeline;
class DiRenderBatchGroup;
class DiRenderUnit;
class DiTransformUnit;
class DiRenderVisitor;
class DiNode;
class DiCullNode;
class DiCullUnit;
class DiSceneCuller;
class DiOctreeCuller;
class DiOctreeCullUnit;
class DiFrustum;
class DiSceneManager;
class DiStateManager;
class DiLight;
class DiDirLight;
class DiPointLight;
class DiSkyLight;
class DiDeviceLostListener;
class DiRenderTarget;
class DiVertexBuffer;
class DiIndexBuffer;
class DiVertexDeclaration;
class DiVertexElements;
class DiRenderWindow;
class DiRenderDevice;
class DiShaderProgram;
class DiQuadNode;
class DiSprite;
class DiPostEffectRt;
class DiPostEffect;
class DiPostEffectPass;
class DiPostEffectManager;
class DiPixelBox;
class DiBox;
class DiRandomTable;
class DiInstanceBatch;
class DiInstanceManager;
class DiInstancedModel;
class DiInstanceBatchShader;
class DiInstanceBatchHardware;
class DiOctree;
class DiAABBQuery;
class DiSphereSceneQuery;
class DiPBVListSceneQuery;
class DiRaySceneQuery;
class DiShadowManager;
class DiTransPlane;
class DiDepthBuffer;
class DiSkybox;
class DiShaderManager;
class DiGBuffer;
class DiBillboard;
class DiBillboardSet;
class DiScene;
class DiMotion;
class DiEntity;
class DiSceneNode;
class DiOctant;
class DiOctantRoot;
class DiGfxDriver;
class DiShaderInstance;
class DiTextureDrv;
class DiWindow;
class DiWindowManager;
class DiCommandManager;
class DiConsoleVar;
class DiConsoleVarListener;
struct DiFoliageLayerDesc;
struct DiRenderUnitList;
class DiDebugHelper;
class DiMesh;
class DiSubMesh;
class DiModel;
class DiAnimModel;
class DiSubModel;
class DiObject;
class DiBone;
class DiSkeleton;
class DiSkeletonInstance;
class DiAttachNode;
class DiAttachSet;
class DiAttachSetInstance;
class DiKeyFrame;
class DiTransformKeyFrame;
class DiAnimation;
class DiAnimationClip;
class DiClipController;
class DiClipControllerSet;
class DiNodeClip;
class DiPostController;
class DiConsoleLogger;
class DiSimpleShape;
class DiGfxCaps;
class DiTransAxes;
class DiShadowCameraPolicy;
class DiConvexBody;
class DiSpotLight;
class BoneMemoryManager;
class BoneArrayMemoryManager;
class SkeletonDef;
class SkeletonInstance;
class SkeletonManager;
class SkeletonAnimation;
class SimpleMatrixAf4x3;
class DiNewBone;
typedef shared_ptr<DiOctree> DiOctreePtr;
typedef shared_ptr<DiOctreeCullUnit> DiOctreeCullUnitPtr;
typedef shared_ptr<DiCullUnit> DiCullUnitPtr;
typedef shared_ptr<DiAnimModel> DiAnimModelPtr;
typedef shared_ptr<StringVec> DiStringVecPtr;
typedef shared_ptr<DiArchive> ArchivePtr;
typedef shared_ptr<DiAsset> DiAssetPtr;
typedef shared_ptr<DiDebugHelper> DiDebugHelperPtr;
typedef shared_ptr<DiDirLight> DiDirLightPtr;
typedef shared_ptr<DiInstanceBatch> DiInstanceBatchPtr;
typedef shared_ptr<DiInstancedModel> DiInstancedModelPtr;
typedef shared_ptr<DiMaterial> DiMaterialPtr;
typedef shared_ptr<DiMesh> DiMeshPtr;
typedef shared_ptr<DiModel> DiModelPtr;
typedef shared_ptr<DiMotion> DiMotionPtr;
typedef shared_ptr<DiPointLight> DiPointLightPtr;
typedef shared_ptr<DiScene> DiScenePtr;
typedef shared_ptr<DiSimpleShape> DiSimpleShapePtr;
typedef shared_ptr<DiSkyLight> DiSkyLightPtr;
typedef shared_ptr<DiSpotLight> DiSpotLightPtr;
typedef shared_ptr<DiTexture> DiTexturePtr;
typedef shared_ptr<DiTransformUnit> DiTransUnitPtr;
typedef shared_ptr<DiBillboardSet> DiBillboardSetPtr;
typedef shared_ptr<DiTransAxes> DiTransAxesPtr;
}
#include "GfxBase.h"
#endif
| [
"demiwangya@gmail.com"
] | demiwangya@gmail.com |
c8cbc6a6f72244595ab2ce384239d1060bff971e | dab868c6eb63f1b1434b105a04c473769ebd6890 | /02_sdl_basics/16_sdl_ttf/main_scene.h | f08a2c1476e49a7142da68d48a9a25d3cb1423a9 | [
"MIT"
] | permissive | Relintai/programming_tutorials | 53878b1cb6bdd76703fc08b6f59abdf726af5a9a | 5176b9fef8dbeff4ac38f0abb47c361fc8b7616c | refs/heads/master | 2023-06-17T03:29:06.665253 | 2021-07-06T10:09:19 | 2021-07-06T10:09:19 | 355,824,431 | 1 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 768 | h | #ifndef MAIN_SCENE_H
#define MAIN_SCENE_H
#include "scene.h"
#include "image.h"
#include "texture.h"
#include "sprite.h"
#include "camera.h"
#include "button.h"
#include "true_type_font.h"
#include "text_image.h"
#include "text_sprite.h"
class MainScene : public Scene {
public:
void event(const SDL_Event &ev);
void update(float delta);
void render();
//ver a
static void on_first_button_clicked();
//ver b
static void on_first_button_clicked_member(void* cls);
void member_print();
MainScene();
~MainScene();
Camera *_camera;
Image *_image;
Texture *_texture;
TrueTypeFont *_font;
Image *_ii;
Texture *_iit;
Texture *_iit2;
Sprite *_s;
Sprite *_s2;
TextImage *_teximg;
TextSprite *_ts;
Button *b1;
Button *b2;
Button *b3;
};
#endif | [
"relintai@protonmail.com"
] | relintai@protonmail.com |
d17a68a41784932c0c93bc1c5bcd71058055ed51 | ba451b320bf242eb5def1c1ebc3acbba9f94ed7e | /桌面智能贪吃蛇动态壁纸/桌面智能贪吃蛇动态壁纸/WinBatchDraw.h | ec244865199a9b62c3ef6430c071125b2f6f4c12 | [] | no_license | Ice2Faith/DesktopAISnackWallpaper | cb87b34cf20e9f3c12c0883eda15ded38beff24a | 35a5d380fc5da1c2ca002494b4222df40e93de62 | refs/heads/main | 2023-01-13T00:37:16.336559 | 2020-11-22T07:23:30 | 2020-11-22T07:23:30 | 314,981,717 | 0 | 1 | null | null | null | null | GB18030 | C++ | false | false | 750 | h | #pragma once
/*
一个简单封装的WIN API GDI 三缓冲绘图类
通过自动创建内存和缓存DC简化操作
*/
class WinBatchDraw
{
public:
WinBatchDraw(HWND hwnd);
WinBatchDraw(HDC hdc,int wid,int hei);
~WinBatchDraw();
HDC BeginBatchDraw(); //开始批量绘图
void SubmitBatchDraw(); //将BDC中的内容提交到MDC中,并重置BDC中的内容
void FlushBatchDraw(); //将MDC中的内容刷新到HDC中
void EndBatchDraw(); //结束批量绘图,并将图形进行显示
HDC GetHDC();
int GetDCHeight();
int GetDCWidth();
void CenterOrg();
void ResetOrg();
private:
void InitDrawEnv();
void BuildBackgroundImg();
HWND m_hwnd;
HDC hdc, mdc, bdc;
HBITMAP mdimg, bdimg;
int wWid, wHei;
};
| [
"noreply@github.com"
] | noreply@github.com |
f43c27ea60259e66a392edda4ffa080a99b7bb01 | 380349f6eaea0c87ca81676e1220f65406a16bd9 | /src/lab7.cpp | 3c657deccc2c9c38057319ac053a1e4e531c3ba5 | [] | no_license | KovalchukM98/EVM-1 | 7eaad24ea40085e61c6f83d77db5483ba9a08460 | 103bfca938db1d922cd8d6694baa781606d19cf5 | refs/heads/main | 2023-04-06T15:35:32.190765 | 2021-04-18T06:26:49 | 2021-04-18T06:26:49 | 359,062,071 | 0 | 0 | null | 2021-04-18T06:20:55 | 2021-04-18T06:20:54 | null | UTF-8 | C++ | false | false | 2,674 | cpp | #include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>
#include <fstream>
#include <fcntl.h>
#include <termios.h>
typedef struct tCHS{
int C;
int H;
int S;
int max_C;
int max_H;
int max_S;
} tCHS;
typedef struct tLARGE{
int C;
int H;
int S;
int max_C;
int max_H;
int max_S;
} tLARGE;
typedef struct tIDECHS{
int C;
int H;
int S;
int max_C;
int max_H;
int max_S;
} tIDECHS;
typedef struct tLBA{
long long address;
int max_C;
int max_H;
int max_S;
} tLBA;
// lba <-> chs
int g_lba2chs (tLBA lba, tCHS *chs){
chs.max_C = lba.max_C;
chs.max_H = lba.max_H;
chs.max_S = lba.max_S;
chs.S = (lba.address % chs.S) + 1;
chs.H = ((lba.address - chs.S + 1)/ chs.max_S) % chs.max_H;
chs.C = (lba.address - chs.S + 1 - chs.H * chs.max_S)/(chs.max_H * chs.max_S);
return 0;
}
int a_lba2chs (tCHS geometry, tLBA, tCHS *){
}
int g_chs2lba (tCHS chs, tLBA *lba){
lba.max_C = chs.max_C;
lba.max_H = chs.max_H;
lba.max_S = chs.max_S;
lba.address = (((chs.C * chs.max_H) + chs.H) * chs.max_S) + (chs.S – 1);
return 0;
}
int a_chs2lba (tCHS geometry, tCHS, tLBA *){
}
//---------------------------------------------------------
// lba <-> large
int g_lba2large (tLBA, tLARGE *){
}
int a_lba2large (tLARGE geometry, tLBA, tLARGE *){
}
int g_large2lba (tLARGE, tLBA *){
}
int a_large2lba (tLARGE geometry, tLARGE, tLBA *){
}
//---------------------------------------------------------
// lba <-> idechs
int g_lba2idechs (tLBA, tIDECHS *){
}
int a_lba2idechs (tIDECHS geometry, tLBA, tIDECHS *){
}
int g_idechs2lba (tIDECHS, tLBA *){
}
int a_idechs2lba (tIDECHS geometry, tIDECHS, tLBA *){
}
//---------------------------------------------------------
// chs <-> large
int g_chs2large (tCHS, tLARGE *){
}
int a_chs2large (tCHS geometry1, tLARGE geometry2, tCHS, tLARGE *){
}
int g_large2chs (tLARGE, tCHS *){
}
int a_large2chs (tLARGE geometry1, tCHS geometry2, tLARGE, tCHS *){
}
//---------------------------------------------------------
// chs <-> idechs
int g_chs2idechs (tIDECHS, tLBA *){
}
int a_chs2idechs (tCHS geometry1, tIDECHS geometry2, tCHS, tIDECHS*){
}
int g_idechs2chs (tIDECHS, tCHS *){
}
int a_idechs2chs (tIDECHS geometry1, tCHS geometry2, tIDECHS, tCHS*){
}
//---------------------------------------------------------
// large <-> idechs
int g_large2idechs (tLARGE, tIDECHS *){
}
int a_large2idechs (tLARGE geometry1, tIDECHS geometry2, tLARGE, tIDECHS *){
}
int g_idechs2lagre (tIDECHS, tLARGE *){
}
int a_idechs2large (tIDECHS geometry1, tLARGE geometry2, tIDECHS, tLARGE *){
}
//---------------------------------------------------------
int main(){
return 0;
} | [
"babur1189@gmail.com"
] | babur1189@gmail.com |
fa485891924f33c53e1d9ce93c4a5c2227926e21 | 62bc922bf836f1e9964e8ee4050e7a621cdee50d | /src/SqrlBlock.cpp | 60501e6532384f5db7ea98c001af0f617eb5273c | [
"MIT"
] | permissive | Novators/libsqrl | e98bda63a32003086a4c461d5d72fde83b793062 | d54db04d070ec28774cd69c9e8ef072aaddf1eb4 | refs/heads/master | 2020-04-06T05:09:29.773841 | 2016-10-09T14:53:32 | 2016-10-09T14:53:32 | 55,088,537 | 33 | 13 | null | 2016-10-08T11:02:33 | 2016-03-30T18:46:18 | C++ | UTF-8 | C++ | false | false | 15,936 | cpp | /** \file SqrlBlock.cpp
*
* \author Adam Comley
*
* This file is part of libsqrl. It is released under the MIT license.
* For more details, see the LICENSE file included with this package.
**/
#include <new>
#include "sqrl_internal.h"
#include "SqrlBlock.h"
using libsqrl::SqrlBlock;
using libsqrl::SqrlString;
namespace libsqrl
{
/// <summary>Default constructor.</summary>
SqrlBlock::SqrlBlock() : SqrlString() {}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Constructor. Creates a SqrlBlock with the contents of a SqrlString
/// (or another SqrlBlock).</summary>
///
/// <param name="original">[in] If non-null, the SqrlString or SqrlBlock to copy.</param>
////////////////////////////////////////////////////////////////////////////////////////////////////
SqrlBlock::SqrlBlock( const SqrlString * original ) : SqrlString( original ) {
this->cur = (this->length() > 4) ? 4 : (uint16_t)this->length();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Constructor. Creates a SqrlBlock from raw data.</summary>
///
/// <param name="data">The data.</param>
////////////////////////////////////////////////////////////////////////////////////////////////////
SqrlBlock::SqrlBlock( const uint8_t* data ) : SqrlString() {
this->append( data, 2 );
uint16_t len = this->readInt16( 0 );
if( len > 4096 ) {
// Sanity check failed! This is too long to be a proper block!
this->writeInt16( 0, 0 );
this->cur = 2;
return;
}
this->append( data + 2, len - 2 );
this->cur = 4;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Clears and Initializes a SqrlBlock.</summary>
///
/// <param name="blockType"> Type of the block.</param>
/// <param name="blockLength">Length of the block.</param>
////////////////////////////////////////////////////////////////////////////////////////////////////
void SqrlBlock::init( uint16_t blockType, uint16_t blockLength ) {
if( blockLength < 4 ) blockLength = 4;
this->clear();
this->append( (char)0, blockLength );
this->writeInt16( blockLength, 0 );
this->writeInt16( blockType, 2 );
this->cur = 4;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Moves the read/write cursor forward.</summary>
///
/// <param name="dest"> Destination.</param>
/// <param name="offset">if true, moves from current cursor location.
/// if false, moves from beginning of block.</param>
///
/// <returns>The updated cursor position.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
uint16_t SqrlBlock::seek( uint16_t dest, bool offset ) {
if( offset ) {
dest += this->cur;
}
this->cur = dest;
if( this->cur > (uint16_t)this->length() ) this->cur = (uint16_t)this->length();
return this->cur;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Moves the read/write cursor backwards.</summary>
///
/// <param name="dest"> Destination.</param>
/// <param name="offset">If true, moves from current cursor location.
/// If false, moves from end of block.</param>
///
/// <returns>The updated cursor position.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
uint16_t SqrlBlock::seekBack( uint16_t dest, bool offset ) {
if( offset ) {
if( this->cur > dest ) {
this->cur -= dest;
} else {
this->cur = 0;
}
} else {
if( dest < this->length() ) {
this->cur = (uint16_t)this->length() - dest;
} else {
this->cur = 0;
}
}
return this->cur;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Writes data to the block, growing the block if needed.</summary>
///
/// <param name="data"> [in] The data to write.</param>
/// <param name="data_len">Length of the data.</param>
/// <param name="offset"> (Optional) If specified, the position to write data.
/// If unspecified, data will be written at the current cursor position,
/// and the cursor will be updated.</param>
///
/// <returns>The length of data actually written, or -1 on error.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
int SqrlBlock::write( const uint8_t *data, uint16_t data_len, uint16_t offset ) {
bool updateCursor = (offset == UINT16_MAX);
if( updateCursor ) {
offset = this->cur;
}
if( data_len + offset > this->length() ) {
this->append( (char)0, data_len + offset - this->length() );
this->writeInt16( (uint16_t)this->length(), 0 );
}
if( data_len + offset > this->length() ) return -1;
memcpy( (uint8_t*)this->myData + offset, data, data_len );
if( updateCursor ) this->cur += (uint16_t)data_len;
return (int)data_len;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Reads data from the block.</summary>
///
/// <param name="data"> [out] A buffer to hold the read data.</param>
/// <param name="data_len">Length of the data.</param>
/// <param name="offset"> (Optional) The position to begin reading from.
/// If unspecified, read begins at current cursor position, and the
/// cursor will be updated.</param>
///
/// <returns>Number of bytes read, or -1 on error.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
int SqrlBlock::read( uint8_t *data, size_t data_len, uint16_t offset ) {
bool updateCursor = (offset == UINT16_MAX);
if( updateCursor ) offset = this->cur;
if( offset + data_len > this->length() ) return -1;
memcpy( data, (uint8_t*)this->myData + offset, data_len );
if( updateCursor ) this->cur += (uint16_t)data_len;
return (int)data_len;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Reads an unsigned 16 bit integer from the block.</summary>
///
/// <param name="offset">(Optional) The position to begin reading from.
/// If unspecified, reading begins at the current cursos position,
/// and the cursor will be moved forward.</param>
///
/// <returns>An uint16_t.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
uint16_t SqrlBlock::readInt16( uint16_t offset ) {
size_t o;
if( offset == UINT16_MAX ) {
o = this->cur;
if( (o + 2) > this->length() ) return false;
this->cur += 2;
} else {
o = offset;
if( (o + 2) > this->length() ) return false;
}
uint8_t *d = (uint8_t*)this->myData + o;
return ((uint16_t)d[0]) | (((uint16_t)d[1]) << 8);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Writes an unsigned 16 bit integer to the block, growing the block if needed.</summary>
///
/// <param name="value"> The value.</param>
/// <param name="offset">(Optional) The position to begin reading from.
/// If unspecified, reading begins at the current cursos position,
/// and the cursor will be moved forward.</param>
///
/// <returns>true if it succeeds, false if it fails.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
bool SqrlBlock::writeInt16( uint16_t value, uint16_t offset ) {
size_t o;
if( offset == UINT16_MAX ) {
o = this->cur;
this->cur += 2;
} else {
o = offset;
}
if( (o + 2) > this->length() ) {
this->append( (char)0, o + 2 - this->length() );
this->writeInt16( (uint16_t)this->length(), 0 );
}
uint8_t *d = (uint8_t*)this->myData + o;
d[0] = value & 0xff;
d[1] = value >> 8;
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Reads an unsigned 32 bit integer from the block.</summary>
///
/// <param name="offset">(Optional) The position to begin reading from.
/// If unspecified, reading begins at the current cursos position,
/// and the cursor will be moved forward.</param>
///
/// <returns>An uint32_t.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
uint32_t SqrlBlock::readInt32( uint16_t offset ) {
size_t o;
if( offset == UINT16_MAX ) {
o = this->cur;
if( (o + 4) > this->length() ) return 0;
this->cur += 4;
} else {
o = offset;
if( (o + 4) > this->length() ) return 0;
}
uint8_t *d = (uint8_t*)this->myData + o;
uint32_t r = (uint32_t)d[0];
r |= ((uint32_t)d[1]) << 8;
r |= ((uint32_t)d[2]) << 16;
r |= ((uint32_t)d[3]) << 24;
return r;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Writes an unsigned 32 bit integer to the block, growing the block if needed.</summary>
///
/// <param name="value"> The value.</param>
/// <param name="offset">(Optional) The position to begin reading from.
/// If unspecified, reading begins at the current cursos position,
/// and the cursor will be moved forward.</param>
///
/// <returns>true if it succeeds, false if it fails.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
bool SqrlBlock::writeInt32( uint32_t value, uint16_t offset ) {
size_t o;
if( offset == UINT16_MAX ) {
o = this->cur;
this->cur += 4;
} else {
o = offset;
}
if( (o + 4) > this->length() ) {
this->append( (char)0, o + 4 - this->length() );
this->writeInt16( (uint16_t)this->length(), 0 );
}
uint8_t *d = (uint8_t*)this->myData + o;
d[0] = (uint8_t)value;
d[1] = (uint8_t)(value >> 8);
d[2] = (uint8_t)(value >> 16);
d[3] = (uint8_t)(value >> 24);
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Reads a byte from the block.</summary>
///
/// <param name="offset">(Optional) The position to begin reading from.
/// If unspecified, reading begins at the current cursos position,
/// and the cursor will be moved forward.</param>
///
/// <returns>An uint8_t.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t SqrlBlock::readInt8( uint16_t offset ) {
size_t o;
if( offset == UINT16_MAX ) {
o = this->cur;
if( (o + 1) > this->length() ) return 0;
this->cur += 1;
} else {
o = offset;
if( (o + 1) > this->length() ) return 0;
}
uint8_t *d = (uint8_t*)this->myData + o;
return d[0];
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Writes a byte to the block, growing the block if needed.</summary>
///
/// <param name="value"> The value.</param>
/// <param name="offset">(Optional) The position to begin reading from.
/// If unspecified, reading begins at the current cursos position,
/// and the cursor will be moved forward.</param>
///
/// <returns>true if it succeeds, false if it fails.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
bool SqrlBlock::writeInt8( uint8_t value, uint16_t offset ) {
size_t o;
if( offset == UINT16_MAX ) {
o = this->cur;
this->cur += 1;
} else {
o = offset;
}
if( (o + 1) > this->length() ) {
this->append( (char)0, o + 1 - this->length() );
this->writeInt16( (uint16_t)this->length(), 0 );
}
uint8_t *d = (uint8_t*)this->myData + o;
d[0] = value;
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Gets a copy of the data contained within this SqrlBlock.</summary>
///
/// <param name="buf"> [out] (Optional) A SqrlString to hold the data.
/// If unspecified, a new SqrlString will be created. Caller is responsible
/// for deleting the new SqrlString.</param>
/// <param name="append">true to append.</param>
///
/// <returns>Pointer to SqrlString instance containing the data.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
SqrlString* SqrlBlock::getData( SqrlString *buf, bool append ) {
if( buf ) {
if( !append ) buf->clear();
buf->append( this );
return buf;
} else {
buf = new SqrlString( this );
return buf;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Gets a pointer to the data inside this SqrlBlock.</summary>
///
/// <remarks>Careful, modifying the data at the returned pointer location is not recommended.</remarks>
///
/// <param name="atCursor">(Optional) If true, points to the current cursor position.
/// If false or unspecified, points to the beginning of the block.</param>
///
/// <returns>A pointer to this SqrlBlock's data.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t* SqrlBlock::getDataPointer( bool atCursor ) {
if( atCursor ) {
return (uint8_t*)this->myData + this->cur;
} else {
return (uint8_t*)this->myData;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>Gets the type of the block.</summary>
///
/// <returns>The block type.</returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
uint16_t SqrlBlock::getBlockType() {
return this->readInt16( 2 );
}
}
| [
"adam@novators.net"
] | adam@novators.net |
55158e77bcd2c9f568ecd932fd544f4a7e512a47 | 597fb3047835a8c9f53289fa71ecc74b067f24cd | /units_ve/axi4_a23/axi4_a23_svf/tests/interconnects/axi4_svf/tb/axi4_interconnect_env.h | 29c2981f2f7349c376663376c130bf0ca238f003 | [] | no_license | yeloer/socblox | 5ad7fb6e82ac29f2d57f7d758501f87f568b5562 | d2e83c343dfdac477e23b9b31b8d3a32a1238073 | refs/heads/master | 2020-05-31T23:30:36.277012 | 2016-03-01T00:49:40 | 2016-03-01T00:49:40 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 583 | h | /*
* axi4_interconnect_env.h
*
* Created on: Dec 11, 2013
* Author: ballance
*/
#ifndef AXI4_INTERCONNECT_ENV_H_
#define AXI4_INTERCONNECT_ENV_H_
#include "svf_component.h"
#include "axi4_master_bfm.h"
class axi4_interconnect_env: public svf_component {
svf_component_ctor_decl(axi4_interconnect_env);
public:
axi4_interconnect_env(const char *name, svf_component *parent);
virtual ~axi4_interconnect_env();
void build();
void connect();
public:
axi4_master_bfm *m_m1_bfm;
axi4_master_bfm *m_m2_bfm;
};
#endif /* AXI4_INTERCONNECT_ENV_H_ */
| [
"matt.ballance@gmail.com"
] | matt.ballance@gmail.com |
620e442cdad182f76fdf446fce3235d95fc764a2 | 73cfd700522885a3fec41127e1f87e1b78acd4d3 | /_Include/boost/thread/thread_functors.hpp | a585e3838ba64925764875dc04cf5a7382ac8106 | [] | no_license | pu2oqa/muServerDeps | 88e8e92fa2053960671f9f57f4c85e062c188319 | 92fcbe082556e11587887ab9d2abc93ec40c41e4 | refs/heads/master | 2023-03-15T12:37:13.995934 | 2019-02-04T10:07:14 | 2019-02-04T10:07:14 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,464 | hpp | ////////////////////////////////////////////////////////////////////////////////
// thread_functors.hpp
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// (C) Copyright 2009-2012 Anthony Williams
// (C) Copyright 2012 Vicente J. Botet Escriba
// Based on the Anthony's idea of scoped_thread in CCiA
#ifndef BOOST_THREAD_THREAD_FUNCTORS_HPP
#define BOOST_THREAD_THREAD_FUNCTORS_HPP
#include <boost/thread/detail/config.hpp>
#include <boost/thread/detail/delete.hpp>
#include <boost/thread/detail/move.hpp>
#include <boost/thread/thread_only.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost
{
struct detach
{
void operator()(thread& t)
{
t.detach();
}
};
struct join_if_joinable
{
void operator()(thread& t)
{
if (t.joinable())
{
t.join();
}
}
};
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
struct interrupt_and_join_if_joinable
{
void operator()(thread& t)
{
t.interrupt();
if (t.joinable())
{
t.join();
}
}
};
#endif
}
#include <boost/config/abi_suffix.hpp>
#endif
/////////////////////////////////////////////////
// vnDev.Games - Trong.LIVE - DAO VAN TRONG //
////////////////////////////////////////////////////////////////////////////////
| [
"langley.joshua@gmail.com"
] | langley.joshua@gmail.com |
44d0adeac48a2c3a3e7e52bc161a971f05ccdaa6 | d5d558be7517d24ee2a632fea53211a8ec1e7d62 | /include/DataDisplay.h | 5c5ae6d4b7b367eceab7d02486a0fd74763b0945 | [] | no_license | esti3549/invaders_chicken | 824b22c459a33b9cc8c2eb4e0e79b67585728165 | 8a68d5c54f6d932f10b591b70863a4bcd6132ed6 | refs/heads/main | 2023-08-31T14:35:47.731938 | 2021-10-17T06:10:32 | 2021-10-17T06:10:32 | 418,036,180 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 459 | h | #pragma once
#include <SFML/Graphics.hpp>
#include "Recources.h"
class DataDisplay
{
public:
DataDisplay();
~DataDisplay() = default;
void displayData(const int lives, const int score, const int level, sf::RenderWindow& window);
protected:
//sf::Sprite m_lives;
std::vector<sf::Texture> m_lives;
//sf::Text m_printScore;
sf::Text m_printLevel;
void setData(sf::Text& text, sf::Vector2f position, int size, sf::Color color);
};
| [
"noreply@github.com"
] | noreply@github.com |
2cf8fb8e5f3204f41178e6a2f825cc3d751e254a | 9f711d68721fcaa8bd4563afbc7498e5aa6d4ce5 | /src/ukf.cpp | 8872aced0b943567586c48e73b9458f87cd55428 | [
"MIT"
] | permissive | ryan-jonesford/UKF | bd58ca186456abe53587d0711fe5f18ce0d91fe2 | e19840db90db841ab19842144329addc983f2d39 | refs/heads/master | 2020-03-19T01:07:26.846007 | 2018-05-31T03:21:51 | 2018-05-31T03:21:51 | 135,524,435 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 10,966 | cpp | #include "Inc/ukf.h"
#include <iostream>
using namespace std;
using Eigen::MatrixXd;
using Eigen::VectorXd;
using std::vector;
/**
* Initializes Unscented Kalman filter
* This is scaffolding, do not modify
*/
UKF::UKF() {
// Make this true to print an anoying amount of debug statements to the
// console
verbose_ = false;
// if this is false, laser measurements will be ignored (except during init)
use_laser_ = true;
// if this is false, radar measurements will be ignored (except during init)
use_radar_ = true;
/*****
* DO NOT MODIFY measurement noise values below these are provided by the
*sensor manufacturer.
*****/
// Laser measurement noise standard deviation position1 in m
std_laspx_ = 0.15;
// Laser measurement noise standard deviation position2 in m
std_laspy_ = 0.15;
// Radar measurement noise standard deviation radius in m
std_radr_ = 0.3;
// Radar measurement noise standard deviation angle in rad
std_radphi_ = 0.03;
// Radar measurement noise standard deviation radius change in m/s
std_radrd_ = 0.3;
/*****
* DO NOT MODIFY measurement noise values above these are provided by the
*sensor manufacturer.
****/
// Process noise standard deviation longitudinal acceleration in m/s^2
std_a_ = .8;
// Process noise standard deviation yaw acceleration in rad/s^2
std_yawdd_ = .75;
// initial state vector
x_ = VectorXd(5);
// initial process noise vector
u_ = VectorXd::Zero(5);
// initial covariance matrix
P_ = MatrixXd(5, 5);
// clang-format off
// measurement matrix
H_ = MatrixXd(2,5);
H_ << 1, 0, 0, 0, 0,
0, 1, 0, 0, 0;
// Laser measurement covariance matrix
R_ = MatrixXd(2,2);
R_<< std_laspx_ * std_laspx_, 0,
0, std_laspy_ * std_laspy_;
// clang-format on
// State dimension
n_x_ = 5;
// Augmented state dimension
n_aug_ = 7;
// Radar measurement direction: r, phi and r_dot
n_z_ = 3;
// Sigma point spreading parameter
lambda_ = 3 - n_aug_;
srt_lambda_n_aug_ = sqrt(lambda_ + n_aug_);
// set weights
weights = VectorXd::Zero(2 * n_aug_ + 1);
weights(0) = lambda_ / (lambda_ + n_aug_);
for (int i = 1; i < 2 * n_aug_ + 1; ++i) {
weights(i) = 1 / (2 * (lambda_ + n_aug_));
}
// Initalize the predicted and augmented sigma points matrix
Xsig_pred_ = MatrixXd::Zero(n_x_, 2 * n_aug_ + 1);
Xsig_aug_ = MatrixXd::Zero(n_aug_, 2 * n_aug_ + 1);
print_nis_ = false;
is_initalized_ = false;
}
UKF::~UKF() {}
/**
* @param {MeasurementPackage} meas_package The latest measurement data of
* either radar or laser.
*/
void UKF::ProcessMeasurement(const MeasurementPackage& measurement_pack) {
if (!is_initalized_) {
// set timestamp
previous_timestamp_ = measurement_pack.timestamp_;
// first measurement
x_ = VectorXd::Ones(n_x_);
switch (measurement_pack.sensor_type_) {
case (MeasurementPackage::RADAR): {
verbosity("Initalizing UKF with Radar measurement");
VectorXd px_py =
tools.PolarToCartesian(measurement_pack.raw_measurements_);
x_(0) = px_py(0);
x_(1) = px_py(1);
// clang-format off
P_ << 0.2, 0.0, 0.0, 0.0, 0.0,
0.0, 0.009, 0.0, 0.0, 0.0,
0.0, 0.0, 0.283, 0.0, 0.0,
0.0, 0.0, 0.0, 2.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0;
// clang-format on
break;
}
case (MeasurementPackage::LASER): {
verbosity("Initalizing UKF with Lasar measurement");
x_(0) = measurement_pack.raw_measurements_(0);
x_(1) = measurement_pack.raw_measurements_(1);
// clang-format off
P_ << 0.075, 0.0, 0.0, 0.0, 0.0,
0.0, 0.075, 0.0, 0.0, 0.0,
0.0, 0.0, 2.7, 0.0, 0.0,
0.0, 0.0, 0.0, 20.0, 0.0,
0.0, 0.0, 0.0, 0.0, 20.0;
// clang-format on
break;
}
default:
cerr << "Bad Sensor type" << endl;
exit(1);
}
is_initalized_ = true;
return; // don't need to make predictions
}
/*****************************************************************************
* Prediction
****************************************************************************/
// get time step in seconds
double dt_1 = get_dt(measurement_pack);
// Execute the predition step
PredictUKF(dt_1);
/*****************************************************************************
* Update
****************************************************************************/
// Different update routines based on sensor type
switch (measurement_pack.sensor_type_) {
case (MeasurementPackage::RADAR): {
if (use_laser_) {
return;
}
verbosity("Updating UKF with Radar measurement");
UpdateRadar(measurement_pack.raw_measurements_);
break;
}
case (MeasurementPackage::LASER): {
if (use_radar_) {
return;
}
verbosity("Updating UKF with Lasar measurement");
Update(measurement_pack.raw_measurements_);
break;
}
default:
cerr << "EKF::ProcessMeasurement: Invalid Measurment device"
<< endl;
}
}
/**
* Predicts sigma points, the state, and the state covariance matrix.
* @param {double} delta_t the change in time (in seconds) between the last
* measurement and this one.
*/
void UKF::PredictUKF(double dt_1) {
verbosity("creating augmented mean vector");
VectorXd x_aug = VectorXd::Zero(n_aug_);
verbosity("setting x_ to head of x_aug");
x_aug.head(n_x_) = x_;
verbosity("Creating augmented state covariance matrix");
MatrixXd A = MatrixXd::Zero(n_aug_, n_aug_);
verbosity("setting P_ to top left corner of A");
A.topLeftCorner(n_x_, n_x_) = P_;
verbosity("Creating and setting Q_aug to bottom right corner of A");
MatrixXd Q_aug = MatrixXd::Zero(2, 2);
Q_aug(0, 0) = std_a_ * std_a_;
Q_aug(1, 1) = std_yawdd_ * std_yawdd_;
A.block(n_x_, n_x_, 2, 2) = Q_aug;
verbosity("Getting the square root of A");
A = A.llt().matrixL();
verbosity("Generating the sigma points");
verbosity("Setting x_ to the first column of Xsig_aug_");
Xsig_aug_.col(0).head(n_x_) = x_;
verbosity("Setting the remaining sigma poitns to Xsig_aug_");
for (int i = 0; i < n_aug_; i++) {
// clang-format off
Xsig_aug_.col(i + 1) = x_aug + srt_lambda_n_aug_ * A.col(i);
Xsig_aug_.col(i + 1 + n_aug_) = x_aug - srt_lambda_n_aug_ * A.col(i);
// clang-format ON
}
double dt_2 = dt_1 * dt_1;
verbosity("Making prediction for the Sigma Points");
for (int i = 0; i < 2 * n_aug_ + 1; ++i) {
// get first 5 rows of column i set = to vector x
VectorXd x = Xsig_aug_.block(0, i, n_x_, 1);
VectorXd x_pred = VectorXd(n_x_);
VectorXd x_noise = VectorXd(n_x_);
// Avoiding divide by zero
if (x(4)) {
// clang-format off
x_pred << (x(2) / x(4)) * (sin(x(3) + x(4) * dt_1) - sin(x(3))),
(x(2) / x(4)) * (-cos(x(3) + x(4) * dt_1) + cos(x(3))), 0,
dt_1 * x(4), 0;
// clang-format on
} else {
x_pred << x(2) * cos(x(3)) * dt_1, x(2) * sin(x(3)) * dt_1, 0, 0, 0;
}
x_noise << .5 * dt_2 * cos(x(3)) * Xsig_aug_(n_x_, i),
.5 * dt_2 * sin(x(3)) * Xsig_aug_(n_x_, i),
dt_1 * Xsig_aug_(n_x_, i), .5 * dt_2 * Xsig_aug_(n_x_ + 1, i),
dt_1 * Xsig_aug_(n_x_ + 1, i);
// Add the vectors up and put them into column i of predicted sigma pts
Xsig_pred_.col(i) = x + x_pred + x_noise;
}
x_.setZero();
P_.setZero();
verbosity("Predicting the state mean");
for (int i = 0; i < 2 * n_aug_ + 1; ++i) {
x_ += Xsig_pred_.col(i) * weights(i);
}
verbosity("Predicting state covariance matrix");
for (int i = 0; i < 2 * n_aug_ + 1; ++i) {
VectorXd F = VectorXd(n_x_);
F = Xsig_pred_.col(i) - x_;
// angle normalization
F(3) = tools.normalizePhi(F(3));
P_ += weights(i) * F * F.transpose();
}
}
/**
* Updates the state and the state covariance matrix using a radar measurement.
* @param {MeasurementPackage} meas_package
*/
void UKF::UpdateRadar(VectorXd z) {
// create matrix for sigma points in measurement space
MatrixXd Zsig = MatrixXd(n_z_, 2 * n_aug_ + 1);
// mean predicted measurement
VectorXd z_pred = VectorXd(n_z_);
verbosity("transform sigma points into measurement space");
for (int i = 0; i < 2 * n_aug_ + 1; ++i) {
Zsig.col(i) = tools.CartesianToPolar(Xsig_pred_.col(i));
}
verbosity("calculate mean predicted measurement");
z_pred.setZero();
for (int i = 0; i < 2 * n_aug_ + 1; ++i) {
z_pred += weights(i) * Zsig.col(i);
}
verbosity("calculate innovation covariance matrix, S");
MatrixXd S = MatrixXd::Zero(n_z_, n_z_);
MatrixXd R = MatrixXd::Zero(n_z_, n_z_);
R(0, 0) = std_radr_ * std_radr_;
R(1, 1) = std_radphi_ * std_radphi_;
R(2, 2) = std_radrd_ * std_radrd_;
for (int i = 0; i < 2 * n_aug_ + 1; ++i) {
VectorXd s = VectorXd::Zero(3);
s = Zsig.col(i) - z_pred;
// angle normalization
s(1) = tools.normalizePhi(s(1));
S += weights(i) * s * s.transpose();
}
S += R;
verbosity("calculate cross correlation matrix");
// create matrix for cross correlation Tc
MatrixXd Tc = MatrixXd::Zero(n_x_, n_z_);
for (int i = 0; i < 2 * n_aug_ + 1; ++i) {
VectorXd t1 = VectorXd::Zero(3);
VectorXd t2 = VectorXd::Zero(3);
t1 = Xsig_pred_.col(i) - x_;
t2 = Zsig.col(i) - z_pred;
// angle normalization
t1(3) = tools.normalizePhi(t1(3));
t2(1) = tools.normalizePhi(t2(1));
Tc += weights(i) * t1 * t2.transpose();
}
verbosity("calculate Kalman gain K");
MatrixXd K = Tc * S.inverse();
verbosity("update state mean and covariance matrix");
MatrixXd z_diff = z - z_pred;
// angle normalization
z_diff(1) = tools.normalizePhi(z_diff(1));
x_ = x_ + K * z_diff;
P_ = P_ - K * S * K.transpose();
// calculate the radar NIS.
if (print_nis_) {
tools.track_nis(tools.RADAR, z_pred, z, S);
}
}
/**
* Returns the type of Kalman Filter that's been implemented
*/
const char* UKF::get_kf_type(void) { return "UKF"; }
| [
"ryanjonesford@gmail.com"
] | ryanjonesford@gmail.com |
16e8d0e67b7b6b524da9efc5ceb08d71b4bc4595 | 91934b8ad2f42f29c445d511c6dd273b7e35ed86 | /Source/Main.cpp | 4b2e374db9f87ca7b60da1bead53f36587e69326 | [] | no_license | fubyo/osccalibrator | 882d348ecf738a11f9bfddf3511693a69d6c1d9e | 9c3652957c2ddc3d2a550f80be1cdb5e6707b8ce | refs/heads/master | 2021-01-10T21:04:00.712697 | 2015-03-16T12:45:03 | 2015-03-16T12:45:03 | 32,316,417 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,422 | cpp | /* OscCalibrator - A mapping and routing tool for use with the Open Sound Control protocol.
Copyright (C) 2012 Dionysios Marinos - fewbio@googlemail.com
This program is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
*/
#include "../JuceLibraryCode/JuceHeader.h"
#include "MainComponent.h"
#include "Pool.h"
class MainWindow : public DocumentWindow
{
public:
//==============================================================================
MainWindow() : DocumentWindow (T("OscCalibrator v0.15"), Colours::lightgrey, DocumentWindow::allButtons, true)
{
MainComponent* const mainComponent = new MainComponent();
setContentComponent (mainComponent, true, true);
centreWithSize (800, 600);
setResizable(true, true);
setVisible (true);
}
~MainWindow()
{
// (the content component will be deleted automatically, so no need to do it here)
}
//==============================================================================
void closeButtonPressed()
{
((MainComponent*)getContentComponent())->oscManager.stop();
JUCEApplication::quit();
}
};
//==============================================================================
class OscCalibratorApplication : public JUCEApplication
{
public:
//==============================================================================
OscCalibratorApplication() : mainWindow(0)
{
}
~OscCalibratorApplication()
{
}
//==============================================================================
void initialise (const String& commandLine)
{
/*
#ifdef _DEBUG
int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
flag |= _CRTDBG_LEAK_CHECK_DF; // Turn on leak-checking bit
_CrtSetDbgFlag(flag);
//_CrtSetBreakAlloc(9667);
#endif
*/
mainWindow = new MainWindow();
}
void shutdown()
{
mainWindow = 0;
int curlong, totlong;
qh_memfreeshort (&curlong, &totlong); /* free short memory and memory allocator */
}
//==============================================================================
void systemRequestedQuit()
{
quit();
}
//==============================================================================
const String getApplicationName()
{
return "OscCalibrator";
}
const String getApplicationVersion()
{
return ProjectInfo::versionString;
}
bool moreThanOneInstanceAllowed()
{
return true;
}
void anotherInstanceStarted (const String& commandLine)
{
}
private:
ScopedPointer<MainWindow> mainWindow;
};
//==============================================================================
// This macro generates the main() routine that starts the app.
START_JUCE_APPLICATION(OscCalibratorApplication)
| [
"fubyo@yahoo.com"
] | fubyo@yahoo.com |
980839fc4547ad29d8a0a8014c3326d69fd3e6a3 | 60f5e2e60f725f4d0bfdda68974c942030021fb2 | /codechef/ICPCIN19/d.cpp | 3997945ca468fb201b9c017ba39dfe9e5d62a360 | [] | no_license | i-64/Competitive-Programming | 3887080a40b8c4c4f31390ac1c61e04f3b27de0d | 43d65120bd94fdb10dd45c323fe445ae775e6408 | refs/heads/master | 2020-09-12T08:42:18.304339 | 2019-11-19T05:44:03 | 2019-11-19T05:44:03 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,293 | cpp | #include <bits/stdc++.h>
using namespace std;
typedef long long i64;
int main () {
ios_base :: sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
string str;
int n, k;
cin >> n >> k >> str;
string arr[k];
vector <int> ms[20];
vector <int> ins[n];
for (int i = 0; i < k; i++) {
cin >> arr[i];
for (char ch:arr[i]) {
ms[ch-'a'].push_back(i);
}
}
for (auto el:ms[str[0]-'a']) {
ins[0].push_back(el);
}
int ret = 0;
int pos[n], l = 0;
memset(pos, 0, sizeof(pos));
for (int i = 1; i < n; i++) {
int setnum = str[i] - 'a';
set_intersection(ms[setnum].begin(), ms[setnum].end(), ins[i-1].begin(), ins[i-1].end(), inserter(ins[i], ins[i].begin()));
if (ins[i].size() == 0) {
pos[i] = 1;
ret++;
for (auto el:ms[setnum]) {
ins[i].push_back(el);
}
}
}
// for (auto el:pos) cout<<el<<" ";cout<<endl;
int retans[n], pen = *ins[n-1].begin();
for (int i = n-1; i >= 0; i--) {
if (pos[i+1] == 1) {
pen = *ins[i].begin();
}
else {}
retans[i] = pen;
}
for (int i = 0; i < n; i++) {
cout << retans[i]+1 << " ";
}
cout << endl;
}
return 0;
}
| [
"mrunal.ahire@gmail.com"
] | mrunal.ahire@gmail.com |
69fa4b3a8a4dff0a0992f9d12bf326e0a66ebe46 | c55d42ab95995ee394c096875b0c2e2837b7fd3c | /SimTKmath/Integrators/include/simmath/internal/SimTKcpodes.h | e65db66268de22577c715b1ed169ebbd00f4b526 | [
"Apache-2.0"
] | permissive | chrisdembia/simbody | 35d72ba384d60e27d84d0daa06d92d15f67f61c0 | 590e75993dd9abf6167c1e5dca88dd7c09b4ab29 | refs/heads/master | 2020-04-05T22:59:51.837566 | 2015-03-28T06:22:50 | 2015-03-28T06:22:50 | 12,479,956 | 0 | 1 | Apache-2.0 | 2017-12-14T08:19:11 | 2013-08-30T06:46:15 | C++ | UTF-8 | C++ | false | false | 17,144 | h | #ifndef SimTK_SIMMATH_CPODES_H_
#define SimTK_SIMMATH_CPODES_H_
/* -------------------------------------------------------------------------- *
* Simbody(tm): SimTKmath *
* -------------------------------------------------------------------------- *
* This is part of the SimTK biosimulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
* *
* Portions copyright (c) 2006-12 Stanford University and the Authors. *
* Authors: Michael Sherman *
* Contributors: *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain a *
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* -------------------------------------------------------------------------- */
/** @file
* This is the header file that user code should include to pick up the
* SimTK C++ interface to the Sundials CPODES coordinate-projection
* integrator.
*/
#include "SimTKcommon.h"
#include "simmath/internal/common.h"
#include <cstdio> // Needed for "FILE".
namespace SimTK {
/**
* This abstract class defines the system to be integrated with SimTK
* CPodes. Note that this defines a client-side virtual function table
* which must be used only on the client side. Library-side access to
* these virtual functions is done only through a set
* of equivalent static functions (provided in this same header files)
* whose addresses can be reliably "tossed over the fence" to the library
* side without compromising binary compatibility.
*/
class SimTK_SIMMATH_EXPORT CPodesSystem {
public:
virtual ~CPodesSystem() {}
// The default implementations of these virtual functions
// just throw an "unimplemented virtual function" exception.
// At least one of these two must be supplied by the concrete class.
virtual int explicitODE(Real t, const Vector& y, Vector& fout) const;
virtual int implicitODE(Real t, const Vector& y, const Vector& yp,
Vector& fout) const;
virtual int constraint(Real t, const Vector& y,
Vector& cout) const;
virtual int project(Real t, const Vector& ycur, Vector& corr,
Real epsProj, Vector& err) const; // err is in/out
virtual int quadrature(Real t, const Vector& y,
Vector& qout) const;
virtual int root(Real t, const Vector& y, const Vector& yp,
Vector& gout) const;
virtual int weight(const Vector& y, Vector& weights) const;
virtual void errorHandler(int error_code, const char* module,
const char* function, char* msg) const;
//TODO: Jacobian functions
};
// These static functions are private to the current (client-side) compilation
// unit. They are used to navigate the client-side CPodesSystem virtual function
// table, which cannot be done on the library side. Note that these are defined
// in the SimTK namespace so don't need "SimTK" in their names.
static int explicitODE_static(const CPodesSystem& sys,
Real t, const Vector& y, Vector& fout)
{ return sys.explicitODE(t,y,fout); }
static int implicitODE_static(const CPodesSystem& sys,
Real t, const Vector& y, const Vector& yp, Vector& fout)
{ return sys.implicitODE(t,y,yp,fout); }
static int constraint_static(const CPodesSystem& sys,
Real t, const Vector& y, Vector& cout)
{ return sys.constraint(t,y,cout); }
static int project_static(const CPodesSystem& sys,
Real t, const Vector& ycur, Vector& corr,
Real epsProj, Vector& err)
{ return sys.project(t,ycur,corr,epsProj,err); }
static int quadrature_static(const CPodesSystem& sys,
Real t, const Vector& y, Vector& qout)
{ return sys.quadrature(t,y,qout); }
static int root_static(const CPodesSystem& sys,
Real t, const Vector& y, const Vector& yp, Vector& gout)
{ return sys.root(t,y,yp,gout); }
static int weight_static(const CPodesSystem& sys,
const Vector& y, Vector& weights)
{ return sys.weight(y,weights); }
static void errorHandler_static(const CPodesSystem& sys,
int error_code, const char* module,
const char* function, char* msg)
{ sys.errorHandler(error_code,module,function,msg); }
/**
* This is a straightforward translation of the Sundials CPODES C
* interface into C++. The class CPodes represents a single instance
* of a CPODES integrator, and handles the associated memory internally.
* Methods here are identical to the corresponding CPODES functions (with
* the "CPode" prefix removed) but are const-correct and use SimTK
* Vector & Real rather than Sundials N_Vector and realtype.
*/
class SimTK_SIMMATH_EXPORT CPodes {
public:
// no default constructor
// copy constructor and default assignment are suppressed
enum ODEType {
UnspecifiedODEType=0,
ExplicitODE,
ImplicitODE
};
enum LinearMultistepMethod {
UnspecifiedLinearMultistepMethod=0,
BDF,
Adams
};
enum NonlinearSystemIterationType {
UnspecifiedNonlinearSystemIterationType=0,
Newton,
Functional
};
enum ToleranceType {
UnspecifiedToleranceType=0,
ScalarScalar,
ScalarVector,
WeightFunction
};
enum ProjectionNorm {
UnspecifiedProjectionNorm=0,
L2Norm,
ErrorNorm
};
enum ConstraintLinearity {
UnspecifiedConstraintLinearity=0,
Linear,
Nonlinear
};
enum ProjectionFactorizationType {
UnspecifiedProjectionFactorizationType=0,
ProjectWithLU,
ProjectWithQR,
ProjectWithSchurComplement,
ProjectWithQRPivot // for handling redundancy
};
enum StepMode {
UnspecifiedStepMode=0,
Normal,
OneStep,
NormalTstop,
OneStepTstop
};
explicit CPodes
(ODEType ode=UnspecifiedODEType,
LinearMultistepMethod lmm=UnspecifiedLinearMultistepMethod,
NonlinearSystemIterationType nls=UnspecifiedNonlinearSystemIterationType)
{
// Perform construction of the CPodesRep on the library side.
librarySideCPodesConstructor(ode, lmm, nls);
// But fill in function pointers from the client side.
clientSideCPodesConstructor();
}
// Values for 'flag' return values. These are just the "normal" return
// values; there are many more which are all negative and represent
// error conditions.
static const int Success = 0;
static const int TstopReturn = 1;
static const int RootReturn = 2;
static const int Warning = 99;
static const int TooMuchWork = -1;
static const int TooClose = -27;
// These values should be used by user routines. "Success" is the
// same as above. A positive return value means "recoverable error",
// i.e., CPodes should cut the step size and try again, while a
// negative number means "unrecoverable error" which will kill
// CPODES altogether with a CP_xxx_FAIL error. The particular numerical
// values here have no significance, just + vs. -.
static const int RecoverableError = 9999;
static const int UnrecoverableError = -9999;
~CPodes();
// Depending on the setting of ode_type at construction, init()
// and reInit() will tell CPodes to use either the explicitODE()
// or implicitODE() function from the CPodesSystem, so the user
// MUST have overridden at least one of those virtual methods.
int init(CPodesSystem& sys,
Real t0, const Vector& y0, const Vector& yp0,
ToleranceType tt, Real reltol, void* abstol);
int reInit(CPodesSystem& sys,
Real t0, const Vector& y0, const Vector& yp0,
ToleranceType tt, Real reltol, void* abstol);
// This tells CPodes to make use of the user's constraint()
// method from CPodesSystem, and perform projection internally.
int projInit(ProjectionNorm, ConstraintLinearity,
const Vector& ctol);
// This tells CPodes to make use of the user's project()
// method from CPodesSystem.
int projDefine();
// These tell CPodes to make use of the user's quadrature()
// method from CPodesSystem.
int quadInit(const Vector& q0);
int quadReInit(const Vector& q0);
// This tells CPodes to make use of the user's root() method
// from CPodesSystem.
int rootInit(int nrtfn);
// This tells CPodes to make use of the user's errorHandler()
// method from CPodesSystem.
int setErrHandlerFn();
// These tells CPodes to make use of the user's weight()
// method from CPodesSystem.
int setEwtFn();
// TODO: these routines should enable methods that are defined
// in the CPodesSystem, but a proper interface to the Jacobian
// routines hasn't been implemented yet.
int dlsSetJacFn(void* jac, void* jac_data);
int dlsProjSetJacFn(void* jacP, void* jacP_data);
int step(Real tout, Real* tret,
Vector& y_inout, Vector& yp_inout, StepMode=Normal);
int setErrFile(FILE* errfp);
int setMaxOrd(int maxord);
int setMaxNumSteps(int mxsteps);
int setMaxHnilWarns(int mxhnil);
int setStabLimDet(bool stldet) ;
int setInitStep(Real hin);
int setMinStep(Real hmin);
int setMaxStep(Real hmax);
int setStopTime(Real tstop);
int setMaxErrTestFails(int maxnef);
int setMaxNonlinIters(int maxcor);
int setMaxConvFails(int maxncf);
int setNonlinConvCoef(Real nlscoef);
int setProjUpdateErrEst(bool proj_err);
int setProjFrequency(int proj_freq);
int setProjTestCnstr(bool test_cnstr);
int setProjLsetupFreq(int proj_lset_freq);
int setProjNonlinConvCoef(Real prjcoef);
int setQuadErrCon(bool errconQ,
int tol_typeQ, Real reltolQ, void* abstolQ);
int setTolerances(int tol_type, Real reltol, void* abstol);
int setRootDirection(Array_<int>& rootdir);
int getDky(Real t, int k, Vector& dky);
int getQuad(Real t, Vector& yQout);
int getQuadDky(Real t, int k, Vector& dky);
int getWorkSpace(int* lenrw, int* leniw);
int getNumSteps(int* nsteps);
int getNumFctEvals(int* nfevals);
int getNumLinSolvSetups(int* nlinsetups);
int getNumErrTestFails(int* netfails);
int getLastOrder(int* qlast);
int getCurrentOrder(int* qcur);
int getNumStabLimOrderReds(int* nslred);
int getActualInitStep(Real* hinused);
int getLastStep(Real* hlast);
int getCurrentStep(Real* hcur);
int getCurrentTime(Real* tcur);
int getTolScaleFactor(Real* tolsfac);
int getErrWeights(Vector& eweight);
int getEstLocalErrors(Vector& ele) ;
int getNumGEvals(int* ngevals);
int getRootInfo(int* rootsfound);
int getRootWindow(Real* tLo, Real* tHi);
int getIntegratorStats(int* nsteps,
int* nfevals, int* nlinsetups,
int* netfails, int* qlast,
int* qcur, Real* hinused, Real* hlast,
Real* hcur, Real* tcur);
int getNumNonlinSolvIters(int* nniters);
int getNumNonlinSolvConvFails(int* nncfails);
int getNonlinSolvStats(int* nniters, int* nncfails);
int getProjNumProj(int* nproj);
int getProjNumCnstrEvals(int* nce);
int getProjNumLinSolvSetups(int* nsetupsP);
int getProjNumFailures(int* nprf) ;
int getProjStats(int* nproj,
int* nce, int* nsetupsP,
int* nprf);
int getQuadNumFunEvals(int* nqevals);
int getQuadErrWeights(Vector& eQweight);
char* getReturnFlagName(int flag);
int dlsGetWorkSpace(int* lenrwLS, int* leniwLS);
int dlsGetNumJacEvals(int* njevals);
int dlsGetNumFctEvals(int* nfevalsLS);
int dlsGetLastFlag(int* flag);
char* dlsGetReturnFlagName(int flag);
int dlsProjGetNumJacEvals(int* njPevals);
int dlsProjGetNumFctEvals(int* ncevalsLS);
int lapackDense(int N);
int lapackBand(int N, int mupper, int mlower);
int lapackDenseProj(int Nc, int Ny, ProjectionFactorizationType);
private:
// This is how we get the client-side virtual functions to
// be callable from library-side code while maintaining binary
// compatibility.
typedef int (*ExplicitODEFunc)(const CPodesSystem&,
Real t, const Vector& y, Vector& fout);
typedef int (*ImplicitODEFunc)(const CPodesSystem&,
Real t, const Vector& y, const Vector& yp,
Vector& fout);
typedef int (*ConstraintFunc) (const CPodesSystem&,
Real t, const Vector& y, Vector& cout);
typedef int (*ProjectFunc) (const CPodesSystem&,
Real t, const Vector& ycur, Vector& corr,
Real epsProj, Vector& err);
typedef int (*QuadratureFunc) (const CPodesSystem&,
Real t, const Vector& y, Vector& qout);
typedef int (*RootFunc) (const CPodesSystem&,
Real t, const Vector& y, const Vector& yp,
Vector& gout);
typedef int (*WeightFunc) (const CPodesSystem&,
const Vector& y, Vector& weights);
typedef void (*ErrorHandlerFunc)(const CPodesSystem&,
int error_code, const char* module,
const char* function, char* msg);
// Note that these routines do not tell CPodes to use the supplied
// functions. They merely provide the client-side addresses of functions
// which understand how to find the user's virtual functions, should those
// actually be provided. Control over whether to actually call any of these
// is handled elsewhere, with user-visible methods. These private methods
// are to be called only upon construction of the CPodes object here. They
// are not even dependent on which user-supplied concrete CPodesSystem is
// being used.
void registerExplicitODEFunc(ExplicitODEFunc);
void registerImplicitODEFunc(ImplicitODEFunc);
void registerConstraintFunc(ConstraintFunc);
void registerProjectFunc(ProjectFunc);
void registerQuadratureFunc(QuadratureFunc);
void registerRootFunc(RootFunc);
void registerWeightFunc(WeightFunc);
void registerErrorHandlerFunc(ErrorHandlerFunc);
// This is the library-side part of the CPodes constructor. This must
// be done prior to the client side construction.
void librarySideCPodesConstructor(ODEType, LinearMultistepMethod, NonlinearSystemIterationType);
// Note that this routine MUST be called from client-side code so that
// it picks up exactly the static routines above which will agree with
// the client about the layout of the CPodesSystem virtual function table.
void clientSideCPodesConstructor() {
registerExplicitODEFunc(explicitODE_static);
registerImplicitODEFunc(implicitODE_static);
registerConstraintFunc(constraint_static);
registerProjectFunc(project_static);
registerQuadratureFunc(quadrature_static);
registerRootFunc(root_static);
registerWeightFunc(weight_static);
registerErrorHandlerFunc(errorHandler_static);
}
// FOR INTERNAL USE ONLY
private:
class CPodesRep* rep;
friend class CPodesRep;
const CPodesRep& getRep() const {assert(rep); return *rep;}
CPodesRep& updRep() {assert(rep); return *rep;}
// Suppress copy constructor and default assigment operator.
CPodes(const CPodes&);
CPodes& operator=(const CPodes&);
};
} // namespace SimTK
#endif // SimTK_CPODES_H_
| [
"sherm1@gmail.com"
] | sherm1@gmail.com |
70577985856711d8df9c4641c98cd65324705c39 | bd86576343264b722ce8c3c8b12152726d741732 | /graph/CNodeTester.h | efa5951717d51a944633348489c42774eb2ae72b | [] | no_license | OlivierCoue/graphlib | 968abd7927ec103fc162d5631c39f7e493ce3c72 | 97a76fbb7d37bca999f90f5531dd2aaf4f6b170b | refs/heads/master | 2021-01-18T22:36:37.692034 | 2017-05-13T12:37:13 | 2017-05-13T12:37:13 | 87,059,656 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 409 | h | #ifndef CNODE_TESTER_H
#define CNODE_TESTER_H
#include "stdafx.h"
#include <iostream>
using namespace std;
class CNodeTester {
public:
/**********************************
Tester
**********************************
Input : nothing
Required : nothing
Output : nothing
Consequence : a serie of test is made one the class CNode
**********************************/
static void NODTmakeTest();
};
#endif | [
"olivier28.coue@gmail.com"
] | olivier28.coue@gmail.com |
cbdf759bd966a7ae0df6a08080a28adc62791607 | 340194d91982838879d92c6ca46cd3106146abc3 | /include/oglplus/context/buffer_selection.hpp | 3ae750da8bd554859f68a94f9466358645a24372 | [
"BSL-1.0"
] | permissive | CallForSanity/oglplus | 38fdee526ed37ddb2413aab518d70c94b2e980db | 9b34fb003cbb0abe62a4aa13cd5a1f15990cbb10 | refs/heads/develop | 2021-01-22T17:15:11.351572 | 2015-01-06T11:34:52 | 2015-01-06T11:34:52 | 28,927,911 | 1 | 0 | null | 2015-01-07T18:35:49 | 2015-01-07T18:35:49 | null | UTF-8 | C++ | false | false | 2,050 | hpp | /** * @file oglplus/context/buffer_selection.hpp
* @brief Wrappers for functions selecting the buffers for read/write operations
*
* @author Matus Chochlik
*
* Copyright 2010-2014 Matus Chochlik. Distributed under the Boost
* Software License, Version 1.0. (See accompanying file
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#pragma once
#ifndef OGLPLUS_CONTEXT_BUFFER_SELECTION_1201040722_HPP
#define OGLPLUS_CONTEXT_BUFFER_SELECTION_1201040722_HPP
#include <oglplus/glfunc.hpp>
#include <oglplus/color_buffer.hpp>
#include <oglplus/framebuffer_attachment.hpp>
#include <oglplus/one_of.hpp>
namespace oglplus {
namespace context {
/// Wrappers for functions selecting the buffers for read/write operations
/**
* @ingroup ogl_context
*/
class BufferSelection
{
public:
/// Color buffer specification type
typedef OneOf<
GLenum,
std::tuple<
oglplus::ColorBuffer,
oglplus::FramebufferColorAttachment
>
> ColorBuffer;
#if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_0
/// Sets the destination color buffer for draw operations
/**
* @glsymbols
* @glfunref{DrawBuffer}
*/
static void DrawBuffer(ColorBuffer buffer)
{
OGLPLUS_GLFUNC(DrawBuffer)(GLenum(buffer));
OGLPLUS_VERIFY_SIMPLE(DrawBuffer);
}
/// Sets the destination color buffers for draw operations
/**
* @glsymbols
* @glfunref{DrawBuffers}
*/
static void DrawBuffers(const EnumArray<ColorBuffer>& buffers)
{
OGLPLUS_GLFUNC(DrawBuffers)(
buffers.Count(),
buffers.Values()
);
OGLPLUS_VERIFY_SIMPLE(DrawBuffers);
}
static void DrawBuffers(GLsizei count, const ColorBuffer* buffers)
{
DrawBuffers(oglplus::EnumArray<ColorBuffer>(count, buffers));
}
#endif // GL_VERSION_3_0
/// Sets the source color buffer for read operations
/**
* @glsymbols
* @glfunref{ReadBuffer}
*/
static void ReadBuffer(ColorBuffer buffer)
{
OGLPLUS_GLFUNC(ReadBuffer)(GLenum(buffer));
OGLPLUS_VERIFY_SIMPLE(ReadBuffer);
}
};
} // namespace context
} // namespace oglplus
#endif // include guard
| [
"chochlik@gmail.com"
] | chochlik@gmail.com |
279193feefd377464202e89d7c3edc394c091611 | e3c7024b5af415a8ee9e79e8cea94bbc410084ec | /project/Haaris/Haaris/Haaris/solution1/syn/systemc/Haaris_Core_mac_mlbW.h | 3f5243b4aa7cfed3af2e07e33f89de597bb4abfb | [] | no_license | lh9171338/HLS | 6fa5e5f981f04f476e99a7d2e61ec385bd671998 | 0d3165c42abe86650a05d568d5c2518956d83ba9 | refs/heads/master | 2022-04-09T15:27:35.605761 | 2020-04-05T09:48:16 | 2020-04-05T09:48:16 | 175,017,352 | 5 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,131 | h | // ==============================================================
// File generated by Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC
// Version: 2018.2
// Copyright (C) 1986-2018 Xilinx, Inc. All Rights Reserved.
//
// ==============================================================
#ifndef __Haaris_Core_mac_mlbW__HH__
#define __Haaris_Core_mac_mlbW__HH__
#include "simcore_mac_3.h"
#include <systemc>
template<
int ID,
int NUM_STAGE,
int din0_WIDTH,
int din1_WIDTH,
int din2_WIDTH,
int dout_WIDTH>
SC_MODULE(Haaris_Core_mac_mlbW) {
sc_core::sc_in< sc_dt::sc_lv<din0_WIDTH> > din0;
sc_core::sc_in< sc_dt::sc_lv<din1_WIDTH> > din1;
sc_core::sc_in< sc_dt::sc_lv<din2_WIDTH> > din2;
sc_core::sc_out< sc_dt::sc_lv<dout_WIDTH> > dout;
simcore_mac_3<ID, 1, din0_WIDTH, din1_WIDTH, din2_WIDTH, dout_WIDTH> simcore_mac_3_U;
SC_CTOR(Haaris_Core_mac_mlbW): simcore_mac_3_U ("simcore_mac_3_U") {
simcore_mac_3_U.din0(din0);
simcore_mac_3_U.din1(din1);
simcore_mac_3_U.din2(din2);
simcore_mac_3_U.dout(dout);
}
};
#endif //
| [
"2909171338@qq.com"
] | 2909171338@qq.com |
82d15c63e6d53ee25b8ce24ce2daa0816cf9e860 | e7a83eff3f71c056fa7a7dbbd28b12eb4ab262bf | /imgSegmentation.h | 86f8af55f589cfb6107bddeb66f7525dfc139a4b | [] | no_license | cokeroluwafemi/Mosaic_cpp | 4f6c257bc3b5f4d0cf6b4d153901ebab0b081c43 | 7553b47d2af87367a5ddbbbc2be1fe10925a1617 | refs/heads/master | 2022-02-26T00:38:02.090284 | 2017-11-22T12:06:03 | 2017-11-22T12:06:03 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,870 | h | //
// Created by Zhiyuan Wang on 19/06/2017.
//
#ifndef MOSAIC_IMGSEGMENTATION_H
#define MOSAIC_IMGSEGMENTATION_H
#include <unordered_set>
#include <unordered_map>
#include <opencv/cv.hpp>
#include "colorHistVector.h"
using namespace std;
using namespace cv;
/**
* Customized class inherited from Rect class. Added hash and equal functions.
*/
class mRect: public Rect{
public:
mRect(){};
mRect(int x, int y, int width, int height);
mRect(Rect rect);
bool operator==(const mRect& rect);
};
template <>
struct std::hash<mRect>{
size_t operator()(const mRect& rect) const{
int result = rect.x;
result = 31*result + rect.width;
result = 31*result + rect.y;
result = 31*result + rect.height;
return result;
}
};
/**
* The class representing the color histogram of a chunk.
*/
class block {
public:
block(Mat const& img, mRect const& roi, int colorRes);
~block();
//bool operator==(const block& b);
public:
int size;
//mRect roi;
colorHistVector* colorhist;
};
/**
* The major class for image segmentation.
*/
class imgSegmentation {
private:
Mat mImg;
unordered_map<mRect, block*> map;
double similarity_threshold;
int min_size;
int max_size;
int color_resolution;
public:
/**
* Constructor. This segmentation class uses bottom-top method (merge).
* @param img source image.
* @param color_resolution color resolution of 3d-vector for color histogram.
* @param similarity_threshold the threshold of color similarity for different chunks to get merged.
* @param min_size the starting size of each chunk during merging.
* @param max_size maximum size limit of chunks in segmentation result.
*/
imgSegmentation(Mat &img, int color_resolution = 10, double similarity_threshold = 0.5,
int min_size = 20, int max_size = 160);
/**
* Destructor.
*/
~imgSegmentation();
/**
* The method doing actual segmentation.
*/
void segment();
/**
* Print some info to help debug.
*/
void print();
/**
* Save merge result to disk.
* @param path the destination path.
*/
void saveMergeResult(string path);
/**
* Helper method for mosaicGenerator to get map.
* @return the map in this class.
*/
unordered_map<mRect, block*> getMap(){ return this->map; };
/**
* Helper method for mosaicGenerator to get source image Mat object.
*/
Mat get_img(){ return mImg; };
private:
/**
* Helper method to crop source image to fit for merge. The remainder of image size
* divided by minimal chunk size (starting size) would be cropped.
* @param img source image.
* @param min_size starting size of chunks.
*/
void imgCropper(Mat &img, int min_size);
/**
* Calculate all colorHistVector and save for later merge.
*/
void initialize_segments();
/**
* If there're 4 neighbor segments with same size and color histogram similarities
* between each pair are above threshold, then merge them. Do this step until there
* are no segments satisfying the condition.
* */
void merge_segments();
/**
* For a given rectangle area, generate all 4 possible combinations of rectangles.
*/
vector<vector<mRect>> get_candidate_rois(const mRect& rect);
/**
* Decide if given 4 roi is valid for merge. All 4 rois must be in map (the chunks exist)
* and not merged yet, and the similarities between each pair of chunks must be above threshold.
*/
bool valid_for_merge(const vector<mRect>& rois, const unordered_set<mRect>& merged);
/**
* Get result rectangle of the chunk merged by 4 smaller chunks.
*/
mRect merge_rois(const vector<mRect> rois);
};
#endif //MOSAIC_IMGSEGMENTATION_H
| [
"wangzhiy@usc.edu"
] | wangzhiy@usc.edu |
da17a8852339cda7fa1f870b70b02b3acb05c3ed | 005cb1c69358d301f72c6a6890ffeb430573c1a1 | /Pods/Headers/Private/GeoFeatures/boost/geometry/algorithms/detail/is_valid/pointlike.hpp | 748a866c582058eb556a12adc909c79e294a46cf | [
"Apache-2.0"
] | permissive | TheClimateCorporation/DemoCLUs | 05588dcca687cc5854755fad72f07759f81fe673 | f343da9b41807694055151a721b497cf6267f829 | refs/heads/master | 2021-01-10T15:10:06.021498 | 2016-04-19T20:31:34 | 2016-04-19T20:31:34 | 51,960,444 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 103 | hpp | ../../../../../../../../GeoFeatures/GeoFeatures/boost/geometry/algorithms/detail/is_valid/pointlike.hpp | [
"tommy.rogers@climate.com"
] | tommy.rogers@climate.com |
92b2fac76433c71edae4646204fce60b6f37de1a | 71c165473a96cfc844b25fe81f6d3253bd232d8e | /src/claimtrie.h | b57e0dcce15cbcfc0c67834a3ce639b420eb1dca | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | marceluphd/lbrycrd | 26f8c667ddf6e19764a39b109e4a7ea40d2d993b | 90afa721475a67d2c9a0723f3d766ded938e9ec8 | refs/heads/master | 2020-06-22T08:28:28.883558 | 2019-07-02T14:44:33 | 2019-07-02T14:44:33 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 21,534 | h | #ifndef BITCOIN_CLAIMTRIE_H
#define BITCOIN_CLAIMTRIE_H
#include <amount.h>
#include <chain.h>
#include <chainparams.h>
#include <dbwrapper.h>
#include <prefixtrie.h>
#include <primitives/transaction.h>
#include <serialize.h>
#include <uint256.h>
#include <util.h>
#include <map>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
// leveldb keys
#define TRIE_NODE 'n'
#define CLAIM_BY_ID 'i'
#define CLAIM_QUEUE_ROW 'r'
#define CLAIM_QUEUE_NAME_ROW 'm'
#define EXP_QUEUE_ROW 'e'
#define SUPPORT 's'
#define SUPPORT_QUEUE_ROW 'u'
#define SUPPORT_QUEUE_NAME_ROW 'p'
#define SUPPORT_EXP_QUEUE_ROW 'x'
uint256 getValueHash(const COutPoint& outPoint, int nHeightOfLastTakeover);
struct CClaimValue
{
COutPoint outPoint;
uint160 claimId;
CAmount nAmount;
CAmount nEffectiveAmount;
int nHeight;
int nValidAtHeight;
CClaimValue()
{
}
CClaimValue(const COutPoint& outPoint, const uint160& claimId, CAmount nAmount, int nHeight, int nValidAtHeight)
: outPoint(outPoint), claimId(claimId), nAmount(nAmount), nEffectiveAmount(nAmount), nHeight(nHeight), nValidAtHeight(nValidAtHeight)
{
}
CClaimValue(CClaimValue&&) = default;
CClaimValue(const CClaimValue&) = default;
CClaimValue& operator=(CClaimValue&&) = default;
CClaimValue& operator=(const CClaimValue&) = default;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(outPoint);
READWRITE(claimId);
READWRITE(nAmount);
READWRITE(nHeight);
READWRITE(nValidAtHeight);
}
bool operator<(const CClaimValue& other) const
{
if (nEffectiveAmount < other.nEffectiveAmount)
return true;
if (nEffectiveAmount != other.nEffectiveAmount)
return false;
if (nHeight > other.nHeight)
return true;
if (nHeight != other.nHeight)
return false;
return outPoint != other.outPoint && !(outPoint < other.outPoint);
}
bool operator==(const CClaimValue& other) const
{
return outPoint == other.outPoint && claimId == other.claimId && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
}
bool operator!=(const CClaimValue& other) const
{
return !(*this == other);
}
};
struct CSupportValue
{
COutPoint outPoint;
uint160 supportedClaimId;
CAmount nAmount;
int nHeight;
int nValidAtHeight;
CSupportValue()
{
}
CSupportValue(const COutPoint& outPoint, const uint160& supportedClaimId, CAmount nAmount, int nHeight, int nValidAtHeight)
: outPoint(outPoint), supportedClaimId(supportedClaimId), nAmount(nAmount), nHeight(nHeight), nValidAtHeight(nValidAtHeight)
{
}
CSupportValue(CSupportValue&&) = default;
CSupportValue(const CSupportValue&) = default;
CSupportValue& operator=(CSupportValue&&) = default;
CSupportValue& operator=(const CSupportValue&) = default;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(outPoint);
READWRITE(supportedClaimId);
READWRITE(nAmount);
READWRITE(nHeight);
READWRITE(nValidAtHeight);
}
bool operator==(const CSupportValue& other) const
{
return outPoint == other.outPoint && supportedClaimId == other.supportedClaimId && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
}
bool operator!=(const CSupportValue& other) const
{
return !(*this == other);
}
};
typedef std::vector<CClaimValue> claimEntryType;
typedef std::vector<CSupportValue> supportEntryType;
struct CClaimTrieData
{
uint256 hash;
claimEntryType claims;
int nHeightOfLastTakeover = 0;
CClaimTrieData() = default;
CClaimTrieData(CClaimTrieData&&) = default;
CClaimTrieData(const CClaimTrieData&) = default;
CClaimTrieData& operator=(CClaimTrieData&&) = default;
CClaimTrieData& operator=(const CClaimTrieData& d) = default;
bool insertClaim(const CClaimValue& claim);
bool removeClaim(const COutPoint& outPoint, CClaimValue& claim);
bool getBestClaim(CClaimValue& claim) const;
bool haveClaim(const COutPoint& outPoint) const;
void reorderClaims(const supportEntryType& support);
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(hash);
if (ser_action.ForRead()) {
if (s.eof()) {
claims.clear();
nHeightOfLastTakeover = 0;
return;
}
}
else if (claims.empty())
return;
READWRITE(claims);
READWRITE(nHeightOfLastTakeover);
}
bool operator==(const CClaimTrieData& other) const
{
return hash == other.hash && nHeightOfLastTakeover == other.nHeightOfLastTakeover && claims == other.claims;
}
bool operator!=(const CClaimTrieData& other) const
{
return !(*this == other);
}
bool empty() const
{
return claims.empty();
}
};
struct COutPointHeightType
{
COutPoint outPoint;
int nHeight;
COutPointHeightType()
{
}
COutPointHeightType(const COutPoint& outPoint, int nHeight)
: outPoint(outPoint), nHeight(nHeight)
{
}
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(outPoint);
READWRITE(nHeight);
}
};
struct CNameOutPointHeightType
{
std::string name;
COutPoint outPoint;
int nHeight;
CNameOutPointHeightType()
{
}
CNameOutPointHeightType(std::string name, const COutPoint& outPoint, int nHeight)
: name(std::move(name)), outPoint(outPoint), nHeight(nHeight)
{
}
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(name);
READWRITE(outPoint);
READWRITE(nHeight);
}
};
struct CNameOutPointType
{
std::string name;
COutPoint outPoint;
CNameOutPointType()
{
}
CNameOutPointType(std::string name, const COutPoint& outPoint)
: name(std::move(name)), outPoint(outPoint)
{
}
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(name);
READWRITE(outPoint);
}
};
struct CClaimIndexElement
{
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(name);
READWRITE(claim);
}
std::string name;
CClaimValue claim;
};
struct CClaimsForNameType
{
claimEntryType claims;
supportEntryType supports;
int nLastTakeoverHeight;
std::string name;
CClaimsForNameType(claimEntryType claims, supportEntryType supports, int nLastTakeoverHeight, const std::string& name)
: claims(std::move(claims)), supports(std::move(supports)), nLastTakeoverHeight(nLastTakeoverHeight), name(name)
{
}
CClaimsForNameType(CClaimsForNameType&&) = default;
CClaimsForNameType(const CClaimsForNameType&) = default;
CClaimsForNameType& operator=(CClaimsForNameType&&) = default;
CClaimsForNameType& operator=(const CClaimsForNameType&) = default;
};
class CClaimTrie : public CPrefixTrie<std::string, CClaimTrieData>
{
int nNextHeight = 0;
int nExpirationTime = 0;
int nProportionalDelayFactor = 0;
std::unique_ptr<CDBWrapper> db;
public:
CClaimTrie() = default;
CClaimTrie(CClaimTrie&&) = delete;
CClaimTrie(const CClaimTrie&) = delete;
CClaimTrie(bool fMemory, bool fWipe, int proportionalDelayFactor = 32);
CClaimTrie& operator=(CClaimTrie&&) = delete;
CClaimTrie& operator=(const CClaimTrie&) = delete;
bool SyncToDisk();
friend class CClaimTrieCacheBase;
friend class ClaimTrieChainFixture;
friend class CClaimTrieCacheExpirationFork;
friend class CClaimTrieCacheNormalizationFork;
};
class CClaimTrieProofNode
{
public:
CClaimTrieProofNode(std::vector<std::pair<unsigned char, uint256>> children, bool hasValue, const uint256& valHash)
: children(std::move(children)), hasValue(hasValue), valHash(valHash)
{
}
CClaimTrieProofNode(CClaimTrieProofNode&&) = default;
CClaimTrieProofNode(const CClaimTrieProofNode&) = default;
CClaimTrieProofNode& operator=(CClaimTrieProofNode&&) = default;
CClaimTrieProofNode& operator=(const CClaimTrieProofNode&) = default;
std::vector<std::pair<unsigned char, uint256>> children;
bool hasValue;
uint256 valHash;
};
class CClaimTrieProof
{
public:
CClaimTrieProof()
{
}
CClaimTrieProof(std::vector<CClaimTrieProofNode> nodes, bool hasValue, const COutPoint& outPoint, int nHeightOfLastTakeover)
: nodes(std::move(nodes)), hasValue(hasValue), outPoint(outPoint), nHeightOfLastTakeover(nHeightOfLastTakeover)
{
}
CClaimTrieProof(CClaimTrieProof&&) = default;
CClaimTrieProof(const CClaimTrieProof&) = default;
CClaimTrieProof& operator=(CClaimTrieProof&&) = default;
CClaimTrieProof& operator=(const CClaimTrieProof&) = default;
std::vector<CClaimTrieProofNode> nodes;
bool hasValue;
COutPoint outPoint;
int nHeightOfLastTakeover;
};
typedef std::pair<std::string, CClaimValue> claimQueueEntryType;
typedef std::vector<claimQueueEntryType> claimQueueRowType;
typedef std::map<int, claimQueueRowType> claimQueueType;
typedef std::pair<std::string, CSupportValue> supportQueueEntryType;
typedef std::vector<supportQueueEntryType> supportQueueRowType;
typedef std::map<int, supportQueueRowType> supportQueueType;
typedef std::vector<COutPointHeightType> queueNameRowType;
typedef std::map<std::string, queueNameRowType> queueNameType;
typedef std::vector<CNameOutPointHeightType> insertUndoType;
typedef std::vector<CNameOutPointType> expirationQueueRowType;
typedef std::map<int, expirationQueueRowType> expirationQueueType;
typedef std::set<CClaimValue> claimIndexClaimListType;
typedef std::vector<CClaimIndexElement> claimIndexElementListType;
class CClaimTrieCacheBase
{
public:
explicit CClaimTrieCacheBase(CClaimTrie* base, bool fRequireTakeoverHeights = true);
virtual ~CClaimTrieCacheBase() = default;
uint256 getMerkleHash();
bool checkConsistency(int minimumHeight = 1) const;
bool getClaimById(const uint160& claimId, std::string& name, CClaimValue& claim) const;
bool flush();
bool empty() const;
bool ReadFromDisk(const CBlockIndex* tip);
bool haveClaim(const std::string& name, const COutPoint& outPoint) const;
bool haveClaimInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight);
bool haveSupport(const std::string& name, const COutPoint& outPoint) const;
bool haveSupportInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight);
std::size_t getTotalNamesInTrie() const;
std::size_t getTotalClaimsInTrie() const;
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
bool addClaim(const std::string& name, const COutPoint& outPoint, const uint160& claimId, CAmount nAmount, int nHeight);
bool undoAddClaim(const std::string& name, const COutPoint& outPoint, int nHeight);
bool spendClaim(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight);
bool undoSpendClaim(const std::string& name, const COutPoint& outPoint, const uint160& claimId, CAmount nAmount, int nHeight, int nValidAtHeight);
bool addSupport(const std::string& name, const COutPoint& outPoint, CAmount nAmount, const uint160& supportedClaimId, int nHeight);
bool undoAddSupport(const std::string& name, const COutPoint& outPoint, int nHeight);
bool spendSupport(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight);
bool undoSpendSupport(const std::string& name, const COutPoint& outPoint, const uint160& supportedClaimId, CAmount nAmount, int nHeight, int nValidAtHeight);
virtual bool incrementBlock(insertUndoType& insertUndo,
claimQueueRowType& expireUndo,
insertUndoType& insertSupportUndo,
supportQueueRowType& expireSupportUndo,
std::vector<std::pair<std::string, int>>& takeoverHeightUndo);
virtual bool decrementBlock(insertUndoType& insertUndo,
claimQueueRowType& expireUndo,
insertUndoType& insertSupportUndo,
supportQueueRowType& expireSupportUndo);
virtual bool getProofForName(const std::string& name, CClaimTrieProof& proof);
virtual bool getInfoForName(const std::string& name, CClaimValue& claim) const;
bool finalizeDecrement(std::vector<std::pair<std::string, int>>& takeoverHeightUndo);
virtual CClaimsForNameType getClaimsForName(const std::string& name) const;
CAmount getEffectiveAmountForClaim(const std::string& name, const uint160& claimId, std::vector<CSupportValue>* supports = nullptr) const;
CAmount getEffectiveAmountForClaim(const CClaimsForNameType& claims, const uint160& claimId, std::vector<CSupportValue>* supports = nullptr) const;
void setExpirationTime(int time);
int expirationTime();
CClaimTrie::const_iterator begin() const;
CClaimTrie::const_iterator end() const;
CClaimTrie::const_iterator find(const std::string& name) const;
void dumpToLog(CClaimTrie::const_iterator it, bool diffFromBase = true) const;
protected:
CClaimTrie* base;
CClaimTrie cache;
std::unordered_set<std::string> namesToCheckForTakeover;
uint256 recursiveComputeMerkleHash(CClaimTrie::iterator& it);
virtual bool insertClaimIntoTrie(const std::string& name, const CClaimValue& claim, bool fCheckTakeover);
virtual bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint, CClaimValue& claim, bool fCheckTakeover);
virtual bool insertSupportIntoMap(const std::string& name, const CSupportValue& support, bool fCheckTakeover);
virtual bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint, CSupportValue& support, bool fCheckTakeover);
virtual bool addClaimToQueues(const std::string& name, const CClaimValue& claim);
virtual bool addSupportToQueues(const std::string& name, const CSupportValue& support);
virtual bool removeSupportFromQueue(const std::string& name, const COutPoint& outPoint, CSupportValue& support);
virtual std::string adjustNameForValidHeight(const std::string& name, int validHeight) const;
void addToExpirationQueue(int nExpirationHeight, CNameOutPointType& entry);
void removeFromExpirationQueue(const std::string& name, const COutPoint& outPoint, int nHeight);
void addSupportToExpirationQueue(int nExpirationHeight, CNameOutPointType& entry);
void removeSupportFromExpirationQueue(const std::string& name, const COutPoint& outPoint, int nHeight);
supportEntryType getSupportsForName(const std::string& name) const;
int getDelayForName(const std::string& name);
virtual int getDelayForName(const std::string& name, const uint160& claimId);
CClaimTrie::iterator cacheData(const std::string& name, bool create = true);
bool getLastTakeoverForName(const std::string& name, uint160& claimId, int& takeoverHeight) const;
int getNumBlocksOfContinuousOwnership(const std::string& name);
expirationQueueType expirationQueueCache;
expirationQueueType supportExpirationQueueCache;
int nNextHeight; // Height of the block that is being worked on, which is
// one greater than the height of the chain's tip
private:
uint256 hashBlock;
std::unordered_map<std::string, std::pair<uint160, int>> takeoverCache;
bool fRequireTakeoverHeights;
claimQueueType claimQueueCache;
queueNameType claimQueueNameCache;
supportQueueType supportQueueCache;
queueNameType supportQueueNameCache;
claimIndexElementListType claimsToAdd;
claimIndexClaimListType claimsToDelete;
std::unordered_map<std::string, supportEntryType> cacheSupports;
std::unordered_set<std::string> nodesToDelete;
std::unordered_set<std::string> alreadyCachedNodes;
std::unordered_map<std::string, bool> takeoverWorkaround;
std::unordered_set<std::string> removalWorkaround;
bool shouldUseTakeoverWorkaround(const std::string& key) const;
void addTakeoverWorkaroundPotential(const std::string& key);
void confirmTakeoverWorkaroundNeeded(const std::string& key);
bool clear();
void markAsDirty(const std::string& name, bool fCheckTakeover);
bool removeSupport(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover);
bool removeClaim(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover);
bool removeClaimFromQueue(const std::string& name, const COutPoint& outPoint, CClaimValue& claim);
typename claimQueueType::value_type* getQueueCacheRow(int nHeight, bool createIfNotExists = false);
typename queueNameType::value_type* getQueueCacheNameRow(const std::string& name, bool createIfNotExists = false);
typename expirationQueueType::value_type* getExpirationQueueCacheRow(int nHeight, bool createIfNotExists = false);
typename supportQueueType::value_type* getSupportQueueCacheRow(int nHeight, bool createIfNotExists = false);
typename queueNameType::value_type* getSupportQueueCacheNameRow(const std::string& name, bool createIfNotExists = false);
typename expirationQueueType::value_type* getSupportExpirationQueueCacheRow(int nHeight, bool createIfNotExists = false);
// for unit test
friend class ClaimTrieChainFixture;
friend class CClaimTrieCacheTest;
};
class CClaimTrieCacheExpirationFork : public CClaimTrieCacheBase
{
public:
explicit CClaimTrieCacheExpirationFork(CClaimTrie* base, bool fRequireTakeoverHeights = true)
: CClaimTrieCacheBase(base, fRequireTakeoverHeights)
{
}
bool forkForExpirationChange(bool increment);
// TODO: move the expiration fork code from main.cpp to overrides of increment/decrement block
private:
void removeAndAddSupportToExpirationQueue(expirationQueueRowType& row, int height, bool increment);
void removeAndAddToExpirationQueue(expirationQueueRowType& row, int height, bool increment);
};
class CClaimTrieCacheNormalizationFork : public CClaimTrieCacheExpirationFork
{
public:
explicit CClaimTrieCacheNormalizationFork(CClaimTrie* base, bool fRequireTakeoverHeights = true)
: CClaimTrieCacheExpirationFork(base, fRequireTakeoverHeights), overrideInsertNormalization(false), overrideRemoveNormalization(false)
{
}
bool shouldNormalize() const;
// lower-case and normalize any input string name
// see: https://unicode.org/reports/tr15/#Norm_Forms
std::string normalizeClaimName(const std::string& name, bool force = false) const; // public only for validating name field on update op
bool incrementBlock(insertUndoType& insertUndo,
claimQueueRowType& expireUndo,
insertUndoType& insertSupportUndo,
supportQueueRowType& expireSupportUndo,
std::vector<std::pair<std::string, int>>& takeoverHeightUndo) override;
bool decrementBlock(insertUndoType& insertUndo,
claimQueueRowType& expireUndo,
insertUndoType& insertSupportUndo,
supportQueueRowType& expireSupportUndo) override;
bool getProofForName(const std::string& name, CClaimTrieProof& proof) override;
bool getInfoForName(const std::string& name, CClaimValue& claim) const override;
CClaimsForNameType getClaimsForName(const std::string& name) const override;
protected:
bool insertClaimIntoTrie(const std::string& name, const CClaimValue& claim, bool fCheckTakeover = false) override;
bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint, CClaimValue& claim, bool fCheckTakeover = false) override;
bool insertSupportIntoMap(const std::string& name, const CSupportValue& support, bool fCheckTakeover) override;
bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint, CSupportValue& support, bool fCheckTakeover) override;
int getDelayForName(const std::string& name, const uint160& claimId) override;
bool addClaimToQueues(const std::string& name, const CClaimValue& claim) override;
bool addSupportToQueues(const std::string& name, const CSupportValue& support) override;
std::string adjustNameForValidHeight(const std::string& name, int validHeight) const override;
private:
bool overrideInsertNormalization;
bool overrideRemoveNormalization;
bool normalizeAllNamesInTrieIfNecessary(insertUndoType& insertUndo,
claimQueueRowType& removeUndo,
insertUndoType& insertSupportUndo,
supportQueueRowType& expireSupportUndo,
std::vector<std::pair<std::string, int>>& takeoverHeightUndo);
};
typedef CClaimTrieCacheNormalizationFork CClaimTrieCache;
#endif // BITCOIN_CLAIMTRIE_H
| [
"countprimes@gmail.com"
] | countprimes@gmail.com |
d3e85d7e16366308a2392ad1556a48d7e1adca53 | 04b1803adb6653ecb7cb827c4f4aa616afacf629 | /chromeos/components/tether/gms_core_notifications_state_tracker_impl.cc | 99e5a9bb15dd846a97c110401ab88f5d9d8c36c0 | [
"BSD-3-Clause"
] | permissive | Samsung/Castanets | 240d9338e097b75b3f669604315b06f7cf129d64 | 4896f732fc747dfdcfcbac3d442f2d2d42df264a | refs/heads/castanets_76_dev | 2023-08-31T09:01:04.744346 | 2021-07-30T04:56:25 | 2021-08-11T05:45:21 | 125,484,161 | 58 | 49 | BSD-3-Clause | 2022-10-16T19:31:26 | 2018-03-16T08:07:37 | null | UTF-8 | C++ | false | false | 4,164 | cc | // Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/components/tether/gms_core_notifications_state_tracker_impl.h"
#include <sstream>
#include "chromeos/components/multidevice/logging/logging.h"
namespace chromeos {
namespace tether {
namespace {
bool ContainsDeviceWithId(
const std::string& device_id,
const std::vector<HostScannerOperation::ScannedDeviceInfo>&
device_info_list) {
for (const auto& device_info : device_info_list) {
if (device_info.remote_device.GetDeviceId() == device_id)
return true;
}
return false;
}
bool ContainsDeviceWithId(
const std::string& device_id,
const multidevice::RemoteDeviceRefList& remote_device_list) {
for (const auto& device_info : remote_device_list) {
if (device_info.GetDeviceId() == device_id)
return true;
}
return false;
}
} // namespace
GmsCoreNotificationsStateTrackerImpl::GmsCoreNotificationsStateTrackerImpl() =
default;
GmsCoreNotificationsStateTrackerImpl::~GmsCoreNotificationsStateTrackerImpl() {
bool was_empty = device_id_to_name_map_.empty();
device_id_to_name_map_.clear();
if (!was_empty)
SendDeviceNamesChangeEvent();
}
std::vector<std::string> GmsCoreNotificationsStateTrackerImpl::
GetGmsCoreNotificationsDisabledDeviceNames() {
std::vector<std::string> device_names;
for (const auto& map_entry : device_id_to_name_map_)
device_names.push_back(map_entry.second);
return device_names;
}
void GmsCoreNotificationsStateTrackerImpl::OnTetherAvailabilityResponse(
const std::vector<HostScannerOperation::ScannedDeviceInfo>&
scanned_device_list_so_far,
const multidevice::RemoteDeviceRefList&
gms_core_notifications_disabled_devices,
bool is_final_scan_result) {
size_t old_size = device_id_to_name_map_.size();
// Insert all names gathered by this scan to |device_id_to_name_map_|.
for (const auto& remote_device : gms_core_notifications_disabled_devices)
device_id_to_name_map_[remote_device.GetDeviceId()] = remote_device.name();
bool names_changed = old_size < device_id_to_name_map_.size();
// Iterate through |device_id_to_name_map_| and remove entries which are no
// longer valid given the newest scan results.
auto it = device_id_to_name_map_.begin();
while (it != device_id_to_name_map_.end()) {
// A device has enabled notifications if it is included in the list of
// scanned devices (only valid tether hosts are present in the list).
bool device_enabled_notifications =
ContainsDeviceWithId(it->first, scanned_device_list_so_far);
// If this is the final scan result for this scan session and
// |gms_core_notifications_disabled_devices| does not contain a given
// device, the device was not found in the scan, and there is no way of
// knowing whether that device has its notifications enabled or not.
bool device_no_longer_found =
is_final_scan_result &&
!ContainsDeviceWithId(it->first,
gms_core_notifications_disabled_devices);
if (device_enabled_notifications || device_no_longer_found) {
it = device_id_to_name_map_.erase(it);
names_changed = true;
} else {
++it;
}
}
if (names_changed)
SendDeviceNamesChangeEvent();
}
void GmsCoreNotificationsStateTrackerImpl::SendDeviceNamesChangeEvent() {
std::stringstream ss;
ss << "GmsCore notifications disabled device list changed. Current list: [";
if (!device_id_to_name_map_.empty()) {
for (const auto& map_entry : device_id_to_name_map_) {
ss << "{name: \"" << map_entry.second << "\", id: \""
<< multidevice::RemoteDeviceRef::TruncateDeviceIdForLogs(
map_entry.first)
<< "\"},";
}
// Move backward one character so that the final trailing comma will be
// replaced by the ']' character below.
ss.seekp(-1, ss.cur);
}
ss << "]";
PA_LOG(VERBOSE) << ss.str();
NotifyGmsCoreNotificationStateChanged();
}
} // namespace tether
} // namespace chromeos
| [
"sunny.nam@samsung.com"
] | sunny.nam@samsung.com |
77545a1eb52f3679a48d28699a1c9e4bb1f0d303 | a763f6505331d1c1823d0e8620cc2d5f83048486 | /wdm/capture/mini/bt848/pisces.cpp | e1ca9d3ef50bf3709d2613fe41a7d8c40031034f | [] | no_license | KernelPanic-OpenSource/Win2K3_NT_drivers | 1dc9ccd83e38299f6643ecfd996a5df1357cc912 | 1b5d2672673ff31b60ee4a5b96922ddbcc203749 | refs/heads/master | 2023-04-11T08:18:29.881663 | 2021-04-14T04:30:34 | 2021-04-14T04:30:34 | 357,772,205 | 12 | 5 | null | null | null | null | UTF-8 | C++ | false | false | 36,472 | cpp | // $Header: G:/SwDev/WDM/Video/bt848/rcs/Pisces.cpp 1.15 1998/05/04 23:48:53 tomz Exp $
#include "pisces.h"
#include <stdlib.h>
/*
*/
BtPisces::BtPisces( DWORD *xtals ) : Engine_(), Inited_( false ),
Even_( CAPTURE_EVEN, VF_Even,&COLOR_EVEN, &WSWAP_EVEN, &BSWAP_EVEN ),
Odd_( CAPTURE_ODD, VF_Odd, &COLOR_ODD, &WSWAP_ODD, &BSWAP_ODD ),
VBIE_( CAPTURE_VBI_EVEN ), VBIO_( CAPTURE_VBI_ODD ), Update_( false ),
nSkipped_( 0 ), Paused_( false ),
Starter_( ),
SyncEvenEnd1_( ),
SyncEvenEnd2_( ),
SyncOddEnd1_( ),
SyncOddEnd2_( ),
PsDecoder_( xtals ),
dwPlanarAdjust_( 0 ),
CONSTRUCT_COLORCONTROL,
CONSTRUCT_INTERRUPTSTATUS,
CONSTRUCT_INTERRUPTMASK,
CONSTRUCT_CONTROL,
CONSTRUCT_CAPTURECONTROL,
CONSTRUCT_COLORFORMAT,
CONSTRUCT_GPIOOUTPUTENABLECONTROL,
CONSTRUCT_GPIODATAIO
{
Trace t("BtPisces::BtPisces()");
Init();
}
BtPisces::~BtPisces()
{
Trace t("BtPisces::~BtPisces()");
Engine_.Stop();
InterruptMask = 0;
InterruptStatus = AllFs;
// prevent risc program destructor from gpf-ing
SyncEvenEnd1_.SetParent( NULL );
SyncEvenEnd2_.SetParent( NULL );
SyncOddEnd1_.SetParent( NULL );
SyncOddEnd2_.SetParent( NULL );
// free the association array now
int ArrSize = sizeof( InterruptToIdx_ ) / sizeof( InterruptToIdx_ [0] );
while ( --ArrSize >= 0 )
delete InterruptToIdx_ [ArrSize];
// now is the Skippers_' turn
ArrSize = sizeof( Skippers_ ) / sizeof( Skippers_ [0] );
while ( --ArrSize >= 0 )
delete Skippers_ [ArrSize];
}
/* Method: BtPisces::GetIdxFromStream
* Purpose: Returns starting index in the program array for a field
* Input: aStream: StreamInfo & - reference
* Output: int : Index
*/
int BtPisces::GetIdxFromStream( Field &aStream )
{
Trace t("BtPisces::GetIdxFromStream()");
switch ( aStream.GetStreamID() ) {
case VS_Field1:
return OddStartLocation;
case VS_Field2:
return EvenStartLocation;
case VS_VBI1:
return VBIOStartLocation;
case VS_VBI2:
return VBIEStartLocation;
default:
return 0;
}
}
/* Method: BtPisces::CreateSyncCodes
* Purpose: Creates the risc programs with sync codes needed between data risc
* programs
* Input: None
* Output: ErrorCode
*/
bool BtPisces::CreateSyncCodes()
{
Trace t("BtPisces::CreateSyncCodes()");
bool bRet = SyncEvenEnd1_.Create( SC_VRE ) == Success &&
SyncEvenEnd2_.Create( SC_VRE ) == Success &&
SyncOddEnd1_.Create( SC_VRO ) == Success &&
SyncOddEnd2_.Create( SC_VRO ) == Success &&
Starter_.Create( SC_VRO ) == Success;
DebugOut((1, "*** BtPisces::CreateSyncCodes SyncEvenEnd1_(%x)\n", &SyncEvenEnd1_));
DebugOut((1, "*** BtPisces::CreateSyncCodes SyncEvenEnd2_(%x)\n", &SyncEvenEnd2_));
DebugOut((1, "*** BtPisces::CreateSyncCodes SyncOddEnd1_(%x)\n", &SyncOddEnd1_));
DebugOut((1, "*** BtPisces::CreateSyncCodes SyncOddEnd2_(%x)\n", &SyncOddEnd2_));
DebugOut((1, "*** BtPisces::CreateSyncCodes Starter_(%x)\n", &Starter_));
return( bRet );
}
/* Method: BtPisces::Init
* Purpose: Performs all necessary initialization
* Input: None
* Output: None
*/
void BtPisces::Init()
{
Trace t("BtPisces::Init()");
InterruptStatus = AllFs;
InterruptStatus = 0;
GAMMA = 1;
// initialize the arrays
CreatedProgs_.Clear() ;
ActiveProgs_.Clear() ;
// fill in the skippers array and make each program a 'skipper'
DataBuf buf;
// [!!!] [TMZ]
// Engine_.CreateProgram constants look questionable
for ( int i = 0; i < sizeof( Skippers_ ) / sizeof( Skippers_ [0] ); i++ ) {
if ( i & 1 ) {
MSize s( 10, 10 );
Skippers_ [i] = Engine_.CreateProgram( s, 10 * 2, CF_VBI, buf, true, 0, false );
DebugOut((1, "Creating Skipper[%d] == %x\n", i, Skippers_[i]));
Engine_.Skip( Skippers_ [i] );
} else {
MSize s( 768, 12 );
// now create skippers for the VBI streams
Skippers_ [i] = Engine_.CreateProgram( s, 768 * 2, CF_VBI, buf, true, 0, false );
DebugOut((1, "Creating Skipper[%d] == %x\n", i, Skippers_[i]));
}
if ( !Skippers_ [i] )
return;
}
// create associations between Created and Skippers
int link = 0;
for ( i = 0; i < sizeof( SkipperIdxArr_ ) / sizeof( SkipperIdxArr_ [0] ); i++ ) {
SkipperIdxArr_ [i] = link;
i += link & 1; // advance past the sync program entry
link++;
}
// fill in constant elements; see the table in the .h file
CreatedProgs_ [2] = &SyncOddEnd1_;
CreatedProgs_ [8] = &SyncOddEnd2_;
CreatedProgs_ [5] = &SyncEvenEnd1_;
CreatedProgs_ [11] = &SyncEvenEnd2_;
// set corresponding sync bits
if ( !CreateSyncCodes() )
return;
// initialize association array now
int ArrSize = sizeof( InterruptToIdx_ ) / sizeof( InterruptToIdx_ [0] );
while ( --ArrSize >= 0 ) {
if ( ( InterruptToIdx_ [ArrSize] = new IntrIdxAss() ) == 0 )
return;
}
Even_.SetFrameRate( 333667 );
Odd_. SetFrameRate( 333667 );
VBIE_.SetFrameRate( 333667 );
VBIO_.SetFrameRate( 333667 );
Odd_. SetStreamID( VS_Field1 );
Even_.SetStreamID( VS_Field2 );
VBIO_.SetStreamID( VS_VBI1 );
VBIE_.SetStreamID( VS_VBI2 );
// finally, can wipe out the prespiration from the forehead
Inited_ = true;
}
/* Method: BtPisces::AssignIntNumbers
* Purpose: Assigns numbers to RISC programs that generate interrupt
* Input: None
* Output: None
*/
void BtPisces::AssignIntNumbers()
{
Trace t("BtPisces::AssignIntNumbers()");
int IntrCnt = 0;
int limit = ActiveProgs_.NumElements() ;
int idx;
// initialize InterruptToIdx_ array
for ( idx = 0; idx < limit; idx++ ) {
IntrIdxAss item( idx, -1 );
*InterruptToIdx_ [idx] = item;
}
// assign numbers in front of starting program
bool first = true;
for ( idx = 0; idx < (int) ActiveProgs_.NumElements() ; idx++ ) {
RiscPrgHandle pProg = ActiveProgs_ [idx];
//if not skipped and generates an interrupt assign number
if ( pProg && pProg->IsInterrupting() ) {
if ( first == true ) {
first = false;
pProg->ResetStatus();
Skippers_ [SkipperIdxArr_ [idx] ]->ResetStatus();
} else {
pProg->SetToCount();
Skippers_ [SkipperIdxArr_ [idx] ]->SetToCount();
}
IntrIdxAss item( IntrCnt, idx );
*InterruptToIdx_ [IntrCnt] = item;
IntrCnt++;
}
}
}
/* Method: BtPisces::LinkThePrograms
* Purpose: Creates links between the created programs
* Input: None
* Output: None
*/
void BtPisces::LinkThePrograms()
{
Trace t("BtPisces::LinkThePrograms()");
DebugOut((1, "*** Linking Programs\n"));
RiscPrgHandle hParent = ActiveProgs_.First(),
hChild = NULL,
hVeryFirst = NULL,
hLastChild = NULL ;
if (hParent) {
if ( hParent->IsSkipped() ) {
int idx = ActiveProgs_.GetIndex(hParent) ;
hParent = Skippers_ [SkipperIdxArr_ [idx] ] ;
}
while (hParent) {
if (!hVeryFirst)
hVeryFirst = hParent ;
if ( hChild = ActiveProgs_.Next()) {
if ( hChild->IsSkipped() ) {
int idx = ActiveProgs_.GetIndex(hChild) ;
hChild = Skippers_ [SkipperIdxArr_ [idx] ] ;
}
hLastChild = hChild;
Engine_.Chain( hParent, hChild ) ;
}
hParent = hChild ;
}
// initial jump
Engine_.Chain( &Starter_, hVeryFirst ) ;
// now create the loop
Engine_.Chain( hLastChild ? hLastChild : hVeryFirst, hVeryFirst ) ;
}
}
/* Method: BtPisces::ProcessSyncPrograms()
* Purpose: This function unlinks the helper sync programs
* Input: None
* Output: None
*/
void BtPisces::ProcessSyncPrograms()
{
Trace t("BtPisces::ProcessSyncPrograms()");
for ( int i = 0; i < (int) ActiveProgs_.NumElements(); i += ProgsWithinField ) {
if ( !ActiveProgs_ [i] && !ActiveProgs_ [i+1] ) {
ActiveProgs_ [i+2] = NULL;
} else {
ActiveProgs_ [i+2] = CreatedProgs_ [i+2];
}
}
}
/* Method: BtPisces::ProcessPresentPrograms
* Purpose:
* Input: None
* Output: None
*/
void BtPisces::ProcessPresentPrograms()
{
Trace t("BtPisces::ProcessPresentPrograms()");
// link in/out helper sync programs
ProcessSyncPrograms();
// and now is time to cross link the programs
LinkThePrograms();
// and now figure out the numbers programs use for interrupts
AssignIntNumbers();
}
/* Method: BtPisces::AddProgram
* Purpose: Creates new RISC program and inserts it in the chain at a proper place
* Input: aStream: StreamInfo & - reference to the stream to add a program for
* NumberToAdd: int - number of programs to add
* Output:
* Note: Basically this internal function performs a loop 2 times
* //4. Tries to get another buffer to establish double buffering
* //5. If buffer is available it creates another RISC program with it
* //6. Then it has to link the program in...
*/
RiscPrgHandle BtPisces::AddProgram( Field &ToStart, int NumberToAdd )
{
Trace t("BtPisces::AddProgram()");
DebugOut((1, "BtPisces::AddProgram()\n"));
int StartIdx = GetIdxFromStream( ToStart );
SyncCode Sync;
int SyncIdx;
bool rsync;
if ( StartIdx <= OddStartLocation ) {
Sync = SC_VRO;
SyncIdx = OddSyncStartLoc;
rsync = false;
} else {
Sync = SC_VRE;
SyncIdx = EvenSyncStartLoc;
rsync = bool( StartIdx == EvenStartLocation );
}
// have to know what is the size of the image to produce
MRect r;
ToStart.GetDigitalWindow( r );
// RISC engine operates on absolute sizes, not rectangles
MSize s = r.Size();
int BufCnt = 0;
int Idx = StartIdx;
for ( ; BufCnt < NumberToAdd; BufCnt++ ) {
// init sync programs with a premise tha no data program exists
CreatedProgs_ [SyncIdx]->Create( Sync, true );
// obtain the next buffer from queue ( entry is removed from container )
DataBuf buf = ToStart.GetNextBuffer();
// can create a RISC program now.
RiscPrgHandle hProgram = Engine_.CreateProgram( s, ToStart.GetBufPitch(),
ToStart.GetColorFormat(), buf, ToStart.Interrupt_, dwPlanarAdjust_, rsync );
// store this program
CreatedProgs_ [Idx] = hProgram;
DebugOut((1, "Creating RiscProgram[%d] == %x\n", Idx, CreatedProgs_ [Idx]));
if ( !hProgram ) {
Idx -= DistBetweenProgs;
if ( Idx >= 0 ) {
// clean up previous program
Engine_.DestroyProgram( CreatedProgs_ [Idx] );
CreatedProgs_ [Idx] = NULL;
}
return NULL;
}
// make sure we unskip the program when buffer becomes available
if ( !buf.pData_ ) {
hProgram->SetSkipped(); // do not have enough buffers to support double buffering
nSkipped_++;
}
// assign stream to program; makes it easy during interrupt
hProgram->SetTag( &ToStart );
SyncIdx += DistBetweenProgs;
Idx += DistBetweenProgs; // skip the location intended for the other program
} /* endfor */
return CreatedProgs_ [StartIdx];
}
/* Method: BtPisces::Create
* Purpose: This functions starts the stream.
* Input: aStream: StreamInfo & - reference to a stream to start
* Output: Address of the Starter_
* Note: After the Start 2 entries in the CreatedProgs_ are created. Starting
* location is 4 for even and 1 for odd. Increment is 6. So if it is the first
* invocation and there is enough ( 2 ) buffers present entries [1] and [7]
* or [4] and [10] will be filled with newly created RISC programs. When programs
* exist for one field only they are doubly linked. When programs exist for
* both fields they alternate, i.e. 0->2->1->3->0... When one of the fields
* has 1 program only, programs are linked like this: 0->2->1->0->2...(numbers
* are indexes in the CreatedProgs_ array ). Alternating programs makes for
* maximum frame rate.
*/
ErrorCode BtPisces::Create( Field &ToCreate )
{
Trace t("BtPisces::Create()");
// running full-steam, nothing to create
if ( ToCreate.IsStarted() == true )
return Success;
int StartIdx = GetIdxFromStream( ToCreate );
if ( CreatedProgs_ [StartIdx] )
return Success; // not running yet, but exists
// call into internal function that adds new RISC program
if ( ! AddProgram( ToCreate, MaxProgsForField ) )
return Fail;
return Success;
}
/* Method: BtPisces::Start
* Purpose: Starts given stream ( by putting in in the Active_ array
* Input: ToStart: Field &
*/
void BtPisces::Start( Field & ToStart )
{
Trace t("BtPisces::Start()");
// DebugOut((1, "BtPisces::Start\n"));
if ( ToStart.IsStarted() == true )
return;
// all we need to do at this point is to create a proper starter
// and link the programs in.
int idx = GetIdxFromStream( ToStart );
// this loop will enable LinkThePrograms to see programs for this stream
for ( int i = 0; i < MaxProgsForField; i++, idx += DistBetweenProgs ) {
ActiveProgs_ [idx] = CreatedProgs_ [idx];
}
// all I want to do at this point is call Restart.
// do not signal the buffers
Update_ = false;
Restart();
Update_ = true;
}
/* Method: BtPisces::Stop
* Purpose: This function stops a stream. Called when PAUSE SRB is received
* Input: aStream: StreamInfo & - reference to a stream to start
* Output: None
*/
void BtPisces::Stop( Field &ToStop )
{
Trace t("BtPisces::Stop()");
// DebugOut((1, "BtPisces::Stop\n"));
Engine_.Stop(); // no more interrupts
int StartIdx = GetIdxFromStream( ToStop );
// prevent unneeded syncronization interrupts
IMASK_SCERW = 0;
// it is time to pause the stream now
ToStop.Stop();
bool Need2Restart = false;
// go through the array of programs and killing ones for this field (stream)
for ( int i = 0; i < MaxProgsForField; i++, StartIdx += DistBetweenProgs ) {
RiscPrgHandle ToDie = CreatedProgs_ [StartIdx];
if ( !ToDie ) // this should never happen
continue;
if ( ToDie->IsSkipped() )
nSkipped_--;
DebugOut((1, "about to destroy idx = %d\n", StartIdx ) );
Engine_.DestroyProgram( ToDie );
CreatedProgs_ [StartIdx] = NULL;
ActiveProgs_ [StartIdx] = NULL; // in case Pause wasn't called
Need2Restart = true;
} /* endfor */
// nobody's around anymore
if ( !CreatedProgs_.CountDMAProgs() ) {
Engine_.Stop();
InterruptMask = 0;
InterruptStatus = AllFs;
nSkipped_ = 0;
} else {
if ( Need2Restart ) {
Restart(); // relink the programs and start ones that are alive
IMASK_SCERW = 1; // re-enable the sync error interrupts
}
}
}
/* Method: BtPisces::Pause
* Purpose: This function stops a stream. Called when PAUSE SRB is received
* Input: aStream: Field & - reference to a stream to start
* Output: None
*/
void BtPisces::Pause( Field &ToPause )
{
Trace t("BtPisces::Pause()");
// DebugOut((1, "BtPisces::Pause\n"));
Engine_.Stop(); // no more interrupts
if ( !ToPause.IsStarted() )
return;
int StartIdx = GetIdxFromStream( ToPause );
// prevent unneeded syncronization interrupts
IMASK_SCERW = 0;
// it is time to pause the stream now
// ToPause.Stop(); - done in Restart
// go through the array of programs and killing ones for this field (stream)
for ( int i = 0; i < MaxProgsForField; i++, StartIdx += DistBetweenProgs ) {
ActiveProgs_ [StartIdx] = NULL;
} /* endfor */
Restart(); // relink the programs and start ones that are alive
}
/* Method: BtPisces::PairedPause
* Purpose: This is a hacky function that pauses 2 streams at once
* Input: idx: index of the second program in the second field
* Output: None
*/
void BtPisces::PairedPause( int idx )
{
Trace t("BtPisces::PairedPause()");
// DebugOut((1, "BtPisces::PairedPause\n"));
Engine_.Stop(); // no more interrupts
// go through the array of programs and killing ones for this field (stream)
for ( int i = 0; i < MaxProgsForField; i++, idx -= DistBetweenProgs ) {
ActiveProgs_ [idx] = NULL;
ActiveProgs_ [idx-ProgsWithinField] = NULL;
} /* endfor */
Restart(); // relink the programs and start ones that are alive
}
/* Method: BtPisces::GetStarted
* Purpose: Figures out the channels that are started
* Input:
* Output: None
*/
void BtPisces::GetStarted( bool &EvenWasStarted, bool &OddWasStarted,
bool &VBIEWasStarted, bool &VBIOWasStarted )
{
Trace t("BtPisces::GetStarted()");
VBIEWasStarted = ( ActiveProgs_ [VBIEStartLocation] ? TRUE : FALSE);
EvenWasStarted = ( ActiveProgs_ [EvenStartLocation] ? TRUE : FALSE);
VBIOWasStarted = ( ActiveProgs_ [VBIOStartLocation] ? TRUE : FALSE);
OddWasStarted = ( ActiveProgs_ [OddStartLocation] ? TRUE : FALSE);
}
/* Method: BtPisces::RestartStreams
* Purpose: Restarts streams that were started
* Input:
* Output: None
*/
void BtPisces::RestartStreams( bool EvenWasStarted, bool OddWasStarted,
bool VBIEWasStarted, bool VBIOWasStarted )
{
Trace t("BtPisces::RestartStream()");
// vbi programs are first to execute, so enable them first
if ( VBIOWasStarted )
VBIO_.Start();
if ( OddWasStarted )
Odd_.Start();
if ( VBIEWasStarted )
VBIE_.Start();
if ( EvenWasStarted )
Even_.Start();
}
/* Method: BtPisces::CreateStarter
* Purpose: Creates proper sync code for the bootstrap program
* Input: EvenWasStarted: bool
* Output: None
*/
void BtPisces::CreateStarter( bool EvenWasStarted )
{
Trace t("BtPisces::CreateStarter()");
Starter_.Create( EvenWasStarted ? SC_VRE : SC_VRO, true );
DebugOut((1, "*** BtPisces::CreateStarter(%x) buf(%x)\n", &Starter_ , Starter_.GetPhysProgAddr( )));
}
/* Method: BtPisces::Restart
* Purpose: Restarts the capture process. Called by ISR and Stop()
* Input: None
* Output: None
*/
void BtPisces::Restart()
{
Trace t("BtPisces::Restart()");
bool EvenWasStarted, OddWasStarted, VBIEWasStarted, VBIOWasStarted;
GetStarted( EvenWasStarted, OddWasStarted, VBIEWasStarted, VBIOWasStarted );
DebugOut((2, "BtPisces::Restart - Even WasStarted (%d)\n", EvenWasStarted));
DebugOut((2, "BtPisces::Restart - Odd WasStarted (%d)\n", OddWasStarted));
DebugOut((2, "BtPisces::Restart - VBIE WasStarted (%d)\n", VBIEWasStarted));
DebugOut((2, "BtPisces::Restart - VBIO WasStarted (%d)\n", VBIOWasStarted));
Engine_.Stop(); // No more interrupts!
Odd_.Stop();
Even_.Stop();
VBIE_.Stop();
VBIO_.Stop();
Engine_.Stop(); // No more interrupts!
#if 1
if ( OddWasStarted )
{
Odd_.CancelSrbList();
}
if ( EvenWasStarted )
{
Even_.CancelSrbList();
}
if ( VBIEWasStarted )
{
VBIE_.CancelSrbList();
}
if ( VBIOWasStarted )
{
VBIO_.CancelSrbList();
}
#endif
// this will never happen, probably
if ( !EvenWasStarted && !OddWasStarted && !VBIEWasStarted && !VBIOWasStarted )
return;
InterruptStatus = AllFs; // clear all the status bits
CreateStarter( bool( EvenWasStarted || VBIEWasStarted ) );
ProcessPresentPrograms();
// DumpRiscPrograms();
Engine_.Start( Starter_ );
RestartStreams( EvenWasStarted, OddWasStarted, VBIEWasStarted, VBIOWasStarted );
OldIdx_ = -1;
InterruptMask = RISC_I | FBUS_I | OCERR_I | SCERR_I |
RIPERR_I | PABORT_I | EN_TRITON1_BUG_FIX;
}
/* Method: BtPisces::Skip
* Purpose: Forces a given program to be skipped by the RISC engine
* Input: ToSkip: RiscPrgHandle - program to be skipped
* Output: None
* Note: If the number of skipped programs equals total number of programs, the
* RISC engine is stopped
*/
void BtPisces::Skip( int idx )
{
Trace t("BtPisces::Skip()");
// get the program and skip it
RiscPrgHandle ToSkip = ActiveProgs_ [idx];
if ( ToSkip->IsSkipped() )
return;
ToSkip->SetSkipped();
nSkipped_++;
//skip by linking the Skipper_ in instead of the skippee
RiscPrgHandle SkipeeParent = ToSkip->GetParent();
RiscPrgHandle SkipeeChild = ToSkip->GetChild();
// get the skipper for this program
RiscPrgHandle pSkipper = Skippers_ [SkipperIdxArr_ [idx] ];
Engine_.Chain( pSkipper, SkipeeChild );
Engine_.Chain( SkipeeParent, pSkipper );
DebugOut((1, "BtPisces::Skipped %d Skipper %d\n", idx, SkipperIdxArr_ [idx] ) );
}
inline bool IsFirst( int idx )
{
Trace t("BtPisces::IsFirst()");
return bool( idx == OddStartLocation || idx == VBIOStartLocation ||
idx - DistBetweenProgs == OddStartLocation ||
idx - DistBetweenProgs == VBIOStartLocation );
}
inline bool IsLast( int idx )
{
Trace t("BtPisces::IsLast()");
return bool((idx == (VBIEStartLocation + DistBetweenProgs)) ||
(idx == (EvenStartLocation + DistBetweenProgs)));
}
/* Method: BtPisces::GetPassed
* Purpose: Calculates number of programs that have executed since last interrupt
* Input: None
* Output: int: number of passed
*/
int BtPisces::GetPassed()
{
Trace t("BtPisces::GetPassed()");
// figure out which RISC program caused an interrupt
int ProgCnt = RISCS;
int numActive = ActiveProgs_.CountDMAProgs() ;
if ( ProgCnt >= numActive ) {
DebugOut((1, "ProgCnt = %d, larger than created\n", ProgCnt ) );
}
// now see how many programs have interrupted since last time and process them all
if ( ProgCnt == OldIdx_ ) {
DebugOut((1, "ProgCnt is the same = %d\n", ProgCnt ) );
}
int passed;
if ( ProgCnt < OldIdx_ ) {
passed = numActive - OldIdx_ + ProgCnt; // you spin me like a record, baby - round, round...
} else
passed = ProgCnt - OldIdx_;
// The following line of code was VERY bad !!!
// This caused crashes when the system got busy and had interrupts backed up.
// if ( ProgCnt == OldIdx_ )
// passed = numActive;
OldIdx_ = ProgCnt;
return passed;
}
/* Method: BtPisces::GetProgram
* Purpose: Finds a RISC program based on its position
* Input: None
* Output: None
*/
inline RiscPrgHandle BtPisces::GetProgram( int pos, int &idx )
{
Trace t("BtPisces::GetProgram()");
int nActiveProgs = ActiveProgs_.CountDMAProgs( );
if ( nActiveProgs == 0 )
{
idx = 0;
return ( NULL );
}
IntrIdxAss *item;
item = InterruptToIdx_ [ pos % nActiveProgs ];
idx = item->Idx;
DEBUG_ASSERT( idx != -1 );
return (idx == -1) ? NULL : ActiveProgs_ [idx];
}
/* Method: BtPisces::ProcessRISCIntr
* Purpose: Handles interrupts caused by the RISC programs
* Input: None
* Output: None
*/
void BtPisces::ProcessRISCIntr()
{
PHW_STREAM_REQUEST_BLOCK gpCurSrb = 0;
Trace t("BtPisces::ProcessRISCIntr()");
// this line must be before GetPassed(), as OldIdx_ is changed by that function
int pos = OldIdx_ + 1;
// measure elapsed time
int passed = GetPassed();
DebugOut((1, " passed = %d\n", passed ) );
while ( passed-- > 0 ) {
int idx;
RiscPrgHandle Rspnsbl = GetProgram( pos, idx );
pos++;
// last chance to prevent a disaster...
if ( !Rspnsbl || !Rspnsbl->IsInterrupting() ) {
DebugOut((1, " no resp or not intr\n" ) );
continue;
}
// get conveniently saved stream from the program
Field &Interrupter = *(Field *)Rspnsbl->GetTag();
gpCurSrb = Rspnsbl->pSrb_; // [TMZ] [!!!]
DebugOut((1, "'idx(%d), pSrb(%x)\n", idx, gpCurSrb));
bool paired = Interrupter.GetPaired();
if ( Interrupter.IsStarted() != true ) {
DebugOut((1, " not started %d\n", idx ) );
continue;
}
if ( IsFirst( idx ) && paired ) {
DebugOut((1, " continue pair %d\n", idx ) );
continue;
}
LONGLONG *pL = (LONGLONG *)Rspnsbl->GetDataBuffer();
if ( !pL )
{
DebugOut((1, "null buffer in interrupt, ignore this interrupt\n"));
//continue;
}
else
{
DebugOut((1, "good buffer in interrupt\n"));
}
// now make sure all buffers are written to
if ( !pL || Rspnsbl->IsSkipped() ) {
// want to call notify, so ProcessBufferAtInterrupt is called
DebugOut((1, " skipped %d\n", idx ) );
Interrupter.Notify( (PVOID)idx, true );
Interrupter.SetReady( true );
} else {
BOOL test1 = FALSE;
BOOL test2 = FALSE;
BOOL test3 = FALSE;
if ( 1
//*pL != 0xAAAAAAAA33333333 && (test1 = TRUE) &&
//*(pL + 1) != 0xBBBBBBBB22222222 && (test2 = TRUE) &&
//Interrupter.GetReady() && (test3 = TRUE)
) {
// here buffer is available
DebugOut((1, " notify %d, addr - %x\n", idx,
Rspnsbl->GetDataBuffer() ) );
//#pragma message("*** be very carefull zeroing buffers!!!")
//Rspnsbl->SetDataBuffer( 0 ); // [TMZ] try to fix buffer re-use bug
Interrupter.Notify( (PVOID)idx, false );
Interrupter.SetReady( true );
} else {
// add code for the paired streams here
DebugOut((1, " not time %d (%d, %d, %d)\n", idx , test1, test2, test3));
// this if/else takes care of this cases:
// 1. first buffer for a field is not written to
// 2. second buffer for a field is written to ( this can happen when
// both programs were updated at the same time, but the timing was
// such that first did not start executing, but second was );
// so this if/else prevents sending buffers back out of order
if ( Interrupter.GetReady() ) // it is always true before it is ever false
Interrupter.SetReady( false );
else
// make sure that things are correct when the loop is entered later
// the field must be set to 'ready'
Interrupter.SetReady( true );
}
}
} /* endwhile */
}
/* Method: BtPiscess::ProcessBufferAtInterrupt
* Purpose: Called by a video channel to perform risc program modifications
* if needed
* Input: pTag: PVOID - pointer to some data ( risc program pointer )
* Output: None
*/
void BtPisces::ProcessBufferAtInterrupt( PVOID pTag )
{
Trace t("BtPisces::ProcessBufferAtInterrupt()");
int idx = (int)pTag;
RiscPrgHandle Rspnsbl = ActiveProgs_ [idx];
if ( !Rspnsbl ) {
DebugOut((1, "PBAI: no responsible\n"));
return; // can this really happen ??
}
// get conveniently saved field from the program
Field &Interrupter = *(Field *)Rspnsbl->GetTag();
// see if there is a buffer in the queue and get it
DataBuf buf = Interrupter.GetNextBuffer();
DebugOut((1, "Update %d %x\n", idx, buf.pData_ ) );
// if buffer is not available skip the program
if ( !buf.pData_ ) {
DebugOut((1, "Buffer not available, skipping %d\n", idx ) );
Skip( idx );
} else {
if ( Rspnsbl->IsSkipped() )
nSkipped_--;
Engine_.ChangeAddress( Rspnsbl, buf );
LinkThePrograms();
}
}
/* Method: BtPisces::Interrupt
* Purpose: Called by ISR to initiate the processing of an interrupt
* Input: None
* Output: None
*/
State BtPisces::Interrupt()
{
Trace t("BtPisces::Interrupt()");
DebugOut((2, "BtPisces::Interrupt()\n"));
extern BYTE *gpjBaseAddr;
DWORD IntrStatus = *(DWORD*)(gpjBaseAddr+0x100);
State DidWe = Off;
if ( IntrStatus & RISC_I ) {
DebugOut((2, "RISC_I\n"));
ProcessRISCIntr();
*(DWORD*)(gpjBaseAddr+0x100) = RISC_I; // reset the status bit
DidWe = On;
}
if ( IntrStatus & FBUS_I ) {
DebugOut((2, "FBUS\n"));
*(DWORD*)(gpjBaseAddr+0x100) = FBUS_I; // reset the status bit
DidWe = On;
}
if ( IntrStatus & FTRGT_I ) {
DebugOut((2, "FTRGT\n"));
*(DWORD*)(gpjBaseAddr+0x100) = FTRGT_I; // reset the status bit
DidWe = On; //[TMZ]
}
if ( IntrStatus & FDSR_I ) {
DebugOut((2, "FDSR\n"));
*(DWORD*)(gpjBaseAddr+0x100) = FDSR_I; // reset the status bit
DidWe = On; //[TMZ]
}
if ( IntrStatus & PPERR_I ) {
DebugOut((2, "PPERR\n"));
*(DWORD*)(gpjBaseAddr+0x100) = PPERR_I; // reset the status bit
DidWe = On; //[TMZ]
}
if ( IntrStatus & RIPERR_I ) {
DebugOut((2, "RIPERR\n"));
*(DWORD*)(gpjBaseAddr+0x100) = RIPERR_I; // reset the status bit
Restart();
DidWe = On;
}
if ( IntrStatus & PABORT_I ) {
DebugOut((2, "PABORT\n"));
*(DWORD*)(gpjBaseAddr+0x100) = PABORT_I; // reset the status bit
DidWe = On;
}
if ( IntrStatus & OCERR_I ) {
DebugOut((2, "OCERR\n"));
DidWe = On;
DebugOut((0, "Stopping RiscEngine due to OCERR\n")); // [!!!] [TMZ] why not restart?
Engine_.Stop();
*(DWORD*)(gpjBaseAddr+0x100) = OCERR_I; // reset the status bit
}
if ( IntrStatus & SCERR_I ) {
DebugOut((0, "SCERR\n"));
DidWe = On;
*(DWORD*)(gpjBaseAddr+0x100) = SCERR_I; // reset the status bit
Restart(); // [TMZ] [!!!] this royally screws us over sometimes, figure it out.
*(DWORD*)(gpjBaseAddr+0x100) = SCERR_I; // reset the status bit
}
return DidWe;
}
// resource allocation group
/* Method: BtPisces::AllocateStream
* Purpose: This function allocates a stream for use by a video channel
* Input: StrInf: StreamInfo & - reference to the stream information structure
* Output:
*/
ErrorCode BtPisces::AllocateStream( Field *&ToAllocate, VideoStream st )
{
Trace t("BtPisces::AllocateStream()");
switch ( st ) {
case VS_Field1:
ToAllocate = &Odd_;
break;
case VS_Field2:
ToAllocate = &Even_;
break;
case VS_VBI1:
ToAllocate = &VBIO_;
break;
case VS_VBI2:
ToAllocate = &VBIE_;
break;
}
return Success;
}
/* Method: BtPisces::SetBrightness
* Purpose: Changes brightness of the captured image
* Input:
* Output:
*/
void BtPisces::SetBrightness( DWORD value )
{
Trace t("BtPisces::SetBrightness()");
PsDecoder_.SetBrightness( value );
}
/* Method: BtPisces::SetSaturation
* Purpose:
* Input:
* Output:
*/
void BtPisces::SetSaturation( DWORD value )
{
Trace t("BtPisces::SetSaturation()");
PsDecoder_.SetSaturation( value );
}
/* Method: BtPisces::SetConnector
* Purpose:
* Input:
* Output:
*/
void BtPisces::SetConnector( DWORD value )
{
Trace t("BtPisces::SetConnector()");
PsDecoder_.SetVideoInput( Connector( value ) );
}
/* Method: BtPisces::SetContrast
* Purpose:
* Input:
* Output:
*/
void BtPisces::SetContrast( DWORD value )
{
Trace t("BtPisces::SetContrast()");
PsDecoder_.SetContrast( value );
}
/* Method: BtPisces::SetHue
* Purpose:
* Input:
* Output:
*/
void BtPisces::SetHue( DWORD value )
{
Trace t("BtPisces::SetHue()");
PsDecoder_.SetHue( value );
}
/* Method: BtPisces::SetSVideo
* Purpose:
* Input:
* Output:
*/
void BtPisces::SetSVideo( DWORD )
{
Trace t("BtPisces::SetSVideo()");
}
/* Method: BtPisces::
* Purpose:
* Input: value: DWORD
* Output:
*/
void BtPisces::SetFormat( DWORD value )
{
Trace t("BtPisces::SetFormat()");
PsDecoder_.SetVideoFormat( VideoFormat( value ) );
// let the scaler know format has changed
Even_.VideoFormatChanged( VideoFormat( value ) );
Odd_.VideoFormatChanged( VideoFormat( value ) );
}
/* Method: BtPisces::GetSaturation
* Purpose:
* Input: pData: PLONG
* Output:
*/
LONG BtPisces::GetSaturation()
{
Trace t("BtPisces::GetSaturation()");
return PsDecoder_.GetSaturation();
}
/* Method: BtPisces::GetHue
* Purpose:
* Input: pData: PLONG
* Output:
*/
LONG BtPisces::GetHue()
{
Trace t("BtPisces::GetHue()");
return PsDecoder_.GetHue();
}
/* Method: BtPisces::GetBrightness
* Purpose:
* Input: pData: PLONG
* Output:
*/
LONG BtPisces::GetBrightness()
{
Trace t("BtPisces::GetBrightness()");
return PsDecoder_.GetBrightness();
}
/* Method: BtPisces::GetSVideo
* Purpose:
* Input: pData: PLONG
* Output:
*/
LONG BtPisces::GetSVideo()
{
Trace t("BtPisces::GetSVideo()");
return 0;
}
/* Method: BtPisces::GetContrast
* Purpose:
* Input: pData: PLONG
* Output:
*/
LONG BtPisces::GetContrast()
{
Trace t("BtPisces::GetContrast()");
return PsDecoder_.GetContrast();
}
/* Method: BtPisces::GetFormat
* Purpose:
* Input: pData: PLONG
* Output:
*/
LONG BtPisces::GetFormat()
{
Trace t("BtPisces::GetFormat()");
return PsDecoder_.GetVideoFormat();
}
/* Method: BtPisces::GetConnector
* Purpose:
* Input: pData: PLONG
* Output:
*/
LONG BtPisces::GetConnector()
{
Trace t("BtPisces::GetConnector()");
return PsDecoder_.GetVideoInput();
}
// scaler group
/* Method: BtPisces::SetAnalogWindow
* Purpose:
* Input:
* Output:
*/
ErrorCode BtPisces::SetAnalogWindow( MRect &r, Field &aField )
{
Trace t("BtPisces::SetAnalogWindow()");
return aField.SetAnalogWindow( r );
}
/* Method: BtPisces::SetDigitalWindow
* Purpose:
* Input:
* Output:
*/
ErrorCode BtPisces::SetDigitalWindow( MRect &r, Field &aField )
{
Trace t("BtPisces::SetDigitalWindow()");
return aField.SetDigitalWindow( r );
}
// color space converter group
/* Method: BtPisces::SetPixelFormat
* Purpose:
* Input:
* Output:
*/
void BtPisces::SetPixelFormat( ColFmt aFormat, Field &aField )
{
Trace t("BtPisces::SetPixelFormat()");
aField.SetColorFormat( aFormat );
}
/* Method: BtPisces::GetPixelFormat
* Purpose:
* Input:
* Output:
*/
ColFmt BtPisces::GetPixelFormat( Field &aField )
{
Trace t("BtPisces::GetPixelFormat()");
return aField.GetColorFormat();
}
void BtPisces::TurnVFilter( State s )
{
Trace t("BtPisces::TurnVFilter()");
Even_.TurnVFilter( s );
Odd_.TurnVFilter( s );
}
/* Method:
* Purpose: returns video standards supported by the board
*/
LONG BtPisces::GetSupportedStandards()
{
Trace t("BtPisces::GetSupportedStandards()");
return PsDecoder_.GetSupportedStandards();
}
void BtPisces::DumpRiscPrograms()
{
LONG x;
// Dump the links
DebugOut((0, "------------------------------------------------\n"));
for( x = 0; x < 12; x++ )
{
if ( CreatedProgs_[x] )
{
DebugOut((0, "Created #%02d addr(%x) paddr(%x) jaddr(%x)\n", x, CreatedProgs_[x], CreatedProgs_[x]->GetPhysProgAddr( ), *(CreatedProgs_[x]->pChainAddress_ + 1)));
}
}
for( x = 0; x < 8; x++ )
{
if ( Skippers_[x] )
{
DebugOut((0, "Skipper #%02d addr(%x) paddr(%x) jaddr(%x)\n", x, Skippers_[x], Skippers_[x]->GetPhysProgAddr( ), *(Skippers_[x]->pChainAddress_ + 1)));
}
}
DebugOut((0, "------------------------------------------------\n"));
return ;
/////////////////////////////////////////////////
for( x = 0; x < 12; x++ ) {
DebugOut((0, "Active Program # %d(%x) buf(%x)\n", x, ActiveProgs_[x], ActiveProgs_[x]?ActiveProgs_[x]->GetPhysProgAddr( ):-1));
}
for( x = 0; x < 12; x++ ) {
DebugOut((0, "Created Program # %d(%x) buf(%x)\n", x, CreatedProgs_[x], CreatedProgs_[x]?CreatedProgs_[x]->GetPhysProgAddr( ):-1));
}
for( x = 0; x < 8; x++ ) {
DebugOut((0, "Skipper Program # %d(%x) buf(%x)\n", x, Skippers_[x], Skippers_[x]?Skippers_[x]->GetPhysProgAddr( ):-1));
}
DebugOut((2, "---------------------------------\n"));
DebugOut((2, "Dumping ActiveProgs_\n"));
DebugOut((2, "---------------------------------\n"));
for( x = 0; x < 12; x++ ) {
DebugOut((1, "Active Program # %d\n", x));
ActiveProgs_[x]->Dump();
}
DebugOut((2, "---------------------------------\n"));
DebugOut((2, "Dumping CreatedProgs_\n"));
DebugOut((2, "---------------------------------\n"));
for( x = 0; x < 12; x++ ) {
DebugOut((1, "Created Program # %d\n", x));
CreatedProgs_[x]->Dump();
}
DebugOut((2, "---------------------------------\n"));
DebugOut((2, "Dumping Skippers_\n"));
DebugOut((2, "---------------------------------\n"));
for( x = 0; x < 8; x++ ) {
DebugOut((1, "Skipper Program # %d\n", x));
Skippers_[x]->Dump();
}
}
| [
"polarisdp@gmail.com"
] | polarisdp@gmail.com |
814fe61edbc954509e1ffa4815c9eb5951cf13e0 | f6be0b6d4641f91df4c7589414920dac09090f6a | /include/HexDetector.hh | 70ab37e7a8e6b82dd07ee134697f07b283590a27 | [] | no_license | piti118/Crystal | 21011d7251f4472e8218f3497d833325d7a96297 | 8e61dfd6791cff16ec050a5e8cc2aca4e2133561 | refs/heads/master | 2016-09-06T15:33:28.710746 | 2012-02-03T22:33:05 | 2012-02-03T22:33:05 | 2,444,831 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,595 | hh | #ifndef HexDetector_h
#define HexDetector_h 1
#include "G4VUserDetectorConstruction.hh"
#include "globals.hh"
#include <vector>
#include "Detector.hh"
#include "HexPosition.hh"
#include "G4Polyhedra.hh"
#include <cmath>
class G4Box;
class G4LogicalVolume;
class G4VPhysicalVolume;
class G4Material;
class G4UniformMagField;
class DetectorMessenger;
class HexDetector : public Detector
{
public:
HexDetector(const char* name,int nring,double hexsize);
~HexDetector();
const char* name;
int nring;
double hexsize;
double gap;
double crystal_length;
std::vector<HexPosition> posmap;
static const unsigned int idoffset = 10000;
virtual const char* getName(){return name;}
G4VPhysicalVolume* Construct();
G4ThreeVector randPos(){
G4double x=((double)std::rand()/(double)RAND_MAX)*2*hexsize-hexsize;
G4double y=((double)std::rand()/(double)RAND_MAX)*2*hexsize-hexsize;
G4double z=0.;
G4ThreeVector toReturn(x,y,z);
return toReturn;
}
inline unsigned int calorRing(int id){return posmap[id-idoffset].ringno;}
inline unsigned int calorSeg(int id){return posmap[id-idoffset].segmentno;}
bool inDetector(int id){
int order = id - idoffset;
return order >=0 && order < posmap.size();
}
void initPosMap();
virtual int calorL(int id){return posmap[id-idoffset].l;}
virtual int calorK(int id){return posmap[id-idoffset].k;}
//TODO: fix this
virtual double calorX(int id){
return posmap[id-idoffset].toXY(2*hexsize+gap).first;
}
virtual double calorY(int id){
return posmap[id-idoffset].toXY(2*hexsize+gap).second;
}
virtual int ringno(int id){return posmap[id-idoffset].ringno;}
virtual int segmentno(int id){return posmap[id-idoffset].segmentno;}
virtual std::vector<int> crystalList(){
std::vector<int> v;
for(int i=0;i<posmap.size();i++){
v.push_back(i+idoffset);
}
return v;
}
virtual void setCrystalLength(double length){
crystal_length=length;
}
private:
G4Material* LYSO;
G4Material* Air;
G4Box* world_box;
G4LogicalVolume* world_log;
G4VPhysicalVolume* world_pv;
std::vector<G4Polyhedra*> calor_box;
std::vector<G4LogicalVolume*> calor_log;
std::vector<G4VPhysicalVolume*> calor_pv;
inline double hexsize2r(double hexsize) const {double pi = std::atan(1)*4;return hexsize/std::cos(pi/6);}
private:
void DefineMaterials();
G4VPhysicalVolume* ConstructCalorimeter();
};
#endif
| [
"piti118@gmail.com"
] | piti118@gmail.com |
39c21f1fbc0d08db8902555c3f3477b9391461b5 | 767cc82b24c5e7400305774605874beda08933c6 | /src/SigMod/CombinedTrieNode.h | 2efbca02074637a59b323786c977169041e0264e | [] | no_license | filipxsikora/SIGMOD-2017 | 78a6c74a408d2f2072744795d0b827f0f50e5c8a | 9b06a4067a63b5192da1fda525a017da57518421 | refs/heads/master | 2020-03-29T20:14:12.493699 | 2018-09-28T06:22:20 | 2018-09-28T06:22:20 | 150,302,113 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 775 | h | #pragma once
#include "MemoryBuffer.h"
#include "HashTable.h"
#include "HashTableItem.h"
enum class TrieNodeMode { Trie, HashTable };
class CombinedTrieNode
{
public:
CombinedTrieNode(MemoryBuffer* memBuffer, TrieNodeMode mode);
~CombinedTrieNode();
CombinedTrieNode* AddNode(uint position, TrieNodeMode mode);
inline CombinedTrieNode* GetNextNode(uint position) { return mNextNode[position]; }
HashTable<HashTableItem*>* GetHashTable() { return mHashTable; }
inline uchar* GetData() { return mData; }
private:
uchar* mData;
CombinedTrieNode** mNextNode;
TrieNodeMode mMode;
HashTable<HashTableItem*>* mHashTable;
MemoryBuffer* mMemoryBuffer;
const int HASHTABLE_AVGITEMSIZE = 256;
const int HASHTABLE_ITEMCOUNT = 32;
const int HASHTABLE_BLOCKSIZE = 512;
}; | [
"filipxsikora@gmail.com"
] | filipxsikora@gmail.com |
a702000c7ed3ae8eb6c7d757fda4ed349ce5d677 | a75b09d874166f9cdfaede6acc5db348b05e8b60 | /Mes_tp/tpc_plus/exo1.cpp | 853062979b94b1cb77f8e6d87d8d76eb4e185aed | [] | no_license | keane-kane/c2-_py_js_csharp_and_others | 779f85aec7a48e371fff9605a1daca960da8f334 | 0760289a79a4fcefd056e4e7091dc5b6ad6aae5a | refs/heads/master | 2023-03-04T21:30:51.555102 | 2021-02-06T09:49:37 | 2021-02-06T09:49:37 | 336,498,554 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 567 | cpp | #include <iostream>
using namespace std;
void add(int s)
{
s++;
}
int main()
{ int s=10 ;
add(s);
cout<<s ;
return 0;
// /*int nbre1, nbre2;
// double somme, produit, reste;
// float quotient;
// cout<<"siasir deux nombre\n";
// cin>>nbre1>>nbre2;
// somme = nbre1 + nbre2;
// produit = nbre1*nbre2;
// quotient = nbre1/nbre2;
// reste = nbre1- nbre2;
//
// cout<<"la somme est de "<<somme<<"\n";
// cout<<"le produit est de "<<produit<<"\n";
// cout<<"le quotient est de "<<quotient<<"\n";
// cout<<"le reste est de "<<reste<<"\n";*/
//
//}
| [
"51829744+keane-kane@users.noreply.github.com"
] | 51829744+keane-kane@users.noreply.github.com |
4fc5deb8df491fb585c0e91ec136015d51025082 | 8e854323d86b97057ee199e545f508d933d3a5be | /src/test/governance_validators_tests.cpp | 037ef8a0a2f38c774b7d3689550d11eef8d900ca | [
"MIT"
] | permissive | julivn/.github | 362789f251e73846441028cf4de5a8279fc40f0e | 6d544f99d9ba53d386863cb58e749af163c30294 | refs/heads/master | 2020-04-14T13:18:14.444317 | 2019-01-02T16:31:03 | 2019-01-02T16:31:03 | 163,864,804 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,920 | cpp | // Copyright (c) 2014-2017 The Dash Core developers
// Copyright (c) 2018 The Bitmonix Core developers
#include "governance-validators.h"
#include "utilstrencodings.h"
#include "data/proposals_valid.json.h"
#include "data/proposals_invalid.json.h"
#include "test/test_bitmonix.h"
#include <iostream>
#include <fstream>
#include <string>
#include <boost/test/unit_test.hpp>
#include <univalue.h>
extern UniValue read_json(const std::string& jsondata);
BOOST_FIXTURE_TEST_SUITE(governance_validators_tests, BasicTestingSetup)
std::string CreateEncodedProposalObject(const UniValue& objJSON)
{
UniValue innerArray(UniValue::VARR);
innerArray.push_back(UniValue("proposal"));
innerArray.push_back(objJSON);
UniValue outerArray(UniValue::VARR);
outerArray.push_back(innerArray);
std::string strData = outerArray.write();
std::string strHex = HexStr(strData);
return strHex;
}
BOOST_AUTO_TEST_CASE(valid_proposals_test)
{
// all proposals are valid but expired
UniValue tests = read_json(std::string(json_tests::proposals_valid, json_tests::proposals_valid + sizeof(json_tests::proposals_valid)));
BOOST_CHECK_MESSAGE(tests.size(), "Empty `tests`");
for(size_t i = 0; i < tests.size(); ++i) {
const UniValue& objProposal = tests[i];
// legacy format
std::string strHexData1 = CreateEncodedProposalObject(objProposal);
CProposalValidator validator1(strHexData1);
BOOST_CHECK_MESSAGE(validator1.Validate(false), validator1.GetErrorMessages());
BOOST_CHECK_MESSAGE(!validator1.Validate(), validator1.GetErrorMessages());
// new format
std::string strHexData2 = HexStr(objProposal.write());
CProposalValidator validator2(strHexData2);
BOOST_CHECK_MESSAGE(validator2.Validate(false), validator2.GetErrorMessages());
BOOST_CHECK_MESSAGE(!validator2.Validate(), validator2.GetErrorMessages());
}
}
BOOST_AUTO_TEST_CASE(invalid_proposals_test)
{
// all proposals are invalid regardless of being expired or not
// (i.e. we don't even check for expiration here)
UniValue tests = read_json(std::string(json_tests::proposals_invalid, json_tests::proposals_invalid + sizeof(json_tests::proposals_invalid)));
BOOST_CHECK_MESSAGE(tests.size(), "Empty `tests`");
for(size_t i = 0; i < tests.size(); ++i) {
const UniValue& objProposal = tests[i];
// legacy format
std::string strHexData1 = CreateEncodedProposalObject(objProposal);
CProposalValidator validator1(strHexData1);
BOOST_CHECK_MESSAGE(!validator1.Validate(false), validator1.GetErrorMessages());
// new format
std::string strHexData2 = HexStr(objProposal.write());
CProposalValidator validator2(strHexData2);
BOOST_CHECK_MESSAGE(!validator2.Validate(false), validator2.GetErrorMessages());
}
}
BOOST_AUTO_TEST_SUITE_END()
| [
"46324696+julivn@users.noreply.github.com"
] | 46324696+julivn@users.noreply.github.com |
c2f8717a760cb1487355643cc03b1ae771afaa9c | f79ac3d5cd0cc2c20bb9fd16a76608ec84b1bc68 | /Season4/Advanced Programming/lab11/task1_1.cpp | 50b46b3c12461b6c20da4019e603e8d6334543e5 | [] | no_license | December1900/ASS-CSCI | 3b4213d45dc07a0b7052a8ceccd27f4fac45e8f8 | 9900568f2c4df32beac122ee556d171e262016eb | refs/heads/master | 2023-06-25T18:27:27.947851 | 2021-07-27T01:19:46 | 2021-07-27T01:19:46 | 288,160,187 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 210 | cpp | #include <iostream>
using namespace std;
class B {
public:
virtual void X() = 0;
};
class D : B {
public:
virtual void X() {cout << "D object" << endl;}
};
int main() {
D objD;
}
| [
"522376693@qq.com"
] | 522376693@qq.com |
b565c6a2a9c12fe25c07895c308523e529381cd4 | c97be5ce5bde844b79c683c5d2bbc625ff6842e0 | /src/test/logging_tests.cpp | eb1826ae8d9eebf60c120a1310af37d2d8dd7950 | [
"MIT"
] | permissive | xunzhang/bitcoin | 6680239da9a535c339305c730bbb51f8626ed49a | 4e21f72980a7514dba2806af3e3e7961d804de43 | refs/heads/master | 2020-09-05T00:02:00.451276 | 2019-11-06T02:08:31 | 2019-11-06T02:37:02 | 219,928,564 | 1 | 0 | MIT | 2019-11-06T06:35:50 | 2019-11-06T06:35:50 | null | UTF-8 | C++ | false | false | 1,100 | cpp | // Copyright (c) 2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <logging.h>
#include <logging/timer.h>
#include <test/setup_common.h>
#include <chrono>
#include <boost/test/unit_test.hpp>
BOOST_FIXTURE_TEST_SUITE(logging_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(logging_timer)
{
SetMockTime(1);
auto sec_timer = BCLog::Timer<std::chrono::seconds>("tests", "end_msg");
SetMockTime(2);
BOOST_CHECK_EQUAL(sec_timer.LogMsg("test secs"), "tests: test secs (1.00s)");
SetMockTime(1);
auto ms_timer = BCLog::Timer<std::chrono::milliseconds>("tests", "end_msg");
SetMockTime(2);
BOOST_CHECK_EQUAL(ms_timer.LogMsg("test ms"), "tests: test ms (1000.00ms)");
SetMockTime(1);
auto micro_timer = BCLog::Timer<std::chrono::microseconds>("tests", "end_msg");
SetMockTime(2);
BOOST_CHECK_EQUAL(micro_timer.LogMsg("test micros"), "tests: test micros (1000000.00μs)");
SetMockTime(0);
}
BOOST_AUTO_TEST_SUITE_END()
| [
"james.obeirne@gmail.com"
] | james.obeirne@gmail.com |
3c4cf0e99e64252a44993be9df731bea7cc40ac6 | c685a193e33bd119ae52f19050dc8fd72d417757 | /TP_Space_Invaders_II/SpaceMain.cpp | 04178c63c5a70206ab6ea83f6bbf21dfc5bcf7b9 | [] | no_license | ChaabaneHatem/Space-Invaders-II | 11b3775bc7316a8047d8477d857ff78b6615293f | 37e743adddd6a9ba932c5461bb313f4454db4af3 | refs/heads/master | 2020-03-18T04:36:57.437431 | 2018-05-21T16:35:56 | 2018-05-21T16:35:56 | 134,296,443 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 742 | cpp | //#include "VaisseauOriginal.h"
//#include"timer.h"
//#include "Laser.h"
//#include"Martien.h"
//#include"ExtraTerrestre.h"
//#include "UIKit.h"
//#include"LaserMartien.h"
//#include"MartienSoldat.h"
//#include"Monstres.h"
#include"jeu.h"
#include"fonctSpace.h"
#include <stdlib.h>
#include <stdlib.h>
#include <Windows.h>
#include <conio.h>
#include <time.h>
#define MAX_ENNEMI 16
#define MAX_LASERS 8
#define LARGUEUR 100
#define LONGUEUR 43
int main()
{
reglage();
bool finDeJeu = false;
jeu unjeu;
unjeu.initialisation();
// boucle principale de jeu
while (!finDeJeu) {
unjeu.jouer(finDeJeu);
}
if (finDeJeu) {
jeu::clrscr();
UIKit::gotoXY(50, 20);
cout << "GAME OVER !!";
UIKit::gotoXY(0, 0);
}
return 0;
} | [
"hatemchaabane0@gmail.com"
] | hatemchaabane0@gmail.com |
2bd9002f9262eae503faf55ea6eb3a1f8f0ced2f | e6391ddcb618cd5db39520a9a5306ead6a78849b | /cpp/udacity_cpp/05_concurrency/garbage_collector_thread/tester.cpp | f99259b041517e14c1ea49ca7315c08a1334a6e5 | [] | no_license | digital-nomad-cheng/study | b618d9f1f7d0eb5a87270d86dfdfe2beaa7a6836 | 7efcb96a91862a93aa0de42b2b8fc10ae5f8e475 | refs/heads/master | 2023-02-10T14:25:48.707379 | 2021-01-13T12:07:51 | 2021-01-13T12:07:51 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 868 | cpp | #include <iostream>
#include <new>
#include "gc_pointer_thread.hpp"
class LoadTest
{
int a, b;
public:
double n[10000];
double val;
LoadTest() { a = b = 0; }
LoadTest(int x, int y) {
a = x;
b = y;
val = 0.0;
}
friend std::ostream &operator<<(std::ostream &strm, LoadTest &obj);
};
std::ostream &operator<<(std::ostream &strm, LoadTest &obj) {
strm << "(" << obj.a << " " << obj.b << ")";
return strm;
}
int main()
{
Pointer<LoadTest> mp;
int i;
for (i = 0; i < 2000; i++) {
try {
mp = new LoadTest(i, i);
// if (!(i%100)) {
mp.showList();
std::cout << "gc_list contains: " << mp.ref_container_size()
<< "entries.\n" << std::endl;
// }
} catch (std::bad_alloc xa) {
std::cout << "last object:" << *mp << std::endl;
std::cout << "Length of gc_list: " << mp.ref_container_size() << std::endl;
}
}
return 0;
} | [
"vincentcheng@929@gmail.com"
] | vincentcheng@929@gmail.com |
5eccd01ab051bf45b17966b63298eb22498bccb6 | fca16f6b7838bd515de786cf6e8c01aee348c1f9 | /fps2015aels/uilibgp2015/OGL/Control/Control.cpp | d66a01cc9776d1187c1dbebc96aaadcb12466d95 | [] | no_license | antoinechene/FPS-openGL | 0de726658ffa278289fd89c1410c490b3dad7f54 | c7b3cbca8c6dc4f190dc92a273fe1b8ed74b7900 | refs/heads/master | 2020-04-06T07:01:17.983451 | 2012-09-06T14:06:25 | 2012-09-06T14:06:25 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 7,132 | cpp | #include "Control.h"
#include "../Drawable/Drawable.h"
#include "../Env.h"
#include <iostream>
ID::Control::Control() : _parent(NULL),
_cbClick(NULL),
_cbDoubleClick(NULL),
_cbClickDown(NULL),
_cbClickUp(NULL),
_cbEnter(NULL),
_cbLeave(NULL),
_cbMotion(NULL),
_cbKeyUp(NULL),
_cbKeyDown(NULL),
_cbFocusEnter(NULL),
_cbFocusLeave(NULL),
_cbEnableChange(NULL),
_cbScreenChange(NULL),
_cbResize(NULL),
_cbQuit(NULL),
_cbUserEvent(NULL),
_cbUpdate(NULL),
__cbClickData(NULL),
__cbDoubleClickData(NULL),
__cbClickDownData(NULL),
__cbClickUpData(NULL),
__cbEnterData(NULL),
__cbLeaveData(NULL),
__cbMotionData(NULL),
__cbKeyUpData(NULL),
__cbKeyDownData(NULL),
__cbFocusEnterData(NULL),
__cbFocusLeaveData(NULL),
__cbEnableChangeData(NULL),
__cbScreenChangeData(NULL),
__cbResizeData(NULL),
__cbQuitData(NULL),
__cbUserEventData(NULL),
__cbUpdateData(NULL),
__name(NULL)
{
}
ID::Control::Control(const ID::Control& c)
{
this->_parent = c._parent;
this->_childrenControl = c._childrenControl;
this->_childrenDrawable = c._childrenDrawable;
this->_cbClick = c._cbClick;
this->_cbDoubleClick = c._cbDoubleClick;
this->_cbClickDown = c._cbClickDown;
this->_cbClickUp = c._cbClickUp;
this->_cbEnter = c._cbEnter;
this->_cbLeave = c._cbLeave;
this->_cbMotion = c._cbMotion;
this->_cbKeyUp = c._cbKeyUp;
this->_cbKeyDown = c._cbKeyDown;
this->_cbFocusEnter = c._cbFocusEnter;
this->_cbFocusLeave = c._cbFocusLeave;
this->_cbEnableChange = c._cbEnableChange;
this->_cbScreenChange = c._cbScreenChange;
this->_cbResize = c._cbResize;
this->_cbQuit = c._cbQuit;
this->_cbUserEvent = c._cbUserEvent;
this->_cbUpdate = c._cbUpdate;
this->__cbClickData = c.__cbClickData;
this->__cbDoubleClickData = c.__cbDoubleClickData;
this->__cbClickDownData = c.__cbClickDownData;
this->__cbClickUpData = c.__cbClickUpData;
this->__cbEnterData = c.__cbEnterData;
this->__cbLeaveData = c.__cbLeaveData;
this->__cbMotionData = c.__cbMotionData;
this->__cbKeyUpData = c.__cbKeyUpData;
this->__cbKeyDownData = c.__cbKeyDownData;
this->__cbFocusEnterData = c.__cbFocusEnterData;
this->__cbFocusLeaveData = c.__cbFocusLeaveData;
this->__cbEnableChangeData = c.__cbEnableChangeData;
this->__cbScreenChangeData = c.__cbScreenChangeData;
this->__cbResizeData = c.__cbResizeData;
this->__cbQuitData = c.__cbQuitData;
this->__cbUserEventData = c.__cbUserEventData;
this->__cbUpdateData = c.__cbUpdateData;
this->__name = c.__name;
}
ID::Control::~Control(void)
{
this->_childrenControl.clear();
this->_childrenDrawable.clear();
}
ID::Control& ID::Control::operator=(const ID::Control& c)
{
this->_parent = c._parent;
this->_childrenControl = c._childrenControl;
this->_childrenDrawable = c._childrenDrawable;
this->_cbClick = c._cbClick;
this->_cbDoubleClick = c._cbDoubleClick;
this->_cbClickDown = c._cbClickDown;
this->_cbClickUp = c._cbClickUp;
this->_cbEnter = c._cbEnter;
this->_cbLeave = c._cbLeave;
this->_cbMotion = c._cbMotion;
this->_cbKeyUp = c._cbKeyUp;
this->_cbKeyDown = c._cbKeyDown;
this->_cbFocusEnter = c._cbFocusEnter;
this->_cbFocusLeave = c._cbFocusLeave;
this->_cbEnableChange = c._cbEnableChange;
this->_cbScreenChange = c._cbScreenChange;
this->_cbResize = c._cbResize;
this->_cbQuit = c._cbQuit;
this->_cbUserEvent = c._cbUserEvent;
this->_cbUpdate = c._cbUpdate;
this->__cbClickData = c.__cbClickData;
this->__cbDoubleClickData = c.__cbDoubleClickData;
this->__cbClickDownData = c.__cbClickDownData;
this->__cbClickUpData = c.__cbClickUpData;
this->__cbEnterData = c.__cbEnterData;
this->__cbLeaveData = c.__cbLeaveData;
this->__cbMotionData = c.__cbMotionData;
this->__cbKeyUpData = c.__cbKeyUpData;
this->__cbKeyDownData = c.__cbKeyDownData;
this->__cbFocusEnterData = c.__cbFocusEnterData;
this->__cbFocusLeaveData = c.__cbFocusLeaveData;
this->__cbEnableChangeData = c.__cbEnableChangeData;
this->__cbScreenChangeData = c.__cbScreenChangeData;
this->__cbResizeData = c.__cbResizeData;
this->__cbQuitData = c.__cbQuitData;
this->__cbUserEventData = c.__cbUserEventData;
this->__cbUpdateData = c.__cbUpdateData;
this->__name = c.__name;
return *this;
}
void ID::Control::AddChild(ID::Drawable* d)
{
ID::REL_POS_TYPE relPos;
ID::Drawable* parent;
parent = d->GetParent();
if (parent != NULL)
{
parent->DelChild(d);
}
this->_childrenDrawable.push_back(d);
d->SetParent((Drawable*)this);
relPos = d->GetRelPos();
if (relPos != ID::REL_POS_NONE)
d->SetPos(relPos);
else
{
int16_t x;
int16_t y;
d->GetPos(&x, &y);
d->SetPos(x, y);
}
}
void ID::Control::AddChild(ID::Control* c)
{
this->_childrenControl.push_back(c);
c->SetParent((Drawable*)this);
}
int ID::Control::DelChild(ID::Control* control)
{
std::list<ID::Control*>::iterator it;
std::list<ID::Control*>::iterator end;
it = this->_childrenControl.begin();
end = this->_childrenControl.end();
while (it != end)
{
if (*it == control)
{
this->_childrenControl.erase(it);
control->SetParent(NULL);
return 0;
}
++it;
}
return -1;
}
int ID::Control::DelChild(ID::Drawable* drawable)
{
ID::Env* e;
std::list<ID::Drawable*>::iterator it;
std::list<ID::Drawable*>::iterator end;
e = Env::GetInstance();
it = this->_childrenDrawable.begin();
end = this->_childrenDrawable.end();
while (it != end)
{
if (*it == drawable)
{
if (e->GetDrawableFocused() == drawable)
e->SetDrawableFocused(NULL);
if (e->GetDrawableEntered() == drawable)
e->SetDrawableEntered(NULL);
this->_childrenDrawable.erase(it);
drawable->SetParent(NULL);
return 0;
}
++it;
}
return -1;
}
int ID::Control::MoveChildFront(ID::Drawable* drawable)
{
std::list<ID::Drawable*>::iterator it;
std::list<ID::Drawable*>::iterator end;
it = this->_childrenDrawable.begin();
end = this->_childrenDrawable.end();
while (it != end)
{
if (*it == drawable)
{
this->_childrenDrawable.push_front(*it);
this->_childrenDrawable.erase(it);
return 0;
}
++it;
}
return -1;
}
int ID::Control::MoveChildBack(ID::Drawable* drawable)
{
std::list<ID::Drawable*>::iterator it;
std::list<ID::Drawable*>::iterator end;
it = this->_childrenDrawable.begin();
end = this->_childrenDrawable.end();
while (it != end)
{
if (*it == drawable)
{
this->_childrenDrawable.push_back(*it);
this->_childrenDrawable.erase(it);
return 0;
}
++it;
}
return -1;
}
void ID::Control::ClearChildren()
{
this->_childrenControl.clear();
this->_childrenDrawable.clear();
}
void ID::Control::SetParent(ID::Drawable* p)
{
Env* e;
e = Env::GetInstance();
if (e->GetDrawableFocused() == this)
e->SetDrawableFocused(NULL);
if (e->GetDrawableEntered() == this)
e->SetDrawableEntered(NULL);
this->_parent = p;
}
ID::Drawable* ID::Control::GetParent(void) const
{
return this->_parent;
}
std::list<ID::Control*>* ID::Control::GetChildrenControl(void)
{
return &(this->_childrenControl);
}
std::list<ID::Drawable*>* ID::Control::GetChildrenDrawable(void)
{
return &(this->_childrenDrawable);
}
| [
"antoinechene@hotmail.fr"
] | antoinechene@hotmail.fr |
35ce26fdd72619d1b41fadd8daab9f7a27afa5ff | ccae3c9b20fa3c895042a1c7aa0815fd0faec141 | /trunk/TxUIProject/TxUITestFrame/TxUITestFrame.h | df63cbd48189b9fb7c9e8503c15ae33b39275d61 | [] | no_license | 15831944/TxUIProject | 7beaf17eb3642bcffba2bbe8eaa7759c935784a0 | e90f3319ad0e57c0012e0e3a7e457851c2c6f0f1 | refs/heads/master | 2021-12-03T10:05:27.018212 | 2014-05-16T08:16:17 | 2014-05-16T08:16:17 | null | 0 | 0 | null | null | null | null | GB18030 | C++ | false | false | 529 | h |
// TxUITestFrame.h : PROJECT_NAME 应用程序的主头文件
//
#pragma once
#ifndef __AFXWIN_H__
#error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件"
#endif
#include "resource.h" // 主符号
// CTxUITestFrameApp:
// 有关此类的实现,请参阅 TxUITestFrame.cpp
//
class CTxUITestFrameApp : public CWinAppEx
{
public:
CTxUITestFrameApp();
// 重写
public:
virtual BOOL InitInstance();
// 实现
DECLARE_MESSAGE_MAP()
virtual int ExitInstance();
};
extern CTxUITestFrameApp theApp; | [
"tyxwgy@sina.com"
] | tyxwgy@sina.com |
2fe20d269f847f2e1e2667985d5e857d6cc21b03 | 35381d94d86558ff2d680df50f50b3d9fa968f15 | /tclparms.h | 6235968bb4932f1603c3c7d514484afed0acf103 | [] | no_license | nedbrek/tclsdl | bbc88f4ac0c1268b32da14aef4d3202ab978f074 | 30728af6829d18d08c70db4269a1eb7035854fc9 | refs/heads/master | 2021-01-10T18:47:04.173155 | 2012-04-15T12:24:56 | 2012-04-15T12:25:20 | 2,450,446 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 781 | h | #ifndef TCL_PARMS_H
#define TCL_PARMS_H
#include <tcl.h>
/// interface to Tcl parameters like an array
class Parms
{
protected:
Tcl_Interp *interp_;
Tcl_Obj *CONST *objv_;
unsigned objc_;
public:
Parms(Tcl_Interp *interp, Tcl_Obj *CONST* objv, unsigned objc):
interp_(interp), objv_(objv), objc_(objc) {}
Tcl_Interp* getInterp(void) { return interp_; }
unsigned getNumArgs(void) const { return objc_-1; }
Tcl_WideInt operator[](unsigned i)
{
if( i+1 >= objc_ ) return -1;
Tcl_WideInt ret;
Tcl_GetWideIntFromObj(interp_, objv_[i+1], &ret);
return ret;
}
const char* getStringParm(unsigned i)
{
if( i+1 >= objc_ ) return NULL;
return Tcl_GetStringFromObj(objv_[i+1], NULL);
}
};
#endif
| [
"nedbrek@yahoo.com"
] | nedbrek@yahoo.com |
37172509d4090c0276a2c651f21e1473b9f2842b | 018d80912bebd999b9605ba7bb55b010580d2a9d | /C± Parser/ParseResult.cpp | f6ce642fbfcfef338739dd714e708b9de5b6cd74 | [] | no_license | d0nutptr/C-plus-or-minus | 58e5b160daa685ee86443a557f5cc53ef0f30c72 | b777f5d98b68f06fb87373ab94c4cc33dc0c0aed | refs/heads/master | 2021-05-30T10:05:45.637866 | 2015-08-31T20:24:57 | 2015-08-31T20:24:57 | 37,954,408 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 494 | cpp | #include "ParseResult.h"
ParseResult::ParseResult(std::vector<MetaToken *> * invalidSet)
{
this->valid = false;
this->failedSet = invalidSet;
this->validResult = NULL;
}
ParseResult::ParseResult(MetaToken * result)
{
this->valid = true;
this->failedSet = NULL;
this->validResult = result;
}
bool ParseResult::isValid()
{
return valid;
}
MetaToken * ParseResult::getValidResult()
{
return validResult;
}
std::vector<MetaToken *> * ParseResult::getInvalidSet()
{
return failedSet;
} | [
"iismathwizard@gmail.com"
] | iismathwizard@gmail.com |
c82066cd23a175bcf3e1e2ba83d12127606aed77 | 23d096a2c207eff63f0c604825d4b2ea1a5474d9 | /EcalValidation/ECALAlignmentFramework/interface/ECALAlignmentFramework.h | d7e4845c06c07441eb81589864aea46de750a55e | [] | no_license | martinamalberti/BicoccaUserCode | 40d8272c31dfb4ecd5a5d7ba1b1d4baf90cc8939 | 35a89ba88412fb05f31996bd269d44b1c6dd42d3 | refs/heads/master | 2021-01-18T09:15:13.790891 | 2013-08-07T17:08:48 | 2013-08-07T17:08:48 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,373 | h | /*
NAMETEMPLATE
*/
#ifndef NAMETEMPLATE_h
#define NAMETEMPLATE_h
#include <vector>
#include <cmath>
#if not defined(__CINT__) || defined(__MAKECINT__)
#include "TMVA/Tools.h"
#include "TMVA/Reader.h"
#endif
#include "Math/GenVector/VectorUtil.h"
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include "functional"
#include <utility>
#include "ConfigParser.h"
#include "ConfigFileLine.h"
#include "TCanvas.h"
#include "TH1.h"
#include "THStack.h"
/** get the parameters from a congiguration file */
int parseConfigFile (const TString& config) ;
///==== GetTrendInfo ====
///==== Transform TH1 with "trace" information to TH1 ====
TH1F* GetTrendInfo(TH1F* hTrend, double min = -1.5, double max = 1.5);
///==== Pull Plot: drawing utility ====
void PullPlot(TCanvas* canvas, TH1* hDATA, TH1* hMC);
void PullPlot(TCanvas* canvas, TH1* hDATA, THStack* hsMC);
TH1F* PullPlot(TH1F* hDATA, TH1F* hMC);
///==== Draw Stack ====
void DrawStack(THStack* hs, int error = 0, double syst = 0);
void DrawStackError(THStack* hs, double syst = 0);
///==== Add systrematic error ====
void AddError(THStack* hs, double syst = 0);
/** compute delta phi */
double deltaPhi (const double& phi1, const double& phi2);
/** compute delta eta */
double deltaEta (const double& eta1, const double& eta2);
#endif
| [
""
] | |
ea2c75e55bc684c9eb545f2b5a80bc3b07f305c1 | a1ad01a032a7b0a09fcde03dccd34cecc53c4166 | /C++SampleCodes - 2015-12-15/StringCtrlSample - 실습과제 4 정답/StringCtrlSample/StringCtrlSample.cpp | 26afa1fd50e4140865454f2b3f57248c78ddc163 | [] | no_license | hojong21c/Solutions | c049ec90f4ecea137f153a1a981a4d134786923e | ef1e4415ec974b83c667adfa08fb56d441e33fd6 | refs/heads/master | 2020-07-30T07:20:14.610537 | 2019-09-22T13:19:45 | 2019-09-22T13:19:45 | 210,132,473 | 0 | 0 | null | null | null | null | UHC | C++ | false | false | 350 | cpp | // StringCtrlSample.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
#include "MyString.h"
void TestFunc(const CMyString &strParam)
{
cout << strParam << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
CMyString strData("Hello");
::TestFunc(strData);
::TestFunc(CMyString("World"));
return 0;
}
| [
"hojong21c@nate.com"
] | hojong21c@nate.com |
93ebf1cc2d721c7903e5a5f150d2237193dac439 | 5b02a21ff1b7080912d072a6bae17c4718808505 | /libs/tracking/interpolation_process.hpp | 50f2dc6bb32d22209c928af199475f83ed616d07 | [
"BSD-3-Clause"
] | permissive | mhough/DSI-Studio | 315641293807a1c2d1ee13123d52aa114841b8ea | 06ec875a21e6609f1fea41e28358b6ea6d3e78a6 | refs/heads/master | 2020-12-24T21:45:07.133859 | 2013-01-18T04:31:49 | 2013-01-18T04:31:49 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,087 | hpp | #ifndef INTERPOLATION_PROCESS_HPP
#define INTERPOLATION_PROCESS_HPP
#include <cstdlib>
#include "image/image.hpp"
class TrackingInfo;
class basic_interpolation
{
public:
virtual bool evaluate(TrackingInfo& info,
const image::vector<3,float>& position,
const image::vector<3,float>& ref_dir,
image::vector<3,float>& result) = 0;
};
class trilinear_interpolation_with_gaussian_basis : public basic_interpolation
{
public:
virtual bool evaluate(TrackingInfo& info,
const image::vector<3,float>& position,
const image::vector<3,float>& ref_dir,
image::vector<3,float>& result);
};
class trilinear_interpolation : public basic_interpolation
{
public:
virtual bool evaluate(TrackingInfo& info,
const image::vector<3,float>& position,
const image::vector<3,float>& ref_dir,
image::vector<3,float>& result);
};
class nearest_direction : public basic_interpolation
{
public:
virtual bool evaluate(TrackingInfo& info,
const image::vector<3,float>& position,
const image::vector<3,float>& ref_dir,
image::vector<3,float>& result);
};
#endif//INTERPOLATION_PROCESS_HPP
| [
"frank.yeh@gmail.com"
] | frank.yeh@gmail.com |
936538ca8039828a0ea4be06381139d66909b88c | bcb81cd629fd9af3038e8b497c0604f4828c952d | /Tread/daikatanareader.h | cfa9e5643d5ff22402eeaacda9e6cda5cc75060c | [
"MIT"
] | permissive | joeriedel/tread2.4f | be2394d4f9fd2820097ecf0bd2efd9ece272479d | e23ac7beb3db6601095334e54b8e3e565f3e520a | refs/heads/master | 2020-06-18T11:12:30.254749 | 2019-07-10T22:42:07 | 2019-07-10T22:42:07 | 196,283,955 | 2 | 1 | null | null | null | null | ISO-8859-1 | C++ | false | false | 635 | h | // DAIKATANAREADER.H
// Copyright © 1999 Joe Riedel, Nick Randal.
// Author: Joe Riedel.
#ifndef DAIKATANAREADER_H
#define DAIKATANAREADER_H
// Loads. Quake2(tm) .wal files. Quake2(tm) is © by id Software®, All Rights Reserved.
// Reads a Q2 .wal file.
#include "TexReader.h"
#define Q2_SURF_TRANS33 0x10
#define Q2_SURF_TRANS66 0x20
class CDaikatanaReader : public CTexReader
{
public:
CDaikatanaReader();
~CDaikatanaReader();
int TranslateSurfaceToRenderFlags(int nFlags);
// Reads info from a Q2. Wal File.
bool LoadTextureInfo(CTexture* pTex);
// Reads a Q2. Wal File.
bool LoadTexture(CTexture* pTex);
};
#endif | [
"joeriedel@hotmail.com"
] | joeriedel@hotmail.com |
646bfd0f8b601a04c1d0a01dab8794dc92616092 | e8e1326efd525a72706a0f365f81325867b51efe | /include/blob/put_page_request.h | 46b697f2862076bcb830fd77a5cf94704c03836c | [
"MIT",
"LicenseRef-scancode-generic-cla"
] | permissive | rviswanathreddy/azure-storage-cpplite | ccd1751d6dd418c0a29c660ad90f8cbb7dbf6cd3 | a8ac45c9479bdd0bcd7107adab300b02955cdf41 | refs/heads/master | 2020-05-05T05:42:52.102273 | 2019-04-05T22:51:32 | 2019-04-05T22:51:32 | 179,761,095 | 0 | 0 | MIT | 2019-04-05T22:11:29 | 2019-04-05T22:11:29 | null | UTF-8 | C++ | false | false | 1,888 | h | #pragma once
#include "put_page_request_base.h"
namespace azure { namespace storage_lite {
class put_page_request : public put_page_request_base
{
public:
put_page_request(const std::string &container, const std::string &blob, bool clear = false)
: m_container(container),
m_blob(blob),
m_clear(clear),
m_start_byte(0),
m_end_byte(0),
m_content_length(0) {}
std::string container() const override
{
return m_container;
}
std::string blob() const override
{
return m_blob;
}
unsigned long long start_byte() const override
{
return m_start_byte;
}
unsigned long long end_byte() const override
{
return m_end_byte;
}
put_page_request &set_start_byte(unsigned long long start_byte)
{
m_start_byte = start_byte;
return *this;
}
put_page_request &set_end_byte(unsigned long long end_byte)
{
m_end_byte = end_byte;
return *this;
}
page_write ms_page_write() const override
{
if (m_clear) {
return page_write::clear;
}
return page_write::update;
}
unsigned int content_length() const override
{
return m_content_length;
}
put_page_request &set_content_length(unsigned int content_length)
{
m_content_length = content_length;
return *this;
}
private:
std::string m_container;
std::string m_blob;
bool m_clear;
unsigned long long m_start_byte;
unsigned long long m_end_byte;
unsigned int m_content_length;
};
}} // azure::storage_lite
| [
"vinjiang@users.noreply.github.com"
] | vinjiang@users.noreply.github.com |
7ea9c0073573c3c5d3d5b291272760016d370e27 | 2692220465f2a4fc8cba6d9b912b76cd4561460e | /src/spruce/solutionset.h | 026ad82fd2c357e05b5d18376fd1e8cf8532d3ba | [
"BSD-3-Clause"
] | permissive | qindan2008/OncoLib | 04071edf323a28a22816968d2cac7ef24d9b385f | 1707709c21f8f54ed7ebff9272f5b159f05a8ee5 | refs/heads/master | 2022-02-24T14:12:33.778892 | 2019-10-20T16:06:00 | 2019-10-20T16:06:00 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,824 | h | /*
* solutionset.h
*
* Created on: 1-oct-2015
* Author: M. El-Kebir
*/
#ifndef SOLUTIONSET_H
#define SOLUTIONSET_H
#include "utils.h"
#include "solution.h"
#include "realtensor.h"
#include "statetree.h"
#include "perfectphylotree.h"
namespace gm {
class SolutionSet
{
public:
typedef std::vector<Solution> SolutionVector;
typedef SolutionVector::const_iterator SolutionVectorIt;
typedef SolutionVector::iterator SolutionVectorNonConstIt;
typedef std::vector<StateTree> StateTreeVector;
SolutionSet();
int solutionCount() const
{
return _sol.size();
}
const Solution& solution(int idx) const
{
assert(0 <= idx && idx < _sol.size());
return _sol[idx];
}
void clear()
{
_sol.clear();
}
void add(const Solution& sol);
void add(const SolutionSet& sols);
void assignDistancesByOccurenceCounts();
void sort();
const Solution& max() const
{
return *std::min_element(_sol.begin(), _sol.end(), Compare());
}
int unique();
friend std::ostream& operator<<(std::ostream& out, const SolutionSet& sols);
friend std::istream& operator>>(std::istream& in, SolutionSet& sols);
private:
typedef std::map<std::string, std::map<std::string, int > > Map;
typedef std::map<std::string, int> StringIntMap;
typedef StringIntMap::const_iterator StringIntMapIt;
private:
SolutionVector _sol;
Map _occArc;
StringIntMap _nodes;
void initSummary();
struct Compare
{
bool operator()(const Solution& sol1,
const Solution& sol2)
{
return sol1.distance() < sol2.distance();
}
};
};
std::ostream& operator<<(std::ostream& out, const SolutionSet& sols);
std::istream& operator>>(std::istream& in, SolutionSet& sols);
} // namespace gm
#endif // SOLUTIONSET_H
| [
"melkebir@cs.brown.edu"
] | melkebir@cs.brown.edu |
4c1a504b25e81b300cf7aec85e0d76044ae92ebc | 91b04e0ae7939a3087ea3edc2eea73c928a54c89 | /sem2/oop/labs/practice/teachers/src/Observer.h | 881751a765214963701fd5dbafc62d905ea5f9af | [] | no_license | mirceadino/CollegeAssignments | cf9111b87f5aaf00783749b5769b91a8e3e13ca5 | fc0f59ae78a6000d0fc1f63edb52ca7e3b840548 | refs/heads/master | 2021-01-12T14:33:44.619046 | 2018-06-12T08:09:20 | 2018-06-12T08:09:20 | 72,014,014 | 1 | 5 | null | null | null | null | UTF-8 | C++ | false | false | 655 | h | #ifndef OBSERVER_H_
#define OBSERVER_H_
#include <vector>
class Observer {
public:
virtual void update() = 0;
virtual ~Observer() {
}
};
class Subject {
public:
virtual ~Subject() {
}
void notify() {
for (auto o : observers_)
o->update();
}
void addObserver(Observer* o) {
observers_.push_back(o);
}
void removeObserver(Observer* o) {
for (auto& op : observers_)
if (op == o) {
std::swap(observers_.back(), op);
observers_.pop_back();
return;
}
}
protected:
std::vector<Observer*> observers_;
};
#endif /* OBSERVER_H_ */
| [
"mirceadino97@gmail.com"
] | mirceadino97@gmail.com |
69240149dcb07d2e4739c5953d8bf6672596fe71 | 74aeae883ce762500129555f08d7e5f5531254f9 | /src/protocol.h | 2e0b6aae41849a26e6e1dcf9a91895d944b5872f | [
"MIT"
] | permissive | HalfMoonDev/halfmoon-daemon | 7c84975af49b2b0b56bc9f507ae755873db4cb62 | 3c2ae230119028cec9be39d00e2bbc923be3f531 | refs/heads/master | 2021-01-23T07:16:32.738042 | 2017-01-31T06:21:26 | 2017-01-31T06:21:26 | 80,495,872 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,377 | h | // Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef __cplusplus
# error This header can only be compiled as C++.
#endif
#ifndef __INCLUDED_PROTOCOL_H__
#define __INCLUDED_PROTOCOL_H__
#include "serialize.h"
#include "netbase.h"
#include <string>
#include "uint256.h"
extern bool fTestNet;
static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
{
return testnet ? 35551 : 15551;
}
extern unsigned char pchMessageStart[4];
/** Message header.
* (4) message start.
* (12) command.
* (4) size.
* (4) checksum.
*/
class CMessageHeader
{
public:
CMessageHeader();
CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
std::string GetCommand() const;
bool IsValid() const;
IMPLEMENT_SERIALIZE
(
READWRITE(FLATDATA(pchMessageStart));
READWRITE(FLATDATA(pchCommand));
READWRITE(nMessageSize);
READWRITE(nChecksum);
)
// TODO: make private (improves encapsulation)
public:
enum {
MESSAGE_START_SIZE=sizeof(::pchMessageStart),
COMMAND_SIZE=12,
MESSAGE_SIZE_SIZE=sizeof(int),
CHECKSUM_SIZE=sizeof(int),
MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
};
char pchMessageStart[MESSAGE_START_SIZE];
char pchCommand[COMMAND_SIZE];
unsigned int nMessageSize;
unsigned int nChecksum;
};
/** nServices flags */
enum
{
NODE_NETWORK = (1 << 0),
};
/** A CService with information about it as peer */
class CAddress : public CService
{
public:
CAddress();
explicit CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK);
void Init();
IMPLEMENT_SERIALIZE
(
CAddress* pthis = const_cast<CAddress*>(this);
CService* pip = (CService*)pthis;
if (fRead)
pthis->Init();
if (nType & SER_DISK)
READWRITE(nVersion);
if ((nType & SER_DISK) ||
(nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
READWRITE(nTime);
READWRITE(nServices);
READWRITE(*pip);
)
void print() const;
// TODO: make private (improves encapsulation)
public:
uint64 nServices;
// disk and network only
unsigned int nTime;
// memory only
int64 nLastTry;
};
/** inv message data */
class CInv
{
public:
CInv();
CInv(int typeIn, const uint256& hashIn);
CInv(const std::string& strType, const uint256& hashIn);
IMPLEMENT_SERIALIZE
(
READWRITE(type);
READWRITE(hash);
)
friend bool operator<(const CInv& a, const CInv& b);
bool IsKnownType() const;
const char* GetCommand() const;
std::string ToString() const;
void print() const;
// TODO: make private (improves encapsulation)
public:
int type;
uint256 hash;
};
#endif // __INCLUDED_PROTOCOL_H__
| [
"halfmoonblockchain@gmail.com"
] | halfmoonblockchain@gmail.com |
1a8076d3963e72b32646958286af70a7e3f2f127 | b22588340d7925b614a735bbbde1b351ad657ffc | /athena/Generators/GeneratorFilters/src/GapJetFilter.cxx | c70313fad873c92665df844741d077ea3dca1e05 | [] | no_license | rushioda/PIXELVALID_athena | 90befe12042c1249cbb3655dde1428bb9b9a42ce | 22df23187ef85e9c3120122c8375ea0e7d8ea440 | refs/heads/master | 2020-12-14T22:01:15.365949 | 2020-01-19T03:59:35 | 2020-01-19T03:59:35 | 234,836,993 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,448 | cxx | /*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// --------------------------------------------------
//
// File: GeneratorFilters/GapJetFilter.cxx
// Description: Filter suppresses events with low Pt
// jets and low forward gaps
// AuthorList: Marek Tasevsky
//
// --------------------------------------------------
// Header for this module:-
#include "GeneratorFilters/GapJetFilter.h"
// Framework Related Headers:-
#include "StoreGate/DataHandle.h"
#include "GaudiKernel/PhysicalConstants.h"
// Truth objects analysed
#include "xAODJet/JetContainer.h"
#include "xAODJet/Jet.h"
// Other classes used by this class:-
//#include <cmath>
#include <math.h>
#include <vector>
#include "TRandom3.h"
#include <iostream>
#include <iomanip>
using namespace std;
// Pt High --> Low
class High2LowByJetClassPt
{
public:
bool operator () (const xAOD::Jet *t1, const xAOD::Jet *t2) const {
return (t1->pt() > t2->pt());
}
};
//--------------------------------------------------------------------------
GapJetFilter::GapJetFilter(const std::string & name,
ISvcLocator * pSvcLocator):
GenFilter (name, pSvcLocator)
{
std::vector<double> empty;
//General Jets
declareProperty("JetContainer", m_jetContainer = "AntiKt4TruthJets");
//Allow a hard cut on the jet system
declareProperty("MinPt1", m_minPt1 = 12.0);//In GeV
declareProperty("MaxPt1", m_maxPt1 = 70000.0);//In GeV
declareProperty("MinPt2", m_minPt2 = 12.0);//In GeV
declareProperty("MaxPt2", m_maxPt2 = 70000.0);//In GeV
declareProperty("MinPtparticle", m_PtCut = 0.);//In MeV
declareProperty("MaxEtaparticle", m_EtaCut = 0.);
declareProperty("weights", m_weights = empty );
declareProperty("c0", m_c0 = 0.);
declareProperty("c1", m_c1 = 0.);
declareProperty("c2", m_c2 = 0.);
declareProperty("c3", m_c3 = 0.);
declareProperty("c4", m_c4 = 0.);
declareProperty("c5", m_c5 = 0.);
declareProperty("c6", m_c6 = 0.);
declareProperty("c7", m_c7 = 0.);
declareProperty("gapf", m_gapf = 0.);
xsgapf = 0.;
m_storeGate = 0;
myRandGen = 0;
}
//--------------------------------------------------------------------------
GapJetFilter::~GapJetFilter()
{
//--------------------------------------------------------------------------
}
//---------------------------------------------------------------------------
StatusCode
GapJetFilter::filterInitialize()
{
//---------------------------------------------------------------------------
StatusCode sc = service("StoreGateSvc", m_storeGate);
if (sc.isFailure()) {
msg(MSG::ERROR)
<< "Unable to retrieve pointer to StoreGateSvc"
<< endreq;
return sc;
}
//Output settings to screen
msg(MSG::INFO) << "xAOD::JetContainer: " << m_jetContainer << endreq;
//Jet Kinematic Cuts
msg( MSG::INFO) << "Jet 1 Min Pt: " << m_minPt1 <<" Gaudi::Units::GeV"<< endreq;
msg( MSG::INFO) << "Jet 1 Max Pt: " << m_maxPt1 <<" Gaudi::Units::GeV"<< endreq;
msg( MSG::INFO) << "Jet 2 Min Pt: " << m_minPt2 <<" Gaudi::Units::GeV"<< endreq;
msg( MSG::INFO) << "Jet 2 Max Pt: " << m_maxPt2 <<" Gaudi::Units::GeV"<< endreq;
//Particle Cuts
msg(MSG::INFO) << "Particle Min Pt: " << m_PtCut <<" Gaudi::Units::MeV" <<endreq;
msg(MSG::INFO) << "Particle Eta: " << m_EtaCut << endreq;
msg(MSG::INFO) << "Fit param. c0 = " << m_c0 << endreq;
msg(MSG::INFO) << "Fit param. c1 = " << m_c1 << endreq;
msg(MSG::INFO) << "Fit param. c2 = " << m_c2 << endreq;
msg(MSG::INFO) << "Fit param. c3 = " << m_c3 << endreq;
msg(MSG::INFO) << "Fit param. c4 = " << m_c4 << endreq;
msg(MSG::INFO) << "Fit param. c5 = " << m_c5 << endreq;
msg(MSG::INFO) << "Fit param. c6 = " << m_c6 << endreq;
msg(MSG::INFO) << "Fit param. c7 = " << m_c7 << endreq;
msg(MSG::INFO) << "Max. weighted gap = " << m_gapf << endreq;
xsgapf = m_c0*exp(m_c1+m_c2*m_gapf)+m_c3*exp(m_c4+m_c5*m_gapf)+m_c6*pow(m_gapf,m_c7);
//Setup the random number generator for weighting
myRandGen = new TRandom3();
myRandGen->SetSeed(0); //completely random!
return StatusCode::SUCCESS;
}
//---------------------------------------------------------------------------
StatusCode
GapJetFilter::filterFinalize()
{
//---------------------------------------------------------------------------
//Get rid of the random number generator
delete myRandGen;
return StatusCode::SUCCESS;
}
//---------------------------------------------------------------------------
StatusCode
GapJetFilter::filterEvent()
{
//---------------------------------------------------------------------------
StatusCode sc = StatusCode::SUCCESS;
// Get TruthJets
//
msg(MSG::DEBUG) << "get truthJet container" << endreq;
const xAOD::JetContainer* truthjetTES;
sc=m_storeGate->retrieve(truthjetTES, m_jetContainer);
if( sc.isFailure() || !truthjetTES ) {
msg(MSG::WARNING)
<< "No xAOD::JetContainer found in TDS "
<< m_jetContainer << " "
<< sc.isFailure() << " " << !truthjetTES
<< endreq;
return StatusCode::SUCCESS;
}
msg(MSG::INFO) << "xAOD::JetContainer Size = "
<< truthjetTES->size() << endreq;
// Get a list of all the truth jets
std::vector<const xAOD::Jet*> jetList;
for (xAOD::JetContainer::const_iterator it_truth = truthjetTES->begin();
it_truth != truthjetTES->end(); ++it_truth) {
jetList.push_back(*it_truth);
}
// Sort of Jets by Pt
std::sort(jetList.begin(), jetList.end(), High2LowByJetClassPt());
//Apply various cuts
// Number of Jets (need at least two)
int flagNJets = -1;
if (int(jetList.size()) < 2) {
flagNJets = 0;
} else {
flagNJets = 1;
}
//
// Leading 1st jet
//
int flag1stJet = -1;
//double jetPt1 = -1.0;
//float jetEta1 = -99.0;
if (jetList.size() >=1) {
const xAOD::Jet *j1 = jetList[0];
//jetPt1 = j1->pt()/1000.0;
flag1stJet = 1;
//jetEta1 = j1->eta();
if (j1->pt()/1000.0 < m_minPt1) {
flag1stJet = 0;
}
if (j1->pt()/1000.0 > m_maxPt1) {
flag1stJet = 0;
}
}
//
// Leading 2nd jet
//
int flag2ndJet = -1;
//float jetEta2 = -99.0;
if (jetList.size() >=2) {
const xAOD::Jet *j2 = jetList[1];
flag2ndJet = 1;
//jetEta2 = j2->eta();
if (j2->pt()/1000.0 < m_minPt2) {
flag2ndJet = 0;
}
if (j2->pt()/1000.0 > m_maxPt2) {
flag2ndJet = 0;
}
}
msg(MSG::INFO) << "NJets OK? : " << flagNJets << endreq;
msg(MSG::INFO) << "1stJet OK? : " << flag1stJet << endreq;
msg(MSG::INFO) << "2ndJet OK? : " << flag2ndJet << endreq;
if (flagNJets != 0 && flag1stJet != 0 && flag2ndJet != 0) {
if (m_gapf == 0) {
return StatusCode::SUCCESS;}
else if (m_gapf > 0) {
float ptpart=-10., etapart=-100., cl_maxeta=-10., cl_mineta=10.;
Int_t Clustag=0;
// Loop over all events in McEventCollection
McEventCollection::const_iterator itr;
for (itr = events()->begin(); itr != events()->end(); ++itr) {
HepMC::GenEvent* genEvt = *itr;
// Loop over all particles in event
HepMC::GenEvent::particle_const_iterator pitr;
for (pitr = genEvt->particles_begin(); pitr != genEvt->particles_end(); ++pitr ) {
//particles must be stable
ptpart = (*pitr)->momentum().perp();
etapart = (*pitr)->momentum().pseudoRapidity();
if((*pitr)->status()==1 && ptpart >m_PtCut && fabs(etapart) < m_EtaCut){
Clustag=1;
if (etapart>cl_maxeta) cl_maxeta=etapart;
if (etapart<cl_mineta) cl_mineta=etapart;
}
}
float rapgap_cl=-100.;
if (fabs(cl_maxeta)<fabs(cl_mineta) && Clustag==1) {
rapgap_cl = 4.9 - cl_maxeta;
}
else if (fabs(cl_maxeta)>fabs(cl_mineta) && Clustag==1) {
rapgap_cl = 4.9 + cl_mineta;
}
double xsgap = m_c0*exp(m_c1+m_c2*rapgap_cl)+m_c3*exp(m_c4+m_c5*rapgap_cl)+m_c6*pow(rapgap_cl,m_c7);
//cout<<"xsgapf2 = "<<std::setprecision(10) <<xsgapf<<endl;
double weighting = xsgapf/xsgap;
double rand = myRandGen->Rndm();
double w = 0.0;
if (rapgap_cl>m_gapf) {
w=1.0;
}
else if (rapgap_cl<m_gapf){
if (rand < weighting) w=weighting;
}
if (w>0.0) {
genEvt->weights().push_back(1.0/w);
return StatusCode::SUCCESS;
}
}
} //else if
}
//++m_nFail;
setFilterPassed(false);
msg(MSG::INFO) << "drop event" << endreq;
return StatusCode::SUCCESS;
}
| [
"rushioda@lxplus754.cern.ch"
] | rushioda@lxplus754.cern.ch |
dfb37689f605dcefd24ffa6bb89432317301bdc0 | 7ceca0c5ad3e07999b3ab87e439f9bbfa0cc49ed | /Plugins/AdvKitPlugin/Source/AdvKitRuntime/Private/Actions/AnimNotify_SetTransitionZone.cpp | af21cdabc29766d7b651e508b758ea55a9e5e452 | [
"CC0-1.0",
"LicenseRef-scancode-public-domain"
] | permissive | crimsonstrife/velorum-defunct | 8323a84b433f4d42f66059f311f073c8e77c242f | 1a6e1eab9057293da2aa045eff021d069df54c5e | refs/heads/master | 2020-02-26T17:42:40.390204 | 2016-09-15T18:41:43 | 2016-09-15T18:41:43 | 68,319,853 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 746 | cpp | // Copyright 2015 Pascal Krabbe
#include "AdvKitRuntime.h"
#include "Actions/AnimNotify_SetTransitionZone.h"
#include "Actions/AdvKitCharacterAction_CharacterModifier.h"
UAnimNotify_SetTransitionZone::UAnimNotify_SetTransitionZone()
: Super()
{
bSnapToZone = true;
}
void UAnimNotify_SetTransitionZone::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation)
{
Super::Notify(MeshComp, Animation);
auto Character = Cast<AAdvKitCharacter>(MeshComp->GetOwner());
if (!Character)
{
return;
}
auto Action = Cast<UAdvKitCA_ZoneTransition>(Character->GetActiveAction());
if (!Action)
{
return;
}
auto Args = Action->GetCurrentArguments();
if (!Args)
{
return;
}
Character->SetZone(Args->Zone, bSnapToZone);
}
| [
"pbarnhardt@helicalgames.net"
] | pbarnhardt@helicalgames.net |
f653b4e2a4be7678e4354adba769b05f33e56de6 | 328f2a34593da66732913b595f1e7dfd0860e361 | /lab 3/task (11).cpp | 27547a05d86b345d16069de36b5710d53a4cf7cb | [] | no_license | acmiitulab/ACMlabs | 71039fd33cc43a3a06fd00db15d090a7657e3715 | 43662bdcda87760f8ecd14f2f638811dd5aba57c | refs/heads/master | 2022-12-29T20:04:02.574324 | 2020-10-18T16:20:13 | 2020-10-18T16:20:13 | 305,133,688 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 480 | cpp | class Solution {
public:
bool isHappy(int n) {
map <int, int> mymap;
if (n == 1) return true;
mymap[n]++;
int sum = 0;
while (true) {
while (n != 0) {
sum += (n%10)*(n%10);
n/=10;
}
if (mymap[sum] != 0) return false;
cout<<sum<<" ";
mymap[sum]++;
n = sum;
sum = 0;
if (n == 1) return true;
}
}
}; | [
"60399541+mukhametkaly@users.noreply.github.com"
] | 60399541+mukhametkaly@users.noreply.github.com |
73d3d0d452f5e008d03d8ff269558eef79e67059 | 9a9387ddb7bdbaff28a6bc305770c69f7620c763 | /bfvmm/src/hve/arch/intel_x64/vmcall/vp_exit_op.cpp | 780ef656963fa1eb105a99036603000c7671dfee | [
"GPL-1.0-or-later",
"MIT"
] | permissive | Bareflank/boxy | 493b32531af3aaa497c45247124b399de738fbe1 | 762d989fcf4ad54eb1e2da4361c7258a712e34ad | refs/heads/master | 2021-07-07T13:18:36.168336 | 2020-07-23T14:16:33 | 2020-07-23T14:16:33 | 162,897,475 | 64 | 17 | MIT | 2020-09-10T14:51:34 | 2018-12-23T14:25:16 | C++ | UTF-8 | C++ | false | false | 1,853 | cpp | //
// Copyright (C) 2019 Assured Information Security, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <hve/arch/intel_x64/vcpu.h>
#include <hve/arch/intel_x64/domain.h>
#include <hve/arch/intel_x64/vmcall/vp_exit_op.h>
namespace boxy::intel_x64
{
vp_exit_op_handler::vp_exit_op_handler(
gsl::not_null<vcpu *> vcpu
) :
m_vcpu{vcpu}
{
if (vcpu->is_domU()) {
return;
}
vcpu->add_vmcall_handler({&vp_exit_op_handler::dispatch, this});
}
bool
vp_exit_op_handler::dispatch(vcpu *vcpu)
{
if (mv_hypercall_opcode(vcpu->rax()) != MV_VP_EXIT_OP_VAL) {
return false;
}
// TODO: Validate the handle
switch (mv_hypercall_index(vcpu->rax())) {
default:
break;
};
vcpu->set_rax(MV_STATUS_FAILURE_UNKNOWN_HYPERCALL);
return true;
}
}
| [
"rianquinn@gmail.com"
] | rianquinn@gmail.com |
eb037f8bee66a7d8dd2b8157cb37986f90cb7eac | 33b567f6828bbb06c22a6fdf903448bbe3b78a4f | /opencascade/StepVisual_SurfaceStyleFillArea.hxx | 51bf6a6568066116a21ad4b8d426bc7f0ce51a77 | [
"Apache-2.0"
] | permissive | CadQuery/OCP | fbee9663df7ae2c948af66a650808079575112b5 | b5cb181491c9900a40de86368006c73f169c0340 | refs/heads/master | 2023-07-10T18:35:44.225848 | 2023-06-12T18:09:07 | 2023-06-12T18:09:07 | 228,692,262 | 64 | 28 | Apache-2.0 | 2023-09-11T12:40:09 | 2019-12-17T20:02:11 | C++ | UTF-8 | C++ | false | false | 1,738 | hxx | // Created on: 1995-12-01
// Created by: EXPRESS->CDL V0.2 Translator
// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _StepVisual_SurfaceStyleFillArea_HeaderFile
#define _StepVisual_SurfaceStyleFillArea_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <Standard_Transient.hxx>
class StepVisual_FillAreaStyle;
class StepVisual_SurfaceStyleFillArea;
DEFINE_STANDARD_HANDLE(StepVisual_SurfaceStyleFillArea, Standard_Transient)
class StepVisual_SurfaceStyleFillArea : public Standard_Transient
{
public:
//! Returns a SurfaceStyleFillArea
Standard_EXPORT StepVisual_SurfaceStyleFillArea();
Standard_EXPORT void Init (const Handle(StepVisual_FillAreaStyle)& aFillArea);
Standard_EXPORT void SetFillArea (const Handle(StepVisual_FillAreaStyle)& aFillArea);
Standard_EXPORT Handle(StepVisual_FillAreaStyle) FillArea() const;
DEFINE_STANDARD_RTTIEXT(StepVisual_SurfaceStyleFillArea,Standard_Transient)
protected:
private:
Handle(StepVisual_FillAreaStyle) fillArea;
};
#endif // _StepVisual_SurfaceStyleFillArea_HeaderFile
| [
"adam.jan.urbanczyk@gmail.com"
] | adam.jan.urbanczyk@gmail.com |
bb330611c21f6592f06d0b3c8b3d163d6ea88e72 | 6b2a8dd202fdce77c971c412717e305e1caaac51 | /solutions_5708921029263360_0/C++/Frostfrog/main.cpp | e8ca449bfacb079f1923e2a311d8e411cefc6cad | [] | no_license | alexandraback/datacollection | 0bc67a9ace00abbc843f4912562f3a064992e0e9 | 076a7bc7693f3abf07bfdbdac838cb4ef65ccfcf | refs/heads/master | 2021-01-24T18:27:24.417992 | 2017-05-23T09:23:38 | 2017-05-23T09:23:38 | 84,313,442 | 2 | 4 | null | null | null | null | UTF-8 | C++ | false | false | 1,884 | cpp | #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <stdint.h>
#include <bitset>
#include <cmath>
#define INPUTFILE "c.in"
#define OUTPUTFILE "c.out"
using namespace std;
int J, P, S, K;
int C = 0;
int _ans;
int cur[64];
int ans[64];
struct ss {
int j, p, s;
} sss[64];
void gen()
{
C = 0;
for (int j=1;j<=J;++j) {
for (int p=1;p<=P;++p) {
for (int s=1;s<=S;++s) {
sss[C++] = {j,p,s};
}
}
}
}
int check2(ss o, int s, int len)
{
int cnt = 0;
for (int j=s;j<len;++j) {
int match = 0;
if (o.j == sss[cur[j]].j) match ++;
if (o.p == sss[cur[j]].p) match ++;
if (o.s == sss[cur[j]].s) match ++;
if (match >= 2) {
cnt ++;
}
}
return cnt;
}
bool check(int l) {
for (int i=0;i<l;++i) {
ss t;
t = sss[cur[i]]; t.j = -1;
if (check2(t, i+1, l) >= K) return false;
t = sss[cur[i]]; t.p = -1;
if (check2(t, i+1, l) >= K) return false;
t = sss[cur[i]]; t.s = -1;
if (check2(t, i+1, l) >= K) return false;
}
return true;
}
void dfs(int x, int l)
{
if (l + C - x < _ans ) return;
if (x >= C) {
if (l > _ans) {
for (int i=0;i<l;++i) {
ans[i] = cur[i];
}
_ans = l;
}
return;
}
cur[l] = x;
if (check(l+1)) {
dfs(x+1, l+1);
}
dfs(x+1, l);
}
void solve_one() {
cin >> J >> P >> S >> K;
_ans= 0;
dfs(0, 0);
cout << _ans << endl;
for (int i=0;i<_ans;++i) {
cout << sss[ans[i]].j << " " <<sss[ans[i]].p << " "<< sss[ans[i]].s << endl;
}
}
int main()
{
int T, cases = 0;
string dummy;
freopen(INPUTFILE,"r",stdin);
freopen(OUTPUTFILE,"w",stdout);
cin >> T;
getline(cin, dummy);
while (T--) {
cout << "case #" << ++cases << ": ";
solve_one();
// cout << endl;
}
return 0;
}
| [
"alexandra1.back@gmail.com"
] | alexandra1.back@gmail.com |
5271c64d83f0230cd6c9b4b65ab6db146a30355e | 34ba2340b90d6b5403cc889fb88f519d2f8e617f | /starShape.cpp | a2a1772ae289802190dbaf6f7d4fb5edbdda38f7 | [] | no_license | meganschmidt23/Tutoring-Work | 126a231fcdfd4498480eb113859964b4d7d6869a | 5809561b914cece8157389ad9802ed6ac63d6e50 | refs/heads/main | 2023-03-10T03:15:10.836520 | 2021-02-27T02:57:17 | 2021-02-27T02:57:17 | 337,133,253 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 640 | cpp | /* Write a program that reads an integer greater or
* equal to 2, n, and prints a shape of a nline
* hollow inverted pyramid of stars */
#include <iostream>
using namespace std;
int main(){
int n;
cout << "Enter an integer, greater or equal to 2:" << endl;
cin >> n;
for(int row = 1; row <=n; row++){
//Printing the spaces
for (int column = 1; column <= row; column++){
cout << " ":
}
// Hollow inverted triangle
for(int column = 1; column <= (n*2 - (2*row-1))){
if(row == 1 || column == 1 || j == (n*2 - (2 * row - 1))) {
cout << "*";
}
else {
cout << " ";
}
}
cout << "\n";
}
return 0;
} | [
"schmidtm6@hawkmail.newpaltz.edu"
] | schmidtm6@hawkmail.newpaltz.edu |
b1b5f6845eb4ece7cdb7e8831bcb7916565db8dd | 082f25f061e59b00e889404a62587437c7c0d25d | /include/Camera.h | 8fba0e1ba42071034e5884508a3beabacd288b4a | [
"MIT"
] | permissive | rGovers/Anny.Mei | 0b30b79ae39dd0a854f43fae544443341ed6c418 | 6329df8eb06ae9d03a4457518b26300942b7cc13 | refs/heads/master | 2020-05-27T21:37:38.964123 | 2020-04-14T08:49:19 | 2020-04-14T08:49:19 | 188,793,951 | 1 | 1 | null | 2019-05-29T06:56:47 | 2019-05-27T07:32:27 | C | UTF-8 | C++ | false | false | 334 | h | #pragma once
#include <glm/glm.hpp>
class StaticTransform;
class Camera
{
private:
glm::mat4 m_projection;
StaticTransform* m_transform;
protected:
public:
Camera();
~Camera();
StaticTransform* GetTransform() const;
void SetProjection(const glm::mat4& a_matrix);
glm::mat4 GetProjection() const;
};
| [
"govers.river.r@gmail.com"
] | govers.river.r@gmail.com |
6a959a91c61ce496ecf40f3b082fd43af6180ab1 | f72a85e80ab7ad4b255657a7923fb3b0c036593a | /src/sccommon.cpp | 53fbd6748d426ac5a1e21fe06c969295f0f918bd | [
"MIT"
] | permissive | ytop/ybtc | bafcb18bb6ade75311d8aeedeeccbf86a9320a8e | ae7f43928f017043a245d0e9c97d70a53ed20d8a | refs/heads/master | 2020-03-23T18:12:39.769670 | 2018-09-18T22:39:00 | 2018-09-18T22:39:00 | 141,895,597 | 3 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 1,226 | cpp | #include <scrlp.h>
#include <scsha3.h>
namespace sc
{
// ============= misc ==============
std::random_device s_fixedHashEngine;
/*** FIPS202 SHAKE VOFs ***/
defshake(128)
defshake(256)
/*** FIPS202 SHA3 FOFs ***/
defsha3(224)
defsha3(256)
defsha3(384)
defsha3(512)
bool sha3(bytesConstRef _input, bytesRef o_output)
{
// FIXME: What with unaligned memory?
if (o_output.size() != 32)
return false;
sha3_256(o_output.data(), 32, _input.data(), _input.size());
return true;
}
h256 EmptySHA3 = sha3(bytesConstRef());
const h256 EmptyTrie = sha3(rlp(""));
/// Convert the given value into h160 (160-bit unsigned integer) using the right 20 bytes.
Address right160(h256 const& _t)
{
Address ret(20);
memcpy(ret.data(), _t.data() + 12, 20);
return ret;
}
// Convert from a 256-bit integer stack/memory entry into a 160-bit Address hash.
// Currently we just pull out the right (low-order in BE) 160-bits.
Address asAddress(u256 _item)
{
return right160(h256(_item));
}
u256 fromAddress(Address _a)
{
/*
byte t[20];
byte* p_a = _a.data();
for (int i = 0; i < 20; i++)
t[i] = *(p_a + 19 - i);
return *((u160*)t);
*/
return (u160)_a;
}
} // namespace sc
| [
"jontera@gmail.com"
] | jontera@gmail.com |
545b7bd25c714e0953d617421109044ecebc297f | 9ec05c4303eb94f18d4eba3d86b399873121b0d6 | /Sample/Win32/SEP2PAppSDKDemo/SEP2PAppSDKDemoDlg.cpp | 86f8125f3df1e4db393b5390966b2b7a4beb799a | [] | no_license | ZHENGZX123/PCCramera | 8a92de1c16d3d3d0ac988247c7fd3c38be91c674 | d84bfe9e98f0817fd5be39cf756590c9a7d1b268 | refs/heads/master | 2021-01-01T19:33:31.483034 | 2017-07-28T06:12:35 | 2017-07-28T06:12:35 | 98,614,879 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 69,086 | cpp | // SEP2PAppSDKDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SEP2PAppSDKDemo.h"
#include "SEP2PAppSDKDemoDlg.h"
#include "DeviceInfo.h"
#include "AudioSample.h"
#include "SE_AudioCodec.h"
#include "SE_VideoCodec.h"
#include "Picture.h"
#include "CamObj.h"
//#include "../../../SEP2P_Define_Ex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define OM_UPDATE_DEVICE WM_USER+10
#define OM_UPDATE_UI WM_USER+11
#define UPDATE_UI_WPARAM_StatusBar 1
#define UPDATE_UI_WPARAM_Connect 2
#define UPDATE_UI_WPARAM_Talk 3
#define UPDATE_UI_WPARAM_MsgArrived 4
CString CSEP2PAppSDKDemoDlg::ms_csTitleStart[MAX_NUM_CHANNEL]={_T("Connect"), _T("StartVideo"), _T("StartAudio"), _T("StartTalk")};
CString CSEP2PAppSDKDemoDlg::ms_csTitleStop[MAX_NUM_CHANNEL] ={_T("Disconnect"), _T("StopVideo"), _T("StopAudio"), _T("StopTalk")};
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
//----{{User defined msg----------------------
#define SEP2P_MSG_EXT_CMD1 0x1000
#define SEP2P_MSG_EXT_CMD2 0x1001
typedef struct tag_SEP2P_MSG_EXT_SDFILE_REQ{
CHAR nAction; //0=list; 1=del;
CHAR reserve[7];
//CHAR chFilename[64];
}SEP2P_MSG_EXT_SDFILE_REQ;
typedef struct tag_SEP2P_MSG_EXT_SDFILE_RESP{
CHAR nAction; //0=list; 1=del;
CHAR nResult; //0=success; 1=fail
CHAR reserve[2];
INT32 nFileNum;
//CHAR chFilename[64];
}SEP2P_MSG_EXT_SDFILE_RESP;
//----}}User defined msg----------------------
// CSEP2PAppSDKDemoDlg dialog
CSEP2PAppSDKDemoDlg::CSEP2PAppSDKDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSEP2PAppSDKDemoDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bStartLanSearch=1;
memset(m_arrDevSearched, 0, sizeof(m_arrDevSearched));
m_pHandleG726 =NULL;
m_pHandleAdpcm=NULL;
m_pHandleH264=NULL;
m_bExitingApp=0;
for(int i=0; i<MAX_NUM_CHANNEL; i++) m_pObjCams[i]=new CCamObj(i, this);
m_chFirstFilePath[0]='\0';
m_nCruiseCount=0;
}
void CSEP2PAppSDKDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT3, m_edtLog);
DDX_Control(pDX, IDC_COMBO1, m_ctlComboDev);
DDX_Control(pDX, IDC_COMBO2, m_ctlComboReqStr);
DDX_Control(pDX, IDC_COMBO3, m_ctlComboChn);
}
BEGIN_MESSAGE_MAP(CSEP2PAppSDKDemoDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_WM_DESTROY()
ON_MESSAGE(OM_UPDATE_DEVICE, &CSEP2PAppSDKDemoDlg::OnUpdateDeviceSearched)
ON_MESSAGE(OM_UPDATE_UI, &CSEP2PAppSDKDemoDlg::OnUpdateUI)
ON_BN_CLICKED(IDC_LANSEARCH, &CSEP2PAppSDKDemoDlg::OnBnClickedLansearch)
ON_BN_CLICKED(IDC_CLEAR_LOG, &CSEP2PAppSDKDemoDlg::OnBnClickedClearLog)
ON_CONTROL_RANGE(BN_CLICKED, IDC_CONNECT1, IDC_EDIT_DEVICE4, OnButtonsRange)
ON_BN_CLICKED(IDC_GET_REQ, &CSEP2PAppSDKDemoDlg::OnBnClickedGetReq)
ON_BN_CLICKED(IDC_SET_REQ, &CSEP2PAppSDKDemoDlg::OnBnClickedSetReq)
END_MESSAGE_MAP()
// CSEP2PAppSDKDemoDlg message handlers
BOOL CSEP2PAppSDKDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CString csText;
UINT32 nVer=SEP2P_GetSDKVersion(NULL, 0);
CHAR *pVer=(CHAR *)&nVer;
csText.Format(_T("AppSDK v%d.%d.%d.%d"), *(pVer+3),*(pVer+2),*(pVer+1),*(pVer+0));
SetDlgItemText(IDC_APIVER, csText);
CWnd *pVideo=NULL;
pVideo=GetDlgItem(IDC_VIDEO0);
if(pVideo) {
m_pObjCams[0]->SetHDC(pVideo->GetDC()->GetSafeHdc());
pVideo->GetClientRect(m_pObjCams[0]->GetRect());
}
m_pObjCams[0]->SetCtrlEdit(GetDlgItem(IDC_EDIT_DEVICE1));
m_pObjCams[0]->SetCtrlConnect(GetDlgItem(IDC_CONNECT1));
m_pObjCams[0]->SetCtrlStartVideo(GetDlgItem(IDC_START_VIDEO1));
m_pObjCams[0]->SetCtrlStartAudio(GetDlgItem(IDC_START_AUDIO1));
m_pObjCams[0]->SetCtrlStartTalk(GetDlgItem(IDC_START_TALK1));
m_pObjCams[0]->SetCtrlStatus(GetDlgItem(IDC_STATUS1));
m_pObjCams[0]->GetCtrlStartVideo()->EnableWindow(FALSE);
m_pObjCams[0]->GetCtrlStartAudio()->EnableWindow(FALSE);
m_pObjCams[0]->GetCtrlStartTalk()->EnableWindow(FALSE);
m_ctlComboChn.EnableWindow(FALSE);
m_ctlComboChn.SetCurSel(0);
pVideo=GetDlgItem(IDC_VIDEO1);
if(pVideo) {
m_pObjCams[1]->SetHDC(pVideo->GetDC()->GetSafeHdc());
pVideo->GetClientRect(m_pObjCams[1]->GetRect());
}
m_pObjCams[1]->SetCtrlEdit(GetDlgItem(IDC_EDIT_DEVICE2));
m_pObjCams[1]->SetCtrlConnect(GetDlgItem(IDC_CONNECT2));
m_pObjCams[1]->SetCtrlStartVideo(GetDlgItem(IDC_START_VIDEO2));
m_pObjCams[1]->SetCtrlStartAudio(GetDlgItem(IDC_START_AUDIO2));
m_pObjCams[1]->SetCtrlStartTalk(GetDlgItem(IDC_START_TALK2));
m_pObjCams[1]->SetCtrlStatus(GetDlgItem(IDC_STATUS2));
m_pObjCams[1]->GetCtrlStartVideo()->EnableWindow(FALSE);
m_pObjCams[1]->GetCtrlStartAudio()->EnableWindow(FALSE);
m_pObjCams[1]->GetCtrlStartTalk()->EnableWindow(FALSE);
pVideo=GetDlgItem(IDC_VIDEO2);
if(pVideo) {
m_pObjCams[2]->SetHDC(pVideo->GetDC()->GetSafeHdc());
pVideo->GetClientRect(m_pObjCams[2]->GetRect());
}
m_pObjCams[2]->SetCtrlEdit(GetDlgItem(IDC_EDIT_DEVICE3));
m_pObjCams[2]->SetCtrlConnect(GetDlgItem(IDC_CONNECT3));
m_pObjCams[2]->SetCtrlStartVideo(GetDlgItem(IDC_START_VIDEO3));
m_pObjCams[2]->SetCtrlStartAudio(GetDlgItem(IDC_START_AUDIO3));
m_pObjCams[2]->SetCtrlStartTalk(GetDlgItem(IDC_START_TALK3));
m_pObjCams[2]->SetCtrlStatus(GetDlgItem(IDC_STATUS3));
m_pObjCams[2]->GetCtrlStartVideo()->EnableWindow(FALSE);
m_pObjCams[2]->GetCtrlStartAudio()->EnableWindow(FALSE);
m_pObjCams[2]->GetCtrlStartTalk()->EnableWindow(FALSE);
pVideo=GetDlgItem(IDC_VIDEO3);
if(pVideo) {
m_pObjCams[3]->SetHDC(pVideo->GetDC()->GetSafeHdc());
pVideo->GetClientRect(m_pObjCams[3]->GetRect());
}
m_pObjCams[3]->SetCtrlEdit(GetDlgItem(IDC_EDIT_DEVICE4));
m_pObjCams[3]->SetCtrlConnect(GetDlgItem(IDC_CONNECT4));
m_pObjCams[3]->SetCtrlStartVideo(GetDlgItem(IDC_START_VIDEO4));
m_pObjCams[3]->SetCtrlStartAudio(GetDlgItem(IDC_START_AUDIO4));
m_pObjCams[3]->SetCtrlStartTalk(GetDlgItem(IDC_START_TALK4));
m_pObjCams[3]->SetCtrlStatus(GetDlgItem(IDC_STATUS4));
m_pObjCams[3]->GetCtrlStartVideo()->EnableWindow(FALSE);
m_pObjCams[3]->GetCtrlStartAudio()->EnableWindow(FALSE);
m_pObjCams[3]->GetCtrlStartTalk()->EnableWindow(FALSE);
SetBtnTitle(0,1);
SetBtnTitle(1,1);
SetBtnTitle(2,1);
SetBtnTitle(3,1);
CSEP2PAppSDKDemoApp::GetAppPath(m_csAppPath);
ReadDevListFromTxt();
m_ctlComboDev.SetCurSel(0);
m_ctlComboReqStr.SetCurSel(0);
CCamObj::P2PAPI_Version();
CCamObj::P2PAPI_Init();
int n=sizeof(8);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSEP2PAppSDKDemoDlg::OnDestroy()
{
m_bExitingApp=1;
CDialog::OnDestroy();
WriteDevListToTxt();
int i=0, nMsgDataSize=0;
CHAR *pMsgData=NULL;
for(i=0;i<MAX_NUM_CHANNEL; i++){
if(i==0){
MSG_STOP_AUDIO stStopAudio;
memset(&stStopAudio, 0, sizeof(stStopAudio));
stStopAudio.nChannel=m_ctlComboChn.GetCurSel();
MSG_STOP_VIDEO stStopVideo;
memset(&stStopVideo, 0, sizeof(stStopVideo));
stStopVideo.nChannel=stStopAudio.nChannel;
MSG_STOP_TALK stStopTalk;
memset(&stStopTalk, 0, sizeof(stStopTalk));
stStopTalk.nChannel=stStopAudio.nChannel;
m_pObjCams[i]->P2PAPI_SendMsg(SEP2P_MSG_STOP_AUDIO, (CHAR *)&stStopAudio, sizeof(stStopAudio));
m_pObjCams[i]->P2PAPI_SendMsg(SEP2P_MSG_STOP_VIDEO, (CHAR *)&stStopVideo, sizeof(stStopVideo));
m_pObjCams[i]->P2PAPI_SendMsg(SEP2P_MSG_STOP_TALK, (CHAR *)&stStopTalk, sizeof(stStopTalk));
}else{
m_pObjCams[i]->P2PAPI_SendMsg(SEP2P_MSG_STOP_AUDIO, NULL, 0);
m_pObjCams[i]->P2PAPI_SendMsg(SEP2P_MSG_STOP_VIDEO, NULL, 0);
m_pObjCams[i]->P2PAPI_SendMsg(SEP2P_MSG_STOP_TALK, NULL, 0);
}
m_pObjCams[i]->P2PAPI_Disconnect();
}
CCamObj::P2PAPI_DeInit();
for(i=0; i<MAX_NUM_CHANNEL; i++)
{
if(m_pObjCams[i]){
delete m_pObjCams[i];
m_pObjCams[i]=NULL;
}
}
}
void CSEP2PAppSDKDemoDlg::ReadDevListFromTxt()
{
CStdioFile objFile;
CString csFileName, csLine;
csFileName.Format(_T("%sSEP2P_API_DEV.txt"), m_csAppPath);
BOOL bRet=objFile.Open(csFileName, CFile::modeRead);
if(bRet){
int iRow=0;
char chDID[128]={0};
while(objFile.ReadString(csLine)){
switch(iRow){
case 0:
CharFromWSTRU(CP_OEMCP, csLine, csLine.GetLength(), chDID);
strcpy(m_pObjCams[0]->GetDID(), chDID);
break;
case 1:
wcscpy(m_pObjCams[0]->GetUsername(), csLine.GetBuffer());
csLine.ReleaseBuffer();
break;
case 2:
wcscpy(m_pObjCams[0]->GetPasswd(), csLine.GetBuffer());
csLine.ReleaseBuffer();
break;
case 3:
CharFromWSTRU(CP_OEMCP, csLine, csLine.GetLength(), chDID);
strcpy(m_pObjCams[1]->GetDID(), chDID);
break;
case 4:
wcscpy(m_pObjCams[1]->GetUsername(), csLine.GetBuffer());
csLine.ReleaseBuffer();
break;
case 5:
wcscpy(m_pObjCams[1]->GetPasswd(), csLine.GetBuffer());
csLine.ReleaseBuffer();
break;
case 6:
CharFromWSTRU(CP_OEMCP, csLine, csLine.GetLength(), chDID);
strcpy(m_pObjCams[2]->GetDID(), chDID);
break;
case 7:
wcscpy(m_pObjCams[2]->GetUsername(), csLine.GetBuffer());
csLine.ReleaseBuffer();
break;
case 8:
wcscpy(m_pObjCams[2]->GetPasswd(), csLine.GetBuffer());
csLine.ReleaseBuffer();
break;
case 9:
CharFromWSTRU(CP_OEMCP, csLine, csLine.GetLength(), chDID);
strcpy(m_pObjCams[3]->GetDID(), chDID);
break;
case 10:
wcscpy(m_pObjCams[3]->GetUsername(), csLine.GetBuffer());
csLine.ReleaseBuffer();
break;
case 11:
wcscpy(m_pObjCams[3]->GetPasswd(), csLine.GetBuffer());
csLine.ReleaseBuffer();
break;
default:;
}
iRow++;
if(iRow>=12) break;
}
objFile.Close();
}
}
void CSEP2PAppSDKDemoDlg::WriteDevListToTxt()
{
CStdioFile objFile;
CString csFileName, csLine, csCrLr=_T("\n");
csFileName.Format(_T("%sSEP2P_API_DEV.txt"), m_csAppPath);
BOOL bRet=objFile.Open(csFileName, CFile::modeReadWrite | CFile::modeCreate);
if(bRet){
CString csDID;
BSTRFromCharU(CP_OEMCP, m_pObjCams[0]->GetDID(), csDID);
objFile.WriteString(csDID);
objFile.WriteString(csCrLr);
objFile.WriteString(CString(m_pObjCams[0]->GetUsername()));
objFile.WriteString(csCrLr);
objFile.WriteString(CString(m_pObjCams[0]->GetPasswd()));
objFile.WriteString(csLine);
objFile.WriteString(csCrLr);
BSTRFromCharU(CP_OEMCP, m_pObjCams[1]->GetDID(), csDID);
objFile.WriteString(csDID);
objFile.WriteString(csCrLr);
objFile.WriteString(CString(m_pObjCams[1]->GetUsername()));
objFile.WriteString(csCrLr);
objFile.WriteString(CString(m_pObjCams[1]->GetPasswd()));
objFile.WriteString(csLine);
objFile.WriteString(csCrLr);
BSTRFromCharU(CP_OEMCP, m_pObjCams[2]->GetDID(), csDID);
objFile.WriteString(csDID);
objFile.WriteString(csCrLr);
objFile.WriteString(CString(m_pObjCams[2]->GetUsername()));
objFile.WriteString(csCrLr);
objFile.WriteString(CString(m_pObjCams[2]->GetPasswd()));
objFile.WriteString(csLine);
objFile.WriteString(csCrLr);
BSTRFromCharU(CP_OEMCP, m_pObjCams[3]->GetDID(), csDID);
objFile.WriteString(csDID);
objFile.WriteString(csCrLr);
objFile.WriteString(CString(m_pObjCams[3]->GetUsername()));
objFile.WriteString(csCrLr);
objFile.WriteString(CString(m_pObjCams[3]->GetPasswd()));
objFile.WriteString(csLine);
objFile.WriteString(csCrLr);
objFile.Close();
}
}
void CSEP2PAppSDKDemoDlg::SetBtnTitle(int nDeviceNo, char bStart)
{
if(nDeviceNo<0 || nDeviceNo>=MAX_NUM_CHANNEL) return;
if(bStart){
m_pObjCams[nDeviceNo]->GetCtrlConnect()->SetWindowText(ms_csTitleStart[0]);
m_pObjCams[nDeviceNo]->GetCtrlStartVideo()->SetWindowText(ms_csTitleStart[1]);
m_pObjCams[nDeviceNo]->GetCtrlStartAudio()->SetWindowText(ms_csTitleStart[2]);
m_pObjCams[nDeviceNo]->GetCtrlStartTalk()->SetWindowText(ms_csTitleStart[3]);
}else{
m_pObjCams[nDeviceNo]->GetCtrlConnect()->SetWindowText(ms_csTitleStop[0]);
m_pObjCams[nDeviceNo]->GetCtrlStartVideo()->SetWindowText(ms_csTitleStop[1]);
m_pObjCams[nDeviceNo]->GetCtrlStartAudio()->SetWindowText(ms_csTitleStop[2]);
m_pObjCams[nDeviceNo]->GetCtrlStartTalk()->SetWindowText(ms_csTitleStop[3]);
}
}
void CSEP2PAppSDKDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if((nID & 0xFFF0) == IDM_ABOUTBOX){
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}else{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSEP2PAppSDKDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}else{
CDialog::OnPaint();
}
}
LRESULT CSEP2PAppSDKDemoDlg::OnUpdateDeviceSearched(WPARAM wParam, LPARAM lParam)
{
CHAR chText[255]={0};
CString csOld, csText, csTmp;
GetDlgItemText(IDC_EDIT3, csOld);
sprintf(chText, "%C \t%s\t%s\r\n",m_arrDevSearched[wParam].product_type[0]==0?'L':'M', m_arrDevSearched[wParam].chDID, m_arrDevSearched[wParam].chIPAddr);
BSTRFromCharU(CP_OEMCP, chText, csTmp);
csText.Format(_T("%s%s"), csOld, csTmp);
SetDlgItemText(IDC_EDIT3, csText);
m_edtLog.LineScroll(m_edtLog.GetLineCount(), 0);
return 0L;
}
LRESULT CSEP2PAppSDKDemoDlg::OnUpdateUI(WPARAM wParam, LPARAM lParam)
{
switch(wParam){
case UPDATE_UI_WPARAM_StatusBar:
break;
case UPDATE_UI_WPARAM_Connect:{
int nDeviceNo=HIWORD(lParam);
int nConnectStatus=LOWORD(lParam);
if(nDeviceNo<0 || nDeviceNo>=MAX_NUM_CHANNEL) break;
CString csText;
CHAR chText[128]={0};
if(nConnectStatus==CONNECT_STATUS_CONNECTED){
sprintf(chText, "%s Online", m_pObjCams[nDeviceNo]->GetDID());
BSTRFromCharU(CP_OEMCP, chText, csText);
m_pObjCams[nDeviceNo]->GetCtrlStatus()->SetWindowText(csText);
m_pObjCams[nDeviceNo]->GetCtrlStartVideo()->EnableWindow(TRUE);
m_pObjCams[nDeviceNo]->GetCtrlStartAudio()->EnableWindow(TRUE);
m_pObjCams[nDeviceNo]->GetCtrlStartTalk()->EnableWindow(TRUE);
if(nDeviceNo==0) m_ctlComboChn.EnableWindow(TRUE);
//m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_DEVICE_VERSION_REQ, NULL, 0);
}else {
if(nConnectStatus==CONNECT_STATUS_CONNECTING) sprintf(chText, "%s Connecting...", m_pObjCams[nDeviceNo]->GetDID());
else sprintf(chText, "%s Connect failed(%d)", m_pObjCams[nDeviceNo]->GetDID(), nConnectStatus);
BSTRFromCharU(CP_OEMCP, chText, csText);
m_pObjCams[nDeviceNo]->GetCtrlStatus()->SetWindowText(csText);
m_pObjCams[nDeviceNo]->GetCtrlStartVideo()->EnableWindow(FALSE);
m_pObjCams[nDeviceNo]->GetCtrlStartAudio()->EnableWindow(FALSE);
m_pObjCams[nDeviceNo]->GetCtrlStartTalk()->EnableWindow(FALSE);
if(nDeviceNo==0) m_ctlComboChn.EnableWindow(FALSE);
}
}break;
case UPDATE_UI_WPARAM_Talk:{
int nDeviceNo=HIWORD(lParam);
int nResult=LOWORD(lParam);
if(nResult==0) m_pObjCams[nDeviceNo]->GetCtrlStatus()->SetWindowText(_T("Talking..."));
else if(nResult==1) m_pObjCams[nDeviceNo]->GetCtrlStatus()->SetWindowText(_T("Other user is talking"));
else if(nResult==2) m_pObjCams[nDeviceNo]->GetCtrlStatus()->SetWindowText(_T("Talk failed"));
else m_pObjCams[nDeviceNo]->GetCtrlStatus()->SetWindowText(_T("Talk stopped"));
}break;
case UPDATE_UI_WPARAM_MsgArrived:{
MSG_INFO *pMsgInfo=(MSG_INFO *)lParam;
if(pMsgInfo->nMsgType==SEP2P_MSG_SNAP_PICTURE_RESP){
CHAR chTmp[256]={0};
sprintf(chTmp, "SEP2P_MSG_SNAP_PICTURE_RESP, pMsgInfo->nMsgSize=%d\n", pMsgInfo->nMsgSize);
OutputDebugStringA(chTmp);
FILE *fp=fopen("d:\\snapshot.jpg", "wb");
if(fp && pMsgInfo->nMsgSize>0){
fwrite(pMsgInfo->pMsg, 1, pMsgInfo->nMsgSize, fp);
fclose(fp);
}
}
TRACE_Msg(pMsgInfo);
}break;
default:;
}
return 0L;
}
void CSEP2PAppSDKDemoDlg::TRACE_Msg(MSG_INFO *pMsgInfo)
{
if(pMsgInfo==NULL) return;
CHAR chTmp[1024]={0};
switch(pMsgInfo->nMsgType)
{
case SEP2P_MSG_GET_CAMERA_PARAM_RESP:{
MSG_GET_CAMERA_PARAM_RESP *pResp=(MSG_GET_CAMERA_PARAM_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s GET_CAMERA_PARAM_RESP, nResolution=%d bOSD=%d\n", m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(), pResp->nResolution, pResp->bOSD);
OutputDebugStringA(chTmp);
}break;
case SEP2P_MSG_GET_CURRENT_WIFI_RESP:{
MSG_GET_CURRENT_WIFI_RESP *pResp=(MSG_GET_CURRENT_WIFI_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s GET_CURRENT_WIFI_RESP, nResolution=%d\n", m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(), pResp->chSSID);
OutputDebugStringA(chTmp);
}break;
case SEP2P_MSG_GET_WIFI_LIST_RESP:{
MSG_GET_WIFI_LIST_RESP *pResp=(MSG_GET_WIFI_LIST_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s MSG_GET_WIFI_LIST_RESP, nResultCount=%d\n", m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(), pResp->nResultCount);
OutputDebugStringA(chTmp);
for(int i=0; i<pResp->nResultCount; i++){
sprintf(chTmp, "i=%d %s\n",i, pResp->wifi[i].chSSID);
OutputDebugStringA(chTmp);
}
}break;
case SEP2P_MSG_GET_USER_INFO_RESP:{
MSG_GET_USER_INFO_RESP *pResp=(MSG_GET_USER_INFO_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s GET_USER_INFO_RESP, user1=%s, curUser=%s roleid=%d, chAdmin=%s\n", m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(),
pResp->chVisitor, pResp->chCurUser, pResp->nCurUserRoleID, pResp->chAdmin);
OutputDebugStringA(chTmp);
}break;
case SEP2P_MSG_GET_DATETIME_RESP:{
MSG_GET_DATETIME_RESP *pResp=(MSG_GET_DATETIME_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s MSG_GET_DATETIME_RESP, nSecToNow=%d nSecTimeZone=%d\n", m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(),pResp->nSecToNow, pResp->nSecTimeZone);
OutputDebugStringA(chTmp);
}break;
case SEP2P_MSG_GET_FTP_INFO_RESP:{
MSG_GET_FTP_INFO_RESP *pResp=(MSG_GET_FTP_INFO_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s GET_FTP_INFO_RESP, chFTPSvr=%s chDir=%s chUser=%s\n", m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(),
pResp->chFTPSvr,pResp->chDir,pResp->chUser);
OutputDebugStringA(chTmp);
}break;
case SEP2P_MSG_GET_EMAIL_INFO_RESP:{
MSG_GET_EMAIL_INFO_RESP *pResp=(MSG_GET_EMAIL_INFO_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s GET_EMAIL_INFO_RESP, bHasTestFunction=%d chSMTPSvr=%s sender=%s subject=%s\n",
m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(),
pResp->bHasTestFunction,
pResp->chSMTPSvr,pResp->chSender,pResp->chSubject);
OutputDebugStringA(chTmp);
}break;
case SEP2P_MSG_GET_ALARM_INFO_RESP:{
MSG_GET_ALARM_INFO_RESP *pResp=(MSG_GET_ALARM_INFO_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s MSG_GET_ALARM_INFO_RESP, bHasTempHumiFunction=%d bMDEnable=%d,%d,%d,%d nMDSensitivity=%d,%d,%d,%d position=(%d,%d,%d,%d),(%d,%d,%d,%d),(%d,%d,%d,%d),(%d,%d,%d,%d)\n\n",
m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(),
pResp->bHasTempHumiFunction,
pResp->bMDEnable[0],pResp->bMDEnable[1],pResp->bMDEnable[2],pResp->bMDEnable[3],
pResp->nMDSensitivity[0],pResp->nMDSensitivity[1],pResp->nMDSensitivity[2],pResp->nMDSensitivity[3],
pResp->md_x[0], pResp->md_y[0],pResp->md_width[0],pResp->md_height[0],
pResp->md_x[1], pResp->md_y[1],pResp->md_width[1],pResp->md_height[1],
pResp->md_x[2], pResp->md_y[2],pResp->md_width[2],pResp->md_height[2],
pResp->md_x[3], pResp->md_y[3],pResp->md_width[3],pResp->md_height[3]);
OutputDebugStringA(chTmp);
}break;
case SEP2P_MSG_GET_SDCARD_REC_PARAM_RESP:{
MSG_GET_SDCARD_REC_PARAM_RESP *pResp=(MSG_GET_SDCARD_REC_PARAM_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s MSG_GET_SDCARD_REC_PARAM_RESP, bRecordCoverInSDCard=%d nRecordTimeLen=%d\n", m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(),
pResp->bRecordCoverInSDCard, pResp->nRecordTimeLen);
OutputDebugStringA(chTmp);
}break;
case SEP2P_MSG_GET_DEVICE_VERSION_RESP:{
MSG_GET_DEVICE_VERSION_RESP *pResp=(MSG_GET_DEVICE_VERSION_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s GET_DEVICE_VERSION_RESP, product_series=%C, fwddns_app_ver=%s fwp2p_app_ver=%s fwp2p_app_buildtime=%s imn_ver=0x%X is_push_function=%d %s\n",
m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(), pResp->product_series[0],
pResp->chFwddns_app_ver, pResp->chFwp2p_app_ver, pResp->chFwp2p_app_buildtime,
pResp->imn_ver_of_device, pResp->is_push_function, pResp->imn_server_port);
OutputDebugStringA(chTmp);
}break;
case SEP2P_MSG_GET_IPUSH_INFO_RESP:{
MSG_GET_IPUSH_INFO_RESP *pResp=(MSG_GET_IPUSH_INFO_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s GET_IPUSH_INFO_RESP bEnable=%d nResult=%d\n", m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(), pResp->bEnable, pResp->nResult);
OutputDebugStringA(chTmp);
}break;
case SEP2P_MSG_SET_IPUSH_INFO_RESP:{
MSG_GET_IPUSH_INFO_RESP *pResp=(MSG_GET_IPUSH_INFO_RESP *)pMsgInfo->pMsg;
sprintf(chTmp, "%s SET_IPUSH_INFO_RESP bEnable=%d nResult=%d\n", m_pObjCams[pMsgInfo->nDeviceNo]->GetDID(), pResp->bEnable, pResp->nResult);
OutputDebugStringA(chTmp);
}break;
default:;
}
if(pMsgInfo){
if(pMsgInfo->pMsg) {
free(pMsgInfo->pMsg);
pMsgInfo->pMsg=NULL;
}
free(pMsgInfo);
pMsgInfo=NULL;
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSEP2PAppSDKDemoDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CSEP2PAppSDKDemoDlg::DoSearch(CHAR* pData, UINT32 nDataSize)
{
SEARCH_RESP *pSearchResp=(SEARCH_RESP *)pData;
int i=0, iPosInserted=-1, bExist=0;
DEVICE_SEARCHED *pDevSearch=NULL;
for(i=0; i<MAX_NUM_SEARCH_ON_LAN; i++){
pDevSearch=&m_arrDevSearched[i];
if(iPosInserted==-1 && !pDevSearch->bUsed) iPosInserted=i;
if(pDevSearch->bUsed && memcmp(pDevSearch->chDID, pSearchResp->szDeviceID, MAX_LEN_DID)==0){
bExist=1;
break;
}
}
if(!bExist){
pDevSearch=&m_arrDevSearched[iPosInserted];
strcpy(pDevSearch->chDID, pSearchResp->szDeviceID);
strcpy(pDevSearch->chIPAddr, pSearchResp->szIpAddr);
pDevSearch->product_type[0]=pSearchResp->product_type[0];
pDevSearch->product_type[1]=pSearchResp->product_type[1];
pDevSearch->bUsed=1;
//TRACE(_T("DoSearchCallback,i=%d %d %s\n"), i, iPosInserted, pDevSearch->chDID);
PostMessage(OM_UPDATE_DEVICE, iPosInserted, 0L);
}
}
void CSEP2PAppSDKDemoDlg::WriteLog(CHAR *format, ...)
{
#ifndef _DEBUG
CHAR chLog[400]={0};
CString csFilename;
FILE *fp=NULL;
csFilename.Format(_T("%s\\connect.log"), m_csAppPath);
CharFromWSTRU(CP_OEMCP, csFilename, csFilename.GetLength(), chLog);
fp=fopen(chLog, "a+");
if(fp){
memset(chLog, 0, sizeof(chLog));
va_list ap;
time_t timep;
struct tm *p=NULL;
time (&timep);
p = localtime (&timep);
sprintf(chLog,"%04d-%02d-%02d %02d:%02d:%02d ",p->tm_year+1900,p->tm_mon+1,p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
va_start(ap, format);
vsprintf(&chLog[20], format,ap);
va_end(ap);
fwrite(chLog, 1, strlen(chLog), fp);
fclose(fp);
}
#endif
}
void CSEP2PAppSDKDemoDlg::DoRecvMsg(UCHAR nDeviceNo, UINT32 nMsgType, CHAR* pMsg, UINT32 nMsgSize)
{
TRACE(_T("DoRecvMsgCallback] nDeviceNo=%d, nMsgType=0x%X, nMsgSize=%d\n"),nDeviceNo, nMsgType, nMsgSize);
if(nMsgType%2==1){
int nRespResult=pMsg[0];
//TRACE(_T("DoRecvMsgCallback] nDeviceNo=%d, nMsgType=0x%X, nRespResult=%d\n"),nDeviceNo, nMsgType, nRespResult);
}
if(nMsgType==SEP2P_MSG_CONNECT_STATUS){
MSG_CONNECT_STATUS *pConnectStatus=(MSG_CONNECT_STATUS *)pMsg;
PostMessage(OM_UPDATE_UI, UPDATE_UI_WPARAM_Connect, MAKELPARAM(pConnectStatus->eConnectStatus, nDeviceNo));
TRACE(_T("DoRecvMsgCallback] SEP2P_MSG_CONNECT_STATUS eConnectStatus=%d\n"), pConnectStatus->eConnectStatus);
if(pConnectStatus->eConnectStatus==CONNECT_STATUS_CONNECTED){
CHAR chIP[3][24];
strcpy(chIP[0],inet_ntoa(pConnectStatus->stRemoteAddr.sin_addr));
strcpy(chIP[1],inet_ntoa(pConnectStatus->stMyLocalAddr.sin_addr));
strcpy(chIP[2],inet_ntoa(pConnectStatus->stMyWanAddr.sin_addr));
WriteLog("%s CONNECT_STATUS_CONNECTED: %s; Remote:%s:%d MyLAN: %s:%d MyWAN: %s:%d\n",
m_pObjCams[nDeviceNo]->GetDID(),
pConnectStatus->eConnectMode==CONNECT_MODE_P2P ? "P2P" : "Relay",
chIP[0], ntohs(pConnectStatus->stRemoteAddr.sin_port),
chIP[1], ntohs(pConnectStatus->stMyLocalAddr.sin_port),
chIP[2], ntohs(pConnectStatus->stMyWanAddr.sin_port));
}
}else if(nMsgType==SEP2P_MSG_CONNECT_MODE){
INT32 *pConnectMode =(INT32 *)pMsg;
if(*pConnectMode==CONNECT_MODE_P2P) TRACE(_T("DoRecvMsgCallback] SEP2P_MSG_CONNECT_MODE=P2P\n"));
else TRACE(_T("DoRecvMsgCallback] SEP2P_MSG_CONNECT_MODE=RLY\n"));
}else if(nMsgType==SEP2P_MSG_START_TALK_RESP){
MSG_START_TALK_RESP *pTalkResp=(MSG_START_TALK_RESP *)pMsg;
TRACE(_T("DoRecvMsgCallback] TalkResp=%d\n"), pTalkResp->result);
if(pTalkResp->result==0) {
//1>stop talk of the other device
//......
//2>start this talk
AV_PARAMETER *pAVParam=m_pObjCams[nDeviceNo]->GetAVParameter();
if(pAVParam->nAudioCodecID==AV_CODECID_AUDIO_AAC) m_objSample.StartSample(nDeviceNo,AUDIO_SAMPLE_RATE_16K, OnSampleCallback, this);
else m_objSample.StartSample(nDeviceNo,AUDIO_SAMPLE_RATE_8K, OnSampleCallback, this);
}
PostMessage(OM_UPDATE_UI, UPDATE_UI_WPARAM_Talk, MAKELPARAM(pTalkResp->result, nDeviceNo));
}else if(nMsgType==SEP2P_MSG_GET_WIFI_LIST_RESP){
MSG_GET_WIFI_LIST_RESP *pResp=(MSG_GET_WIFI_LIST_RESP *)pMsg;
TRACE(_T("DoRecvMsgCallback] nResultCount=%d\n"),pResp->nResultCount);
}else if(nMsgType==SEP2P_MSG_GET_CAMERA_PARAM_RESP){
MSG_GET_CAMERA_PARAM_RESP *pResp=(MSG_GET_CAMERA_PARAM_RESP *)pMsg;
TRACE(_T("DoRecvMsgCallback] MSG_GET_CAMERA_PARAM_RESP, nFlip=%d, nIRLed=%d bOSD=0x%X micvol=%d spkvol=%d\n"),
pResp->nFlip, pResp->nIRLed, pResp->bOSD, pResp->nMICVolume, pResp->nSPKVolume);
}else if(nMsgType==SEP2P_MSG_SET_CAMERA_PARAM_RESP){
MSG_SET_CAMERA_PARAM_RESP *pResp=(MSG_SET_CAMERA_PARAM_RESP *)pMsg;
TRACE(_T("DoRecvMsgCallback] result=%d,nBitMaskToSet=0x%X\n"), pResp->result, pResp->nBitMaskToSet);
}else if(nMsgType==SEP2P_MSG_GET_USER_INFO_RESP){
MSG_GET_USER_INFO_RESP *pResp=(MSG_GET_USER_INFO_RESP *)pMsg;
OutputDebugStringA(pResp->chAdmin);
}else if(nMsgType==SEP2P_MSG_GET_UART_CTRL_RESP){
MSG_GET_UART_CTRL_RESP *pResp=(MSG_GET_UART_CTRL_RESP *)pMsg;
char chTmp[256]={0};
sprintf(chTmp, "DoRecvMsgCallback] SEP2P_MSG_GET_UART_CTRL_RESP, chUartAlarmServer=%s,nUartAlarmServerPort=%d\n", pResp->chUartAlarmServer, pResp->nUartAlarmServerPort);
OutputDebugStringA(chTmp);
}else if(nMsgType==SEP2P_MSG_EXT_CMD1){ //User defined msg response
OutputDebugStringA(pMsg);
}else if(nMsgType==SEP2P_MSG_EXT_CMD2){ //User defined msg response
SEP2P_MSG_EXT_SDFILE_RESP *pResp=(SEP2P_MSG_EXT_SDFILE_RESP *)pMsg;
CHAR *pFile=pMsg+sizeof(SEP2P_MSG_EXT_SDFILE_RESP);
CHAR chTmp[128];
for(int kk=0; kk<pResp->nFileNum; kk++){
sprintf(chTmp, "file%d=%s\n", kk, pFile+kk*64);
OutputDebugStringA(chTmp);
}
}else if(nMsgType==SEP2P_MSG_GET_CUSTOM_PARAM_RESP){
MSG_GET_CUSTOM_PARAM_RESP *pResp=(MSG_GET_CUSTOM_PARAM_RESP *)pMsg;
CHAR chTmp[128];
sprintf(chTmp,"result=%d %s=%s\n", pResp->result, pResp->chParamName, pResp->chParamValue);
OutputDebugStringA(chTmp);
}else if(nMsgType==SEP2P_MSG_SET_CUSTOM_PARAM_RESP){
MSG_SET_CUSTOM_PARAM_RESP *pResp=(MSG_SET_CUSTOM_PARAM_RESP *)pMsg;
CHAR chTmp[128];
sprintf(chTmp,"result=%d %s=%s\n", pResp->result, pResp->chParamName, pResp->chParamValue);
OutputDebugStringA(chTmp);
}else if(nMsgType==SEP2P_MSG_GET_ALARM_INFO_RESP){
MSG_GET_ALARM_INFO_RESP *pResp=(MSG_GET_ALARM_INFO_RESP *)pMsg;
CHAR chTmp[128];
sprintf(chTmp,"MSG_GET_ALARM_INFO_RESP,md_name=%s\n", pResp->md_name);
OutputDebugStringA(chTmp);
}else if(nMsgType==SEP2P_MSG_GET_REMOTE_REC_DAY_BY_MONTH_RESP){
MSG_GET_REMOTE_REC_DAY_BY_MONTH_RESP *pResp=(MSG_GET_REMOTE_REC_DAY_BY_MONTH_RESP *)pMsg;
CHAR chTmp[128];
sprintf(chTmp,"\tMSG_GET_REMOTE_REC_DAY_BY_MONTH_RESP,chDay=%s\n", pResp->chDay);
OutputDebugStringA(chTmp);
}else if(nMsgType==SEP2P_MSG_GET_REMOTE_REC_FILE_BY_DAY_RESP){
MSG_GET_REMOTE_REC_FILE_BY_DAY_RESP *pResp=(MSG_GET_REMOTE_REC_FILE_BY_DAY_RESP *)pMsg;
CHAR chTmp[1024];
sprintf(chTmp,"\tMSG_GET_REMOTE_REC_FILE_BY_DAY_RESP,res=%d TNum=%d no=[%d,%d]\n", pResp->nResult, pResp->nFileTotalNum, pResp->nBeginNoOfThisTime, pResp->nEndNoOfThisTime);
OutputDebugStringA(chTmp);
INT32 ii=0, nNum=pResp->nEndNoOfThisTime - pResp->nBeginNoOfThisTime + 1;
REC_FILE_INFO *pRecFile=(REC_FILE_INFO *)(pMsg+sizeof(MSG_GET_REMOTE_REC_FILE_BY_DAY_RESP));
strcpy(m_chFirstFilePath, pRecFile->chFilePath); //only test
for(ii=0; ii<nNum; ii++){
//1 /mnt/mmc/201412/19/nrc20141219235248.mp4 2014-12-19 23:52:48 2014-12-19 23:57:49, 301s 78418KB
sprintf(chTmp,"\t %d %s %s %s, %ds %dKB\n",
ii+pResp->nBeginNoOfThisTime, pRecFile->chFilePath, pRecFile->chStartTime, pRecFile->chEndTime,
pRecFile->nTimeLen_sec, pRecFile->nFileSize_KB);
OutputDebugStringA(chTmp);
pRecFile+=1;
}
}else if(nMsgType==SEP2P_MSG_START_PLAY_REC_FILE_RESP){
MSG_START_PLAY_REC_FILE_RESP *pResp=(MSG_START_PLAY_REC_FILE_RESP *)pMsg;
CHAR chTmp[256];
sprintf(chTmp,"\tMSG_START_PLAY_REC_FILE_RESP,res=%d fpath=%s, playbackID=%d\n", pResp->nResult, pResp->chFilePath, pResp->nPlaybackID);
OutputDebugStringA(chTmp);
}else if(nMsgType==SEP2P_MSG_STOP_PLAY_REC_FILE_RESP){
MSG_STOP_PLAY_REC_FILE_RESP *pResp=(MSG_STOP_PLAY_REC_FILE_RESP *)pMsg;
CHAR chTmp[128];
sprintf(chTmp,"\tMSG_STOP_PLAY_REC_FILE_RESP,res=%d fpath=%s\n", pResp->nResult, pResp->chFilePath);
OutputDebugStringA(chTmp);
}else if(nMsgType==SEP2P_MSG_GET_DATETIME_RESP){
MSG_GET_DATETIME_RESP *pResp=(MSG_GET_DATETIME_RESP *)pMsg;
char szDateTime[128]={0};
time_t nTime=(time_t)(pResp->nSecToNow+pResp->nSecTimeZone);
struct tm *ptm1=NULL;
ptm1= gmtime(&nTime);
sprintf(szDateTime, "%4d-%02d-%02d %02d:%02d:%02d",
ptm1->tm_year+1900,
ptm1->tm_mon+1,
ptm1->tm_mday,
ptm1->tm_hour,
ptm1->tm_min,
ptm1->tm_sec);
printf("szDateTime=%s", szDateTime);
}/*else if(nMsgType==SEP2P_MSG_GET_EXT_APP_RESP){
MSG_GET_EXT_APP_RESP *pResp=(MSG_GET_EXT_APP_RESP *)pMsg;
printf("%s\n", pResp->chUrlPrefix);
}
*/
if(!m_bExitingApp){
MSG_INFO *pMsgInfo=(MSG_INFO *)malloc(sizeof(MSG_INFO));
memset(pMsgInfo, 0, sizeof(MSG_INFO));
pMsgInfo->nDeviceNo=nDeviceNo;
pMsgInfo->nMsgType=nMsgType;
pMsgInfo->nMsgSize=nMsgSize;
if(nMsgSize>0){
pMsgInfo->pMsg=(CHAR *)malloc(nMsgSize);
memcpy(pMsgInfo->pMsg, pMsg, nMsgSize);
}
PostMessage(OM_UPDATE_UI, UPDATE_UI_WPARAM_MsgArrived, (LPARAM)pMsgInfo);
}
}
void CSEP2PAppSDKDemoDlg::OnButtonsRange(UINT nID)
{
switch(nID)
{
//edit device
case IDC_EDIT_DEVICE1:{
CHAR *pMyDID=m_pObjCams[0]->GetDID();
CDeviceInfo dlg;
dlg.m_nChanNo=1;
if(pMyDID[0]!='\0') BSTRFromCharU(CP_OEMCP, pMyDID, dlg.m_csDID);
dlg.m_csUsername.Format(_T("%s"), m_pObjCams[0]->GetUsername());
dlg.m_csPassword.Format(_T("%s"), m_pObjCams[0]->GetPasswd());
dlg.m_pSampleDlg=this;
if(IDOK==dlg.DoModal()){
CHAR chMyDID[128]={0};
CharFromWSTRU(CP_OEMCP, dlg.m_csDID, dlg.m_csDID.GetLength(), chMyDID);
strcpy(m_pObjCams[0]->GetDID(), chMyDID);
wcscpy(m_pObjCams[0]->GetUsername(), dlg.m_csUsername.GetBuffer());
wcscpy(m_pObjCams[0]->GetPasswd(), dlg.m_csPassword.GetBuffer());
dlg.m_csUsername.ReleaseBuffer();
dlg.m_csPassword.ReleaseBuffer();
}
}
break;
case IDC_EDIT_DEVICE2:{
CHAR *pMyDID=m_pObjCams[1]->GetDID();
CDeviceInfo dlg;
dlg.m_nChanNo=2;
if(pMyDID[0]!='\0') BSTRFromCharU(CP_OEMCP, pMyDID, dlg.m_csDID);
dlg.m_csUsername.Format(_T("%s"), m_pObjCams[1]->GetUsername());
dlg.m_csPassword.Format(_T("%s"), m_pObjCams[1]->GetPasswd());
dlg.m_pSampleDlg=this;
if(IDOK==dlg.DoModal()){
CHAR chMyDID[128]={0};
CharFromWSTRU(CP_OEMCP, dlg.m_csDID, dlg.m_csDID.GetLength(), chMyDID);
strcpy(m_pObjCams[1]->GetDID(), chMyDID);
wcscpy(m_pObjCams[1]->GetUsername(), dlg.m_csUsername.GetBuffer());
wcscpy(m_pObjCams[1]->GetPasswd(), dlg.m_csPassword.GetBuffer());
dlg.m_csUsername.ReleaseBuffer();
dlg.m_csPassword.ReleaseBuffer();
}
}
break;
case IDC_EDIT_DEVICE3:{
CHAR *pMyDID=m_pObjCams[2]->GetDID();
CDeviceInfo dlg;
dlg.m_nChanNo=3;
if(pMyDID[0]!='\0') BSTRFromCharU(CP_OEMCP, pMyDID, dlg.m_csDID);
dlg.m_csUsername.Format(_T("%s"), m_pObjCams[2]->GetUsername());
dlg.m_csPassword.Format(_T("%s"), m_pObjCams[2]->GetPasswd());
dlg.m_pSampleDlg=this;
if(IDOK==dlg.DoModal()){
CHAR chMyDID[128]={0};
CharFromWSTRU(CP_OEMCP, dlg.m_csDID, dlg.m_csDID.GetLength(), chMyDID);
strcpy(m_pObjCams[2]->GetDID(), chMyDID);
wcscpy(m_pObjCams[2]->GetUsername(), dlg.m_csUsername.GetBuffer());
wcscpy(m_pObjCams[2]->GetPasswd(), dlg.m_csPassword.GetBuffer());
dlg.m_csUsername.ReleaseBuffer();
dlg.m_csPassword.ReleaseBuffer();
}
}
break;
case IDC_EDIT_DEVICE4:{
CHAR *pMyDID=m_pObjCams[3]->GetDID();
CDeviceInfo dlg;
dlg.m_nChanNo=4;
if(pMyDID[0]!='\0') BSTRFromCharU(CP_OEMCP, pMyDID, dlg.m_csDID);
dlg.m_csUsername.Format(_T("%s"), m_pObjCams[3]->GetUsername());
dlg.m_csPassword.Format(_T("%s"), m_pObjCams[3]->GetPasswd());
dlg.m_pSampleDlg=this;
if(IDOK==dlg.DoModal()){
CHAR chMyDID[128]={0};
CharFromWSTRU(CP_OEMCP, dlg.m_csDID, dlg.m_csDID.GetLength(), chMyDID);
strcpy(m_pObjCams[3]->GetDID(), chMyDID);
wcscpy(m_pObjCams[3]->GetUsername(), dlg.m_csUsername.GetBuffer());
wcscpy(m_pObjCams[3]->GetPasswd(), dlg.m_csPassword.GetBuffer());
dlg.m_csUsername.ReleaseBuffer();
dlg.m_csPassword.ReleaseBuffer();
}
}
break;
//connect device
case IDC_CONNECT1:{
CHAR *pMyStr=m_pObjCams[0]->GetDID();
if(pMyStr[0]=='\0') {
MessageBox(_T("DID don't enter."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
break;
}
TCHAR* pMyTStr=m_pObjCams[0]->GetUsername();
if(pMyTStr[0]=='\0') {
MessageBox(_T("Username don't enter."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
break;
}
if(m_pObjCams[0]->m_bConnecting){
m_pObjCams[0]->m_bConnecting=0;
m_pObjCams[0]->GetCtrlConnect()->SetWindowText(ms_csTitleStop[0]);
m_pObjCams[0]->P2PAPI_Connect();
}else{
m_pObjCams[0]->m_bConnecting=1;
m_pObjCams[0]->GetCtrlConnect()->SetWindowText(ms_csTitleStart[0]);
m_pObjCams[0]->P2PAPI_Disconnect();
m_pObjCams[0]->GetCtrlStartVideo()->EnableWindow(FALSE);
m_pObjCams[0]->GetCtrlStartAudio()->EnableWindow(FALSE);
m_pObjCams[0]->GetCtrlStartTalk()->EnableWindow(FALSE);
m_ctlComboChn.EnableWindow(FALSE);
}
}break;
case IDC_CONNECT2:{
CHAR *pMyStr=m_pObjCams[1]->GetDID();
if(pMyStr[0]=='\0') {
MessageBox(_T("DID don't enter."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
break;
}
TCHAR* pMyTStr=m_pObjCams[1]->GetUsername();
if(pMyTStr[0]=='\0') {
MessageBox(_T("Username don't enter."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
break;
}
if(m_pObjCams[1]->m_bConnecting){
m_pObjCams[1]->m_bConnecting=0;
m_pObjCams[1]->GetCtrlConnect()->SetWindowText(ms_csTitleStop[0]);
m_pObjCams[1]->P2PAPI_Connect();
}else{
m_pObjCams[1]->m_bConnecting=1;
m_pObjCams[1]->GetCtrlConnect()->SetWindowText(ms_csTitleStart[0]);
m_pObjCams[1]->P2PAPI_Disconnect();
m_pObjCams[1]->GetCtrlStartVideo()->EnableWindow(FALSE);
m_pObjCams[1]->GetCtrlStartAudio()->EnableWindow(FALSE);
m_pObjCams[1]->GetCtrlStartTalk()->EnableWindow(FALSE);
}
}break;
case IDC_CONNECT3:{
CHAR *pMyStr=m_pObjCams[2]->GetDID();
if(pMyStr[0]=='\0') {
MessageBox(_T("DID don't enter."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
break;
}
TCHAR* pMyTStr=m_pObjCams[2]->GetUsername();
if(pMyTStr[0]=='\0') {
MessageBox(_T("Username don't enter."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
break;
}
if(m_pObjCams[2]->m_bConnecting){
m_pObjCams[2]->m_bConnecting=0;
m_pObjCams[2]->GetCtrlConnect()->SetWindowText(ms_csTitleStop[0]);
m_pObjCams[2]->P2PAPI_Connect();
}else{
m_pObjCams[2]->m_bConnecting=1;
m_pObjCams[2]->GetCtrlConnect()->SetWindowText(ms_csTitleStart[0]);
m_pObjCams[2]->P2PAPI_Disconnect();
m_pObjCams[2]->GetCtrlStartVideo()->EnableWindow(FALSE);
m_pObjCams[2]->GetCtrlStartAudio()->EnableWindow(FALSE);
m_pObjCams[2]->GetCtrlStartTalk()->EnableWindow(FALSE);
}
}break;
case IDC_CONNECT4:{
CHAR *pMyStr=m_pObjCams[3]->GetDID();
if(pMyStr[0]=='\0') {
MessageBox(_T("DID don't enter."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
break;
}
TCHAR* pMyTStr=m_pObjCams[3]->GetUsername();
if(pMyTStr[0]=='\0') {
MessageBox(_T("Username don't enter."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
break;
}
if(m_pObjCams[3]->m_bConnecting){
m_pObjCams[3]->m_bConnecting=0;
m_pObjCams[3]->GetCtrlConnect()->SetWindowText(ms_csTitleStop[0]);
m_pObjCams[3]->P2PAPI_Connect();
}else{
m_pObjCams[3]->m_bConnecting=1;
m_pObjCams[3]->GetCtrlConnect()->SetWindowText(ms_csTitleStart[0]);
m_pObjCams[3]->P2PAPI_Disconnect();
m_pObjCams[3]->GetCtrlStartVideo()->EnableWindow(FALSE);
m_pObjCams[3]->GetCtrlStartAudio()->EnableWindow(FALSE);
m_pObjCams[3]->GetCtrlStartTalk()->EnableWindow(FALSE);
}
}break;
//request video
case IDC_START_VIDEO1:{
if(m_pObjCams[0]->m_bStartVideo){
m_pObjCams[0]->m_bStartVideo=0;
m_pObjCams[0]->GetCtrlStartVideo()->SetWindowText(ms_csTitleStop[1]);
MSG_START_VIDEO stStartVideo;
memset(&stStartVideo, 0, sizeof(stStartVideo));
stStartVideo.eVideoReso=VIDEO_RESO_VGA1;
stStartVideo.nChannel=m_ctlComboChn.GetCurSel();
stStartVideo.nVideoCodecID=AV_CODECID_VIDEO_H264;
INT32 nRet=m_pObjCams[0]->P2PAPI_SendMsg(SEP2P_MSG_START_VIDEO, (CHAR *)&stStartVideo, sizeof(stStartVideo)); //NULL: The default is VIDEO_RESO_VGA1.
TRACE(_T("VIDEO P2PAPI_SendMsg=%d\n"), nRet);
}else{
m_pObjCams[0]->m_bStartVideo=1;
m_pObjCams[0]->GetCtrlStartVideo()->SetWindowText(ms_csTitleStart[1]);
MSG_STOP_VIDEO stStopVideo;
memset(&stStopVideo, 0, sizeof(stStopVideo));
stStopVideo.nChannel=m_ctlComboChn.GetCurSel();
m_pObjCams[0]->P2PAPI_SendMsg(SEP2P_MSG_STOP_VIDEO, (CHAR *)&stStopVideo, sizeof(stStopVideo));
}
}break;
case IDC_START_VIDEO2:{
if(m_pObjCams[1]->m_bStartVideo){
m_pObjCams[1]->m_bStartVideo=0;
m_pObjCams[1]->GetCtrlStartVideo()->SetWindowText(ms_csTitleStop[1]);
INT32 nRet=m_pObjCams[1]->P2PAPI_SendMsg(SEP2P_MSG_START_VIDEO, NULL, 0);
TRACE(_T("VIDEO P2PAPI_SendMsg=%d\n"), nRet);
}else{
m_pObjCams[1]->m_bStartVideo=1;
m_pObjCams[1]->GetCtrlStartVideo()->SetWindowText(ms_csTitleStart[1]);
m_pObjCams[1]->P2PAPI_SendMsg(SEP2P_MSG_STOP_VIDEO, NULL, 0);
}
}break;
case IDC_START_VIDEO3:{
if(m_pObjCams[2]->m_bStartVideo){
m_pObjCams[2]->m_bStartVideo=0;
m_pObjCams[2]->GetCtrlStartVideo()->SetWindowText(ms_csTitleStop[1]);
INT32 nRet=m_pObjCams[2]->P2PAPI_SendMsg(SEP2P_MSG_START_VIDEO, NULL, 0);
TRACE(_T("VIDEO P2PAPI_SendMsg=%d\n"), nRet);
}else{
m_pObjCams[2]->m_bStartVideo=1;
m_pObjCams[2]->GetCtrlStartVideo()->SetWindowText(ms_csTitleStart[1]);
m_pObjCams[2]->P2PAPI_SendMsg(SEP2P_MSG_STOP_VIDEO, NULL, 0);
}
}break;
case IDC_START_VIDEO4:{
if(m_pObjCams[3]->m_bStartVideo){
m_pObjCams[3]->m_bStartVideo=0;
m_pObjCams[3]->GetCtrlStartVideo()->SetWindowText(ms_csTitleStop[1]);
INT32 nRet=m_pObjCams[3]->P2PAPI_SendMsg(SEP2P_MSG_START_VIDEO, NULL, 0);
TRACE(_T("VIDEO P2PAPI_SendMsg=%d\n"), nRet);
}else{
m_pObjCams[3]->m_bStartVideo=1;
m_pObjCams[3]->GetCtrlStartVideo()->SetWindowText(ms_csTitleStart[1]);
m_pObjCams[3]->P2PAPI_SendMsg(SEP2P_MSG_STOP_VIDEO, NULL, 0);
}
}break;
//request audio
case IDC_START_AUDIO1:{
if(m_pObjCams[0]->m_bStartAudio){
m_pObjCams[0]->m_bStartAudio=0;
m_pObjCams[0]->GetCtrlStartAudio()->SetWindowText(ms_csTitleStop[2]);
MSG_START_AUDIO stStartAudio;
memset(&stStartAudio, 0, sizeof(stStartAudio));
stStartAudio.nAudioCodecID=AV_CODECID_AUDIO_AAC;
stStartAudio.nChannel=m_ctlComboChn.GetCurSel();
INT32 nRet=m_pObjCams[0]->P2PAPI_SendMsg(SEP2P_MSG_START_AUDIO, (CHAR *)&stStartAudio, sizeof(stStartAudio));
TRACE(_T("AUDIO P2PAPI_SendMsg=%d\n"), nRet);
if(nRet==ERR_P2PAPI_ALREADY_OPEN_AUDIO){
MessageBox(_T("The other audio has already been opened."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
}
}else{
m_pObjCams[0]->m_bStartAudio=1;
m_pObjCams[0]->GetCtrlStartAudio()->SetWindowText(ms_csTitleStart[2]);
MSG_STOP_AUDIO stStopAudio;
memset(&stStopAudio,0,sizeof(stStopAudio));
stStopAudio.nChannel=m_ctlComboChn.GetCurSel();
m_pObjCams[0]->P2PAPI_SendMsg(SEP2P_MSG_STOP_AUDIO, (CHAR *)&stStopAudio, sizeof(stStopAudio));
}
}break;
case IDC_START_AUDIO2:{
if(m_pObjCams[1]->m_bStartAudio){
m_pObjCams[1]->m_bStartAudio=0;
m_pObjCams[1]->GetCtrlStartAudio()->SetWindowText(ms_csTitleStop[2]);
INT32 nRet=m_pObjCams[1]->P2PAPI_SendMsg(SEP2P_MSG_START_AUDIO, NULL, 0);
TRACE(_T("AUDIO P2PAPI_SendMsg=%d\n"), nRet);
if(nRet==ERR_P2PAPI_ALREADY_OPEN_AUDIO){
MessageBox(_T("The other audio has already been opened."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
}
}else{
m_pObjCams[1]->m_bStartAudio=1;
m_pObjCams[1]->GetCtrlStartAudio()->SetWindowText(ms_csTitleStart[2]);
m_pObjCams[1]->P2PAPI_SendMsg(SEP2P_MSG_STOP_AUDIO, NULL, 0);
}
}break;
case IDC_START_AUDIO3:{
if(m_pObjCams[2]->m_bStartAudio){
m_pObjCams[2]->m_bStartAudio=0;
m_pObjCams[2]->GetCtrlStartAudio()->SetWindowText(ms_csTitleStop[2]);
INT32 nRet=m_pObjCams[2]->P2PAPI_SendMsg(SEP2P_MSG_START_AUDIO, NULL, 0);
TRACE(_T("AUDIO P2PAPI_SendMsg=%d\n"), nRet);
if(nRet==ERR_P2PAPI_ALREADY_OPEN_AUDIO){
MessageBox(_T("The other audio has already been opened."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
}
}else{
m_pObjCams[2]->m_bStartAudio=1;
m_pObjCams[2]->GetCtrlStartAudio()->SetWindowText(ms_csTitleStart[2]);
m_pObjCams[2]->P2PAPI_SendMsg(SEP2P_MSG_STOP_AUDIO, NULL, 0);
}
}break;
case IDC_START_AUDIO4:{
if(m_pObjCams[3]->m_bStartAudio){
m_pObjCams[3]->m_bStartAudio=0;
m_pObjCams[3]->GetCtrlStartAudio()->SetWindowText(ms_csTitleStop[2]);
INT32 nRet=m_pObjCams[3]->P2PAPI_SendMsg(SEP2P_MSG_START_AUDIO, NULL, 0);
TRACE(_T("AUDIO P2PAPI_SendMsg=%d\n"), nRet);
if(nRet==ERR_P2PAPI_ALREADY_OPEN_AUDIO){
MessageBox(_T("The other audio has already been opened."), _T("Tips"), MB_OK|MB_ICONINFORMATION);
}
}else{
m_pObjCams[3]->m_bStartAudio=1;
m_pObjCams[3]->GetCtrlStartAudio()->SetWindowText(ms_csTitleStart[2]);
m_pObjCams[3]->P2PAPI_SendMsg(SEP2P_MSG_STOP_AUDIO, NULL, 0);
}
}break;
//request talk
case IDC_START_TALK1:{
if(m_pObjCams[0]->m_bStartTalk){
m_pObjCams[0]->m_bStartTalk=0;
m_pObjCams[0]->GetCtrlStartTalk()->SetWindowText(ms_csTitleStop[3]);
MSG_START_TALK stStartTalk;
memset(&stStartTalk, 0, sizeof(stStartTalk));
stStartTalk.nChannel=m_ctlComboChn.GetCurSel();
INT32 nRet=m_pObjCams[0]->P2PAPI_SendMsg(SEP2P_MSG_START_TALK, (CHAR *)&stStartTalk, sizeof(stStartTalk));
TRACE(_T("TALK P2PAPI_SendMsg=%d\n"), nRet);
}else{
m_pObjCams[0]->m_bStartTalk=1;
m_pObjCams[0]->GetCtrlStartTalk()->SetWindowText(ms_csTitleStart[3]);
m_objSample.StopSample();
PostMessage(OM_UPDATE_UI, UPDATE_UI_WPARAM_Talk, MAKELPARAM(10, 0));
MSG_STOP_TALK stStopTalk;
memset(&stStopTalk, 0, sizeof(stStopTalk));
stStopTalk.nChannel=m_ctlComboChn.GetCurSel();
INT32 nRet=m_pObjCams[0]->P2PAPI_SendMsg(SEP2P_MSG_START_TALK, (CHAR *)&stStopTalk, sizeof(stStopTalk));
m_pObjCams[0]->P2PAPI_SendMsg(SEP2P_MSG_STOP_TALK, (CHAR *)&stStopTalk, sizeof(stStopTalk));
}
}break;
case IDC_START_TALK2:{
if(m_pObjCams[1]->m_bStartTalk){
m_pObjCams[1]->m_bStartTalk=0;
m_pObjCams[1]->GetCtrlStartTalk()->SetWindowText(ms_csTitleStop[3]);
INT32 nRet=m_pObjCams[1]->P2PAPI_SendMsg(SEP2P_MSG_START_TALK, NULL, 0);
TRACE(_T("TALK P2PAPI_SendMsg=%d\n"), nRet);
}else{
m_pObjCams[1]->m_bStartTalk=1;
m_pObjCams[1]->GetCtrlStartTalk()->SetWindowText(ms_csTitleStart[3]);
m_objSample.StopSample();
PostMessage(OM_UPDATE_UI, UPDATE_UI_WPARAM_Talk, MAKELPARAM(10, 1));
m_pObjCams[1]->P2PAPI_SendMsg(SEP2P_MSG_STOP_TALK, NULL, 0);
}
}break;
case IDC_START_TALK3:{
if(m_pObjCams[2]->m_bStartTalk){
m_pObjCams[2]->m_bStartTalk=0;
m_pObjCams[2]->GetCtrlStartTalk()->SetWindowText(ms_csTitleStop[3]);
INT32 nRet=m_pObjCams[2]->P2PAPI_SendMsg(SEP2P_MSG_START_TALK, NULL, 0);
TRACE(_T("TALK P2PAPI_SendMsg=%d\n"), nRet);
}else{
m_pObjCams[2]->m_bStartTalk=1;
m_pObjCams[2]->GetCtrlStartTalk()->SetWindowText(ms_csTitleStart[3]);
m_objSample.StopSample();
PostMessage(OM_UPDATE_UI, UPDATE_UI_WPARAM_Talk, MAKELPARAM(10, 2));
m_pObjCams[2]->P2PAPI_SendMsg(SEP2P_MSG_STOP_TALK, NULL, 0);
}
}break;
case IDC_START_TALK4:{
if(m_pObjCams[3]->m_bStartTalk){
m_pObjCams[3]->m_bStartTalk=0;
m_pObjCams[3]->GetCtrlStartTalk()->SetWindowText(ms_csTitleStop[3]);
INT32 nRet=m_pObjCams[3]->P2PAPI_SendMsg(SEP2P_MSG_START_TALK, NULL, 0);
TRACE(_T("TALK P2PAPI_SendMsg=%d\n"), nRet);
}else{
m_pObjCams[3]->m_bStartTalk=1;
m_pObjCams[3]->GetCtrlStartTalk()->SetWindowText(ms_csTitleStart[3]);
m_objSample.StopSample();
PostMessage(OM_UPDATE_UI, UPDATE_UI_WPARAM_Talk, MAKELPARAM(10, 3));
m_pObjCams[3]->P2PAPI_SendMsg(SEP2P_MSG_STOP_TALK, NULL, 0);
}
}break;
default:;
}
}
BOOL CSEP2PAppSDKDemoDlg::IsExistThisDID(const CHAR *pDID)
{
if(pDID==NULL) return FALSE;
int i=0;
CHAR *pMyDID=NULL;
for(i=0; i<MAX_NUM_CHANNEL; i++){
pMyDID=m_pObjCams[i]->GetDID();
if(memcmp(pMyDID, pDID, MAX_LEN_DID)==0){
return TRUE;
}
}
return FALSE;
}
void CSEP2PAppSDKDemoDlg::OnBnClickedLansearch()
{
INT32 nRet=0;
if(m_bStartLanSearch){
m_bStartLanSearch=0;
SetDlgItemText(IDC_LANSEARCH, _T("Stop LAN Search"));
memset(m_arrDevSearched, 0, sizeof(m_arrDevSearched));
m_pObjCams[0]->P2PAPI_StartSearch();
}else{
m_bStartLanSearch=1;
SetDlgItemText(IDC_LANSEARCH, _T("Start LAN Search"));
m_pObjCams[0]->P2PAPI_StopSearch();
}
TRACE("OnBnClickedLansearch] SEP2P_...=%d\n", nRet);
}
//static
INT32 CSEP2PAppSDKDemoDlg::OnSampleCallback(int index, CHAR* pData, UINT32 nDataSize, void* pUserData)
{
CSEP2PAppSDKDemoDlg* pThis=(CSEP2PAppSDKDemoDlg *)pUserData;
pThis->m_pObjCams[index]->P2PAPI_TalkData(pData, nDataSize);
return 0;
}
void CSEP2PAppSDKDemoDlg::OnBnClickedClearLog()
{
SetDlgItemText(IDC_EDIT3, _T(""));
}
void CSEP2PAppSDKDemoDlg::OnBnClickedGetReq()
{
int nChannel=m_ctlComboChn.GetCurSel();
int nDeviceNo=m_ctlComboDev.GetCurSel(), nCmdIndex=0;
if(nDeviceNo==CB_ERR) return;
if(m_pObjCams[nDeviceNo]->m_bConnecting){
MessageBox(_T("Please first connect the device"), _T("Tips"), MB_OK|MB_ICONINFORMATION);
return;
}
nCmdIndex=m_ctlComboReqStr.GetCurSel();
switch(nCmdIndex)
{
case 0:
TRACE("GET_CAMERA_PARAM------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_CAMERA_PARAM_REQ, NULL, 0);
break;
case 1:
TRACE("GET_CURRENT_WIFI------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_CURRENT_WIFI_REQ, NULL, 0);
break;
case 2:
TRACE("GET_WIFI_LIST------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_WIFI_LIST_REQ, NULL, 0);
break;
case 3:
TRACE("GET_USER_INFO------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_USER_INFO_REQ, NULL, 0);
break;
case 4:
TRACE("GET_DATETIME------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_DATETIME_REQ, NULL, 0);
break;
case 5:
TRACE("GET_FTP_INFO------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_FTP_INFO_REQ, NULL, 0);
break;
case 6:
TRACE("GET_EMAIL_INFO------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_EMAIL_INFO_REQ, NULL, 0);
break;
case 7:
TRACE("GET_ALARM_INFO------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_ALARM_INFO_REQ, NULL, 0);
break;
case 8:
TRACE("GET_SDCARD_REC_PARAM------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_SDCARD_REC_PARAM_REQ, NULL, 0);
//m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_IPUSH_INFO_REQ, NULL, 0);
break;
case 9:
TRACE("GET_DEVICE_VERSION------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_DEVICE_VERSION_REQ, NULL, 0);
break;
case 10:{
TRACE("QUERY_CHANNEL_INFO_OF_NVR_REQ------\n");
MSG_QUERY_CHANNEL_INFO_OF_NVR_REQ stReq;
memset(&stReq, 0, sizeof(stReq));
stReq.nChannel=0xFF;
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_QUERY_CHANNEL_INFO_OF_NVR_REQ, (CHAR *)&stReq, sizeof(stReq));
}break;
case 12:{
TRACE("SEP2P_MSG_GET_REMOTE_REC_DAY_BY_MONTH_REQ------\n");
MSG_GET_REMOTE_REC_DAY_BY_MONTH_REQ stReq;
memset(&stReq, 0, sizeof(stReq));
stReq.nYearMon=201412;
stReq.nRecType=1;
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_REMOTE_REC_DAY_BY_MONTH_REQ, (CHAR *)&stReq, sizeof(stReq));
}break;
case 13:
TRACE("MSG_GET_REMOTE_REC_FILE_BY_DAY_REQ------\n");
{
MSG_GET_REMOTE_REC_FILE_BY_DAY_REQ stReq;
memset(&stReq, 0, sizeof(stReq));
stReq.nYearMonDay=20161205;
stReq.nRecType=1;
stReq.nBeginNoOfThisTime=0;
stReq.nEndNoOfThisTime=0;
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_REMOTE_REC_FILE_BY_DAY_REQ, (CHAR *)&stReq, sizeof(stReq));
}break;
case 14:
TRACE("MSG_START_PLAY_REC_FILE_REQ------%s\n", m_chFirstFilePath);
{
MSG_START_PLAY_REC_FILE_REQ stReq;
memset(&stReq, 0, sizeof(stReq));
stReq.nBeginPos_sec=0;
strcpy(stReq.chFilePath, m_chFirstFilePath);
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_START_PLAY_REC_FILE_REQ, (CHAR *)&stReq, sizeof(stReq));
}break;
case 15:
TRACE("MSG_STOP_PLAY_REC_FILE_REQ------%s\n", m_chFirstFilePath);
{
MSG_STOP_PLAY_REC_FILE_REQ stReq;
memset(&stReq, 0, sizeof(stReq));
strcpy(stReq.chFilePath, m_chFirstFilePath);
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_STOP_PLAY_REC_FILE_REQ, (CHAR *)&stReq, sizeof(stReq));
}break;
case 16:{
TRACE("get ipush info------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_IPUSH_INFO_REQ, NULL, 0);
}break;
case 17:{
TRACE("get USER_INFO2------\n");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_USER_INFO2_REQ, NULL, 0);
// MSG_GET_EXT_APP_REQ stReq;
// memset(&stReq, 0, sizeof(stReq));
// stReq.nAppType=1;
// m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_EXT_APP_REQ, (CHAR*)&stReq, sizeof(stReq));
}break;
default:;
}
}
void CSEP2PAppSDKDemoDlg::OnBnClickedSetReq()
{
int nDeviceNo=m_ctlComboDev.GetCurSel(), nCmdIndex=0;
if(nDeviceNo==CB_ERR) return;
if(m_pObjCams[nDeviceNo]->m_bConnecting){
MessageBox(_T("Please first connect the device"), _T("Tips"), MB_OK|MB_ICONINFORMATION);
return;
}
nCmdIndex=m_ctlComboReqStr.GetCurSel();
switch(nCmdIndex)
{
case 0:{
TRACE("SET_CAMERA_PARAM------\n");
MSG_SET_CAMERA_PARAM_REQ setReq;
CHAR *pTimeNameOSD=NULL;
memset(&setReq, 0, sizeof(setReq));
setReq.nResolution=1;
setReq.nBright =0;
setReq.nContrast=128;
setReq.nIRLed=2;
pTimeNameOSD=(CHAR *)&(setReq.bOSD);
pTimeNameOSD[0]=1; //time region OSD
pTimeNameOSD[1]=1; //name region OSD
pTimeNameOSD[2]=0; //show Temperature&Humidity
if(pTimeNameOSD[2]) strcpy(setReq.chOSDName, "TEMP_HUM"); //TEMP_HUM
else strcpy(setReq.chOSDName, "IPC");
setReq.nMode=0;
setReq.nFlip=3;
setReq.nMICVolume=80;
setReq.nSPKVolume=60;
setReq.nBitMaskToSet=BIT_MASK_CAM_PARAM_MODE;//BIT_MASK_CAM_PARAM_MIC_VOLUME|BIT_MASK_CAM_PARAM_SPK_VOLUME;
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_CAMERA_PARAM_REQ, (CHAR *)&setReq, sizeof(setReq));
//or
//m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_CAMERA_PARAM_DEFAULT_REQ, NULL, 0);
}break;
case 1:{
TRACE("SET_CURRENT_WIFI------\n");
MSG_SET_CURRENT_WIFI_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
setReq.bEnable=1;
strcpy(setReq.chSSID, "TPLINK_soft");
setReq.nAuthtype=5;
strcpy(setReq.chWPAPsk,"11111111");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_CURRENT_WIFI_REQ, (CHAR *)&setReq, sizeof(setReq));
}break;
case 2: //none
//TRACE("SET_WIFI_LIST------\n");
break;
case 3:{
TRACE("SET_USER_INFO------\n");
MSG_SET_USER_INFO_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
strcpy(setReq.chAdmin, "admin");
strcpy(setReq.chAdminPwd, "1234567");
int nRet=m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_USER_INFO_REQ, (CHAR *)&setReq, sizeof(setReq));
TRACE("SET_USER_INFO------, P2PAPI_SendMsg=%d\n", nRet);
}break;
case 4:{
TRACE("SET_DATETIME------\n");
MSG_SET_DATETIME_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
setReq.nSecToNow=0;
setReq.nSecTimeZone=28800;
strcpy(setReq.chNTPServer, "time.nist.gov");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_DATETIME_REQ, (CHAR *)&setReq, sizeof(setReq));
}break;
case 5:{
TRACE("SET_FTP_INFO------\n");
// MSG_SET_FTP_INFO_REQ setReq;
// memset(&setReq, 0, sizeof(setReq));
// strcpy(setReq.chFTPSvr, "192.168.1.100");
// strcpy(setReq.chUser,"ftp");
// strcpy(setReq.chPwd, "ftp");
// strcpy(setReq.chDir,"/device");
// setReq.nPort=2121;
// m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_FTP_INFO_REQ, (CHAR *)&setReq, sizeof(setReq));
}break;
case 6:{
TRACE("SET_EMAIL_INFO------\n");
MSG_SET_EMAIL_INFO_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
strcpy(setReq.chSMTPSvr,"smtp.126.com");
strcpy(setReq.chSender,"sender");
//strcpy(setReq.chUser,"user");
//strcpy(setReq.chPwd,"user");
strcpy(setReq.chReceiver1,"recv@126.com");
strcpy(setReq.chReceiver2, " ");
strcpy(setReq.chText, "email content");
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_EMAIL_INFO_REQ, (CHAR *)&setReq, sizeof(setReq));
}break;
case 7:{
TRACE("SET_ALARM_INFO------\n");
MSG_SET_ALARM_INFO_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
setReq.bMDEnable[0]=0;
setReq.nMDSensitivity[0]=8;
setReq.md_x[0]=10;
setReq.md_y[0]=10;
setReq.md_width[0]=10;
setReq.md_height[0]=10;
setReq.bMDEnable[1]=0;
setReq.nMDSensitivity[1]=8;
setReq.md_x[1]=19;
setReq.md_y[1]=19;
setReq.md_width[1]=19;
setReq.md_height[1]=19;
setReq.bMDEnable[2]=1;
setReq.nMDSensitivity[2]=7;
setReq.md_x[2]=30;
setReq.md_y[2]=30;
setReq.md_width[2]=30;
setReq.md_height[2]=30;
setReq.bMDEnable[3]=1;
setReq.nMDSensitivity[3]=6;
setReq.md_x[3]=40;
setReq.md_y[3]=40;
setReq.md_width[3]=40;
setReq.md_height[3]=40;
setReq.bMailWhenAlarm=1;
setReq.nAudioAlarmSensitivity =1;
setReq.bSnapshotToFTPWhenAlarm=1;
//setReq.nPresetbitWhenAlarm=5;
setReq.bIOLinkageWhenAlarm=1;
setReq.nTimeSecOfIOOut=11;
setReq.bSpeakerWhenAlarm=1;
setReq.nTimeSecOfSpeaker=12;
setReq.nTriggerAlarmType=1;
setReq.bTemperatureAlarm=0;
setReq.bHumidityAlarm=1;
setReq.nTempMinValueWhenAlarm=2;
setReq.nTempMaxValueWhenAlarm=3;
setReq.nHumiMinValueWhenAlarm=4;
setReq.nHumiMaxValueWhenAlarm=5;
//alarm schedule(alarmed time)
// setReq.nAlarmTime_sun_0=0x10000000; //sunday,07:00:00---07:14:59
// setReq.nAlarmTime_sun_1=0x00000001; //sunday,08:00:00---08:14:59
// setReq.nAlarmTime_sun_2=0x80000001; //sunday,16:00:00---16:14:59, 23:45:00---23:59:59
// setReq.nAlarmTime_sat_2=0x80000001; //satday,16:00:00---16:14:59, 23:45:00---23:59:59
//every 00:00:00---07:59:59, 0bit----8*60=480/15=32bit
INT32 i=0;
for(i=0; i<32; i++) set15MinutesFlagAlarmTime(&setReq, 0, i, 1);
for(i=0; i<32; i++) set15MinutesFlagAlarmTime(&setReq, 1, i, 1);
for(i=0; i<32; i++) set15MinutesFlagAlarmTime(&setReq, 2, i, 1);
for(i=0; i<32; i++) set15MinutesFlagAlarmTime(&setReq, 3, i, 1);
for(i=0; i<32; i++) set15MinutesFlagAlarmTime(&setReq, 4, i, 1);
for(i=0; i<32; i++) set15MinutesFlagAlarmTime(&setReq, 5, i, 1);
for(i=0; i<32; i++) set15MinutesFlagAlarmTime(&setReq, 6, i, 1);
//every 22:00:00---23:59:59, 22*60/15=88bit----24*60/15=96bit
for(i=88; i<96; i++) set15MinutesFlagAlarmTime(&setReq, 0, i, 1);
for(i=88; i<96; i++) set15MinutesFlagAlarmTime(&setReq, 1, i, 1);
for(i=88; i<96; i++) set15MinutesFlagAlarmTime(&setReq, 2, i, 1);
for(i=88; i<96; i++) set15MinutesFlagAlarmTime(&setReq, 3, i, 1);
for(i=88; i<96; i++) set15MinutesFlagAlarmTime(&setReq, 4, i, 1);
for(i=88; i<96; i++) set15MinutesFlagAlarmTime(&setReq, 5, i, 1);
for(i=88; i<96; i++) set15MinutesFlagAlarmTime(&setReq, 6, i, 1);
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_ALARM_INFO_REQ, (CHAR *)&setReq, sizeof(setReq));
}break;
case 8:{
TRACE("SET_SDCARD_REC_PARAM------\n");
MSG_SET_SDCARD_REC_PARAM_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
setReq.bRecordCoverInSDCard=1;
setReq.nRecordTimeLen=4;
setReq.nCurChnRecording=1;
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_SDCARD_REC_PARAM_REQ, (CHAR *)&setReq, sizeof(setReq));
}break;
case 9:{//format SDCard
TRACE("Format SDCard------\n");
//m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_FORMAT_SDCARD_REQ, NULL, 0);
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_RESTORE_FACTORY, NULL, 0);
//1.get
// m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_UART_CTRL_REQ, NULL, 0);//(CHAR *)&stReq, sizeof(stReq));
//2.set
// MSG_SET_UART_CTRL_REQ stReq;
// memset(&stReq, 0, sizeof(stReq));
// memset(&stReq.bUartAlarmEnable, 0xFF, sizeof(stReq.bUartAlarmEnable));
// stReq.bUartAlarmEnable[0]=0;
// stReq.nBitMaskToSet=BIT_MASK_UART_ALARM_ENABLE;
// int n=m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_UART_CTRL_REQ,(CHAR *)&stReq, sizeof(stReq));
// TRACE(_T("SEP2P_MSG_SET_UART_CTRL_REQ, n=%d\n"), n);
}break;
case 10:{//PT
TRACE("PT Control------\n");
/*
MSG_PTZ_CONTROL_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
setReq.nCtrlCmd=PTZ_CTRL_PRESET_BIT_SET;
setReq.nCtrlParam=5; //PTZ goto preset position 5
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_PTZ_CONTROL_REQ, (CHAR *)&setReq, sizeof(setReq));
*/
/*
//control PTZ by one step
MSG_PTZ_CONTROL_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
if(nDeviceNo==0) setReq.nChannel=m_ctlComboChn.GetCurSel();
setReq.nCtrlCmd=PTZ_CTRL_LEFT;
//setReq.nCtrlParam=5; //PTZ goto preset position 5
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_PTZ_CONTROL_REQ, (CHAR *)&setReq, sizeof(setReq));
Sleep(500);
setReq.nCtrlCmd=PTZ_CTRL_STOP;
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_PTZ_CONTROL_REQ, (CHAR *)&setReq, sizeof(setReq));
*/
//cruise horizontal
MSG_PTZ_CONTROL_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
if(nDeviceNo==0) setReq.nChannel=m_ctlComboChn.GetCurSel();
setReq.nCtrlCmd=PTZ_CTRL_LEFT;
setReq.nCtrlParam=1;
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_PTZ_CONTROL_REQ, (CHAR *)&setReq, sizeof(setReq));
/*
if(m_nCruiseCount%2==0) setReq.nCtrlCmd=PTZ_CTRL_CRUISE_H;
else setReq.nCtrlCmd=PTZ_CTRL_STOP;
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_PTZ_CONTROL_REQ, (CHAR *)&setReq, sizeof(setReq));
m_nCruiseCount++;
*/
}break;
case 11:{ //User defined msg req
TRACE("User defined msg------\n");
CHAR chData[]={"My msg defined"};
//int n=m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_EXT_CMD1, chData, sizeof(chData));
int n=m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_REBOOT_DEVICE, NULL, 0);
TRACE(_T("UserMsg, n=%d\n"), n);
/*
SEP2P_MSG_EXT_SDFILE_REQ stReq;
memset(&stReq, 0, sizeof(stReq));
int n=m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_EXT_CMD2, (CHAR *)&stReq, sizeof(stReq));
TRACE(_T("UserMsg, n=%d\n"), n);
*/
Sleep(500);
MSG_SET_CUSTOM_PARAM_REQ stReq;
memset(&stReq, 0, sizeof(stReq));
strcpy(stReq.chParamName, "param1"); //param0 to param39 at [admin] of the device
strcpy(stReq.chParamValue, "value1");
n=m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_CUSTOM_PARAM_REQ, (CHAR *)&stReq, sizeof(stReq));
TRACE(_T("param req, n=%d\n"), n);
Sleep(500);
MSG_GET_CUSTOM_PARAM_REQ stReq1;
memset(&stReq1, 0, sizeof(stReq1));
strcpy(stReq1.chParamName, "param1"); //param0 to param39 at [admin] of the device
int n1=m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_GET_CUSTOM_PARAM_REQ, (CHAR *)&stReq1, sizeof(stReq1));
TRACE(_T("param req, n=%d\n"), n1);
}break;
case 16:{
//SEP2P_MSG_SET_IPUSH_INFO_REQ
TRACE("set ipush info------\n");
MSG_SET_IPUSH_INFO_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
setReq.bEnable=0;
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_IPUSH_INFO_REQ, (CHAR *)&setReq, sizeof(setReq));
}break;
case 17:{
TRACE("set USER_INFO2------\n");
MSG_SET_USER_INFO2_REQ setReq;
memset(&setReq, 0, sizeof(setReq));
//L series
setReq.nOpCode=OP_USER_INFO_EDIT;
setReq.nOpUserNum=1;
strcpy(setReq.arrUserInfo[0].chUsername, "admin");
strcpy(setReq.arrUserInfo[0].chUserPwd, "123456");
setReq.arrUserInfo[0].nUserID=1;
setReq.arrUserInfo[0].nUserRoleID=ROLE_ID_ADMIN;
// strcpy(setReq.arrUserInfo[0].chUsername, "guest");
// strcpy(setReq.arrUserInfo[0].chUserPwd, "guest");
// setReq.arrUserInfo[0].nUserID=3;
// setReq.arrUserInfo[0].nUserRoleID=ROLE_ID_GUEST;
m_pObjCams[nDeviceNo]->P2PAPI_SendMsg(SEP2P_MSG_SET_USER_INFO2_REQ, (CHAR *)&setReq, sizeof(setReq));
}break;
default:;
}
}
INT32 CSEP2PAppSDKDemoDlg::get15MinutesFlagAlarmTime(MSG_SET_ALARM_INFO_REQ *pAlarm, INT32 nWeek, INT32 nBitIndex)
{
INT32 bSelected = 0;
if(nWeek<0 || nWeek>=7) return 0;
INT32 nBitValue = 0;
switch(nWeek){
case 0:
if(nBitIndex<32){
nBitValue = (pAlarm->nAlarmTime_sun_0>>nBitIndex)&0x01;
}else if (nBitIndex<64){
nBitValue = (pAlarm->nAlarmTime_sun_1>>(nBitIndex-32))&0x01;
}else if(nBitValue<96){
nBitValue = (pAlarm->nAlarmTime_sun_2>>(nBitIndex-64))&0x01;
}
break;
case 1:
if(nBitIndex<32){
nBitValue = (pAlarm->nAlarmTime_mon_0>>nBitIndex)&0x01;
}else if (nBitIndex<64){
nBitValue = (pAlarm->nAlarmTime_mon_1>>(nBitIndex-32))&0x01;
}else if(nBitValue<96){
nBitValue = (pAlarm->nAlarmTime_mon_2>>(nBitIndex-64))&0x01;
}
break;
case 2:
if(nBitIndex<32){
nBitValue = (pAlarm->nAlarmTime_tue_0>>nBitIndex)&0x01;
}else if ( nBitIndex<64){
nBitValue = (pAlarm->nAlarmTime_tue_1>>(nBitIndex-32))&0x01;
}else if( nBitValue<96){
nBitValue = (pAlarm->nAlarmTime_tue_2>>(nBitIndex-64))&0x01;
}
break;
case 3:
if(nBitIndex<32){
nBitValue = (pAlarm->nAlarmTime_wed_0>>nBitIndex)&0x01;
}else if (nBitIndex<64){
nBitValue = (pAlarm->nAlarmTime_wed_1>>(nBitIndex-32))&0x01;
}else if(nBitValue<96){
nBitValue = (pAlarm->nAlarmTime_wed_2>>(nBitIndex-64))&0x01;
}
break;
case 4:
if(nBitIndex<32){
nBitValue = (pAlarm->nAlarmTime_thu_0>>nBitIndex)&0x01;
}else if (nBitIndex<64){
nBitValue = (pAlarm->nAlarmTime_thu_1>>(nBitIndex-32))&0x01;
}else if( nBitValue<96){
nBitValue = (pAlarm->nAlarmTime_thu_2>>(nBitIndex-64))&0x01;
}
break;
case 5:
if(nBitIndex<32){
nBitValue = (pAlarm->nAlarmTime_fri_0>>nBitIndex)&0x01;
}else if (nBitIndex<64){
nBitValue = (pAlarm->nAlarmTime_fri_1>>(nBitIndex-32))&0x01;
}else if(nBitValue<96){
nBitValue = (pAlarm->nAlarmTime_fri_2>>(nBitIndex-64))&0x01;
}
break;
case 6:
if(nBitIndex<32){
nBitValue = (pAlarm->nAlarmTime_sat_0>>nBitIndex)&0x01;
}else if (nBitIndex<64){
nBitValue = (pAlarm->nAlarmTime_sat_1>>(nBitIndex-32))&0x01;
}else if( nBitValue<96){
nBitValue = (pAlarm->nAlarmTime_sat_2>>(nBitIndex-64))&0x01;
}
break;
}
bSelected = (nBitValue==1) ? 1:0;
return bSelected;
}
INT32 CSEP2PAppSDKDemoDlg::set15MinutesFlagAlarmTime(MSG_SET_ALARM_INFO_REQ *pAlarm,INT32 nWeek ,INT32 nBitIndex, INT32 bSel)
{
INT32 bResult = 0;
if(nWeek<0||nWeek>7) return bResult;
if(nBitIndex<0 || nBitIndex>=96) return bResult;
switch (nWeek){
case 0:
if(nBitIndex<32){
pAlarm->nAlarmTime_sun_0 &=(~(0x01<<nBitIndex));
if(bSel){
pAlarm->nAlarmTime_sun_0 |= (0x1<<nBitIndex);
}
}else if(nBitIndex>=32 && nBitIndex<64){
pAlarm->nAlarmTime_sun_1 &=(~(0x01<<(nBitIndex-32)));
if(bSel){
pAlarm->nAlarmTime_sun_1 |= (0x1<<(nBitIndex-32));
}
}else if(nBitIndex>=64 && nBitIndex<96){
pAlarm->nAlarmTime_sun_2 &=(~(0x01<<(nBitIndex-64)));
if(bSel){
pAlarm->nAlarmTime_sun_2 |= (0x1<<(nBitIndex-64));
}
}
break;
case 1:
if(nBitIndex<32){
pAlarm->nAlarmTime_mon_0 &=(~(0x01<<nBitIndex));
if(bSel){
pAlarm->nAlarmTime_mon_0 |= (0x1<<nBitIndex);
}
}else if(nBitIndex>=32 && nBitIndex<64){
pAlarm->nAlarmTime_mon_1 &=(~(0x01<<(nBitIndex-32)));
if(bSel){
pAlarm->nAlarmTime_mon_1 |= (0x1<<(nBitIndex-32));
}
}else if(nBitIndex>=64 && nBitIndex<96){
pAlarm->nAlarmTime_mon_2 &=(~(0x01<<(nBitIndex-64)));
if(bSel){
pAlarm->nAlarmTime_mon_2 |= (0x1<<(nBitIndex-64));
}
}
break;
case 2:
if(nBitIndex<32){
pAlarm->nAlarmTime_tue_0 &=(~(0x01<<nBitIndex));
if(bSel){
pAlarm->nAlarmTime_tue_0 |= (0x1<<nBitIndex);
}
}else if(nBitIndex>=32 && nBitIndex<64){
pAlarm->nAlarmTime_tue_1 &=(~(0x01<<(nBitIndex-32)));
if(bSel){
pAlarm->nAlarmTime_tue_1 |= (0x1<<(nBitIndex-32));
}
}else if(nBitIndex>=64 && nBitIndex<96){
pAlarm->nAlarmTime_tue_2 &=(~(0x01<<(nBitIndex-64)));
if(bSel){
pAlarm->nAlarmTime_tue_2 |= (0x1<<(nBitIndex-64));
}
}
break;
case 3:
if(nBitIndex<32){
pAlarm->nAlarmTime_wed_0 &=(~(0x01<<nBitIndex));
if(bSel){
pAlarm->nAlarmTime_wed_0 |= (0x1<<nBitIndex);
}
}else if(nBitIndex>=32 && nBitIndex<64){
pAlarm->nAlarmTime_wed_1 &=(~(0x01<<(nBitIndex-32)));
if(bSel){
pAlarm->nAlarmTime_wed_1 |= (0x1<<(nBitIndex-32));
}
}else if(nBitIndex>=64 && nBitIndex<96){
pAlarm->nAlarmTime_wed_2 &=(~(0x01<<(nBitIndex-64)));
if(bSel){
pAlarm->nAlarmTime_wed_2 |= (0x1<<(nBitIndex-64));
}
}
break;
case 4:
if(nBitIndex<32){
pAlarm->nAlarmTime_thu_0 &=(~(0x01<<nBitIndex));
if(bSel){
pAlarm->nAlarmTime_thu_0 |= (0x1<<nBitIndex);
}
}else if(nBitIndex>=32 && nBitIndex<64){
pAlarm->nAlarmTime_thu_1 &=(~(0x01<<(nBitIndex-32)));
if(bSel){
pAlarm->nAlarmTime_thu_1 |= (0x1<<(nBitIndex-32));
}
}else if(nBitIndex>=64 && nBitIndex<96){
pAlarm->nAlarmTime_thu_2 &=(~(0x01<<(nBitIndex-64)));
if(bSel){
pAlarm->nAlarmTime_thu_2 |= (0x1<<(nBitIndex-64));
}
}
break;
case 5:
if(nBitIndex<32){
pAlarm->nAlarmTime_fri_0 &=(~(0x01<<nBitIndex));
if(bSel){
pAlarm->nAlarmTime_fri_0 |= (0x1<<nBitIndex);
}
}else if(nBitIndex>=32 && nBitIndex<64){
pAlarm->nAlarmTime_fri_1 &=(~(0x01<<(nBitIndex-32)));
if(bSel){
pAlarm->nAlarmTime_fri_1 |= (0x1<<(nBitIndex-32));
}
}else if(nBitIndex>=64 && nBitIndex<96){
pAlarm->nAlarmTime_fri_2 &=(~(0x01<<(nBitIndex-64)));
if(bSel){
pAlarm->nAlarmTime_fri_2 |= (0x1<<(nBitIndex-64));
}
}
break;
case 6:
if(nBitIndex<32){
pAlarm->nAlarmTime_sat_0 &=(~(0x01<<nBitIndex));
if(bSel){
pAlarm->nAlarmTime_sat_0 |= (0x1<<nBitIndex);
}
}else if(nBitIndex>=32 && nBitIndex<64){
pAlarm->nAlarmTime_sat_1 &=(~(0x01<<(nBitIndex-32)));
if(bSel){
pAlarm->nAlarmTime_sat_1 |= (0x1<<(nBitIndex-32));
}
}else if(nBitIndex>=64 && nBitIndex<96){
pAlarm->nAlarmTime_sat_2 &=(~(0x01<<(nBitIndex-64)));
if(bSel){
pAlarm->nAlarmTime_sat_2 |= (0x1<<(nBitIndex-64));
}
}
break;
}
return bResult;
}
| [
"656701179@qq.com"
] | 656701179@qq.com |
fe890ae6c23dae398fbda8a92a70cc2b8c89ed2b | e0e702f53690b52d41559532de0d5a87e48f6fb0 | /software/OLED_LoRa_Sender/OLED_LoRa_Sender.ino | f6e2d53f4711a864e2fe965f65338fac30cbb964 | [] | no_license | hftandang/MITnanoSAT | 96026e8fa5f859842d3ea0edad690ca9ea651bd7 | 19d336cd242bdc73325b133e0b336019e3e9eec3 | refs/heads/main | 2023-01-07T06:03:54.855208 | 2020-11-14T19:49:09 | 2020-11-14T19:49:09 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,868 | ino | /*
This is a simple example show the Heltec.LoRa sended data in OLED.
The onboard OLED display is SSD1306 driver and I2C interface. In order to make the
OLED correctly operation, you should output a high-low-high(1-0-1) signal by soft-
ware to OLED's reset pin, the low-level signal at least 5ms.
OLED pins to ESP32 GPIOs via this connecthin:
OLED_SDA -- GPIO4
OLED_SCL -- GPIO15
OLED_RST -- GPIO16
*/
//#######################################
//# #
//# airspacedefense.org #
//# Eng Marcelo Anjos #
//# marcelo.anjos@jcunion.com #
//# marcelu.phd@gmail.com #
//# 16/01/2018 #
//#######################################
#include "heltec.h"
#include "images.h"
#define BAND 915E6 //you can set band here directly,e.g. 868E6,915E6
unsigned int counter = 0;
String rssi = "RSSI --";
String packSize = "--";
String packet ;
void logo()
{
Heltec.display->clear();
Heltec.display->drawXbm(0,5,logo_width,logo_height,logo_bits);
Heltec.display->display();
}
void setup()
{
//WIFI Kit series V1 not support Vext control
Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.Heltec.Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
Heltec.display->init();
Heltec.display->flipScreenVertically();
Heltec.display->setFont(ArialMT_Plain_10);
logo();
delay(1500);
Heltec.display->clear();
Heltec.display->drawString(0, 0, "Heltec.LoRa Initial success!");
Heltec.display->display();
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
delay(1000);
}
void loop()
{
Heltec.display->clear();
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
Heltec.display->setFont(ArialMT_Plain_10);
Heltec.display->drawString(0, 0, "Sending packet: ");
Heltec.display->drawString(90, 0, String(counter));
Heltec.display->display();
Serial.println("'Sending packet: ", String(counter));
// send packet
LoRa.beginPacket();
/*
* LoRa.setTxPower(txPower,RFOUT_pin);
* txPower -- 0 ~ 20
* RFOUT_pin could be RF_PACONFIG_PASELECT_PABOOST or RF_PACONFIG_PASELECT_RFO
* - RF_PACONFIG_PASELECT_PABOOST -- LoRa single output via PABOOST, maximum output 20dBm
* - RF_PACONFIG_PASELECT_RFO -- LoRa single output via RFO_HF / RFO_LF, maximum output 14dBm
*/
LoRa.setTxPower(14,RF_PACONFIG_PASELECT_PABOOST);
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
| [
"projetoslinux@gmail.com"
] | projetoslinux@gmail.com |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.